|
| 1 | +import { TestBed, ComponentFixture } from '@angular/core/testing'; |
| 2 | +import { By } from '@angular/platform-browser'; |
| 3 | +import { Component, DebugElement } from '@angular/core'; |
| 4 | +import { TreeInternalComponent } from '../src/tree-internal.component'; |
| 5 | +import { TreeComponent } from '../src/tree.component'; |
| 6 | +import { TreeModel } from '../src/tree.types'; |
| 7 | +import { TreeService } from '../src/tree.service'; |
| 8 | +import { NodeMenuService } from '../src/menu/node-menu.service'; |
| 9 | +import { NodeMenuComponent } from '../src/menu/node-menu.component'; |
| 10 | +import { NodeDraggableService } from '../src/draggable/node-draggable.service'; |
| 11 | +import { NodeDraggableDirective } from '../src/draggable/node-draggable.directive'; |
| 12 | +import { NodeEditableDirective } from '../src/editable/node-editable.directive'; |
| 13 | + |
| 14 | +let fixture: ComponentFixture<TestComponent>; |
| 15 | +let componentInstance: TreeComponent; |
| 16 | +let componentEl: DebugElement; |
| 17 | + |
| 18 | +describe('TreeComponent (the one that wraps TreeInternalComponent)', () => { |
| 19 | + beforeEach(() => { |
| 20 | + TestBed.configureTestingModule({ |
| 21 | + declarations: [TestComponent, TreeInternalComponent, TreeComponent, NodeEditableDirective, NodeMenuComponent, NodeDraggableDirective], |
| 22 | + providers: [NodeMenuService, NodeDraggableService, TreeService] |
| 23 | + }); |
| 24 | + |
| 25 | + fixture = TestBed.createComponent(TestComponent); |
| 26 | + componentEl = fixture.debugElement.query(By.directive(TreeComponent)); |
| 27 | + componentInstance = componentEl.componentInstance; |
| 28 | + |
| 29 | + fixture.detectChanges(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should be initialized', () => { |
| 33 | + expect(fixture).not.toBeNull(); |
| 34 | + expect(componentInstance.tree).not.toBeFalsy(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should have default empty tree if none was given via input', () => { |
| 38 | + expect(componentInstance.tree.value).toEqual(''); |
| 39 | + expect(componentInstance.tree.isRoot()).toEqual(true); |
| 40 | + expect(componentInstance.treeModel).toBeFalsy(); |
| 41 | + expect(componentInstance.tree.children).toBeFalsy(); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should use given model if it is not falsy', () => { |
| 45 | + fixture.debugElement.componentInstance.model = { |
| 46 | + value: '42' |
| 47 | + }; |
| 48 | + |
| 49 | + fixture.detectChanges(); |
| 50 | + |
| 51 | + expect(componentInstance.tree.value).toEqual('42'); |
| 52 | + expect(componentInstance.treeModel.value).toEqual('42'); |
| 53 | + }); |
| 54 | +}); |
| 55 | + |
| 56 | +@Component({ |
| 57 | + template: ` |
| 58 | + <div><tree [tree]="model"></tree></div> |
| 59 | + ` |
| 60 | +}) |
| 61 | +class TestComponent { |
| 62 | + public model: TreeModel; |
| 63 | +} |
0 commit comments