|
| 1 | +import { TestBed } from '@angular/core/testing'; |
| 2 | +import { By } from '@angular/platform-browser'; |
| 3 | +import { Component, ElementRef, DebugElement } from '@angular/core'; |
| 4 | +import { TreeInternalComponent } from '../src/tree-internal.component'; |
| 5 | +import { TreeComponent } from '../src/tree.component'; |
| 6 | +import { TreeModel, Ng2TreeSettings } 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 | +import { NodeMenuAction } from '../src/menu/menu.events'; |
| 14 | +import * as EventUtils from '../src/utils/event.utils'; |
| 15 | +import { CapturedNode } from '../src/draggable/captured-node'; |
| 16 | +import { SafeHtmlPipe } from '../src/utils/safe-html.pipe'; |
| 17 | + |
| 18 | +let fixture; |
| 19 | +let masterInternalTreeEl; |
| 20 | +let masterComponentInstance; |
| 21 | + |
| 22 | +const tree: TreeModel = { |
| 23 | + value: 'Master', icon: 'icon0', |
| 24 | + children: [ |
| 25 | + {value: 'Servant#1', icon: 'icon1'}, |
| 26 | + {value: 'Servant#2', icon: 'icon2'} |
| 27 | + ] |
| 28 | +}; |
| 29 | + |
| 30 | +@Component({ |
| 31 | + template: `<div><tree id="master" [tree]="tree"><ng-template let-node><span class="icon">{{node.icon}}</span><span class="value">{{node.value}}</span></ng-template></tree></div>` |
| 32 | +}) |
| 33 | +class TestComponent { |
| 34 | + public tree: TreeModel = tree; |
| 35 | + public constructor(public treeHolder: ElementRef) {} |
| 36 | +} |
| 37 | + |
| 38 | +describe('template for tree', () => { |
| 39 | + beforeEach(() => { |
| 40 | + TestBed.configureTestingModule({ |
| 41 | + declarations: [TestComponent, TreeInternalComponent, TreeComponent, NodeEditableDirective, NodeMenuComponent, NodeDraggableDirective, SafeHtmlPipe], |
| 42 | + providers: [NodeMenuService, NodeDraggableService, TreeService] |
| 43 | + }); |
| 44 | + |
| 45 | + fixture = TestBed.createComponent(TestComponent); |
| 46 | + |
| 47 | + masterInternalTreeEl = fixture.debugElement.query(By.css('#master')).query(By.directive(TreeInternalComponent)); |
| 48 | + masterComponentInstance = masterInternalTreeEl.componentInstance; |
| 49 | + |
| 50 | + fixture.detectChanges(); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should not render default node', () => { |
| 54 | + const foldingEl: DebugElement[] = masterInternalTreeEl.queryAll(By.css('.node-name')); |
| 55 | + expect(foldingEl.length).toEqual(0); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should render the template', () => { |
| 59 | + const icons: DebugElement[] = masterInternalTreeEl.queryAll(By.css('.icon')); |
| 60 | + expect(icons.length).toEqual(3); |
| 61 | + expect(icons[0].nativeElement.innerHTML).toEqual('icon0'); |
| 62 | + expect(icons[1].nativeElement.innerHTML).toEqual('icon1'); |
| 63 | + expect(icons[2].nativeElement.innerHTML).toEqual('icon2'); |
| 64 | + |
| 65 | + const values: DebugElement[] = masterInternalTreeEl.queryAll(By.css('.value')); |
| 66 | + expect(values.length).toEqual(3); |
| 67 | + expect(values[0].nativeElement.innerHTML).toEqual('Master'); |
| 68 | + expect(values[1].nativeElement.innerHTML).toEqual('Servant#1'); |
| 69 | + expect(values[2].nativeElement.innerHTML).toEqual('Servant#2'); |
| 70 | + }); |
| 71 | + |
| 72 | +}); |
0 commit comments