Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / components / logic / hierarchy-navigtion / hierarchy-navigation.component.spec.ts
1 import { async, ComponentFixture } from '@angular/core/testing';
2 import { By } from '@angular/platform-browser';
3 import { ConfigureFn, configureTests } from '../../../../../jest/test-config.helper';
4 import 'jest-dom/extend-expect';
5 import {HierarchyNavigationComponent} from "./hierarchy-navigation.component";
6 import {HierarchyDisplayOptions} from "./hierarchy-display-options";
7
8
9 describe('hierarchyNavigationComponent', () => {
10   let fixture: ComponentFixture<HierarchyNavigationComponent>;
11     let hierarchyDisplayOptions: HierarchyDisplayOptions;
12   beforeEach(
13     async(() => {
14       const configure: ConfigureFn = testBed => {
15         testBed.configureTestingModule({
16           declarations: [HierarchyNavigationComponent]
17         });
18       };
19
20       configureTests(configure).then(testBed => {
21         fixture = testBed.createComponent(HierarchyNavigationComponent);
22         hierarchyDisplayOptions = new HierarchyDisplayOptions("id", "name", "children");
23           fixture.componentInstance.displayOptions = hierarchyDisplayOptions;
24           fixture.detectChanges();
25           fixture.componentInstance.displayData = [{name: "aaa", id: "1", children: [{name: "bbb", id: "1.1"}, {name: "ccc", id: "1.2", children: [{name: "aaa", id: "1.2.1"}]}]}, {name: "bbb", id: "2"}];
26           fixture.detectChanges();
27       });
28     })
29   );
30
31   it('should have a selected class after user click on a tree node',
32     () => {
33         let firstNodeElement = fixture.debugElement.query(By.css('.node-item'));
34         fixture.componentInstance.updateSelected.subscribe((item) => {
35             fixture.componentInstance.selectedItem = item.id;
36             fixture.detectChanges();
37         });
38         firstNodeElement.nativeElement.click();
39         fixture.whenStable().then(() => {
40             expect(firstNodeElement.children[0].nativeElement).toHaveClass('selected');
41         });
42     });
43
44     it('should call onClick function when user click on a tree node',
45         () => {
46             spyOn(fixture.componentInstance, 'onClick');
47             let firstNodeElement = fixture.debugElement.query(By.css('.node-item')).nativeElement;
48             firstNodeElement.click();
49             expect(fixture.componentInstance.onClick).toHaveBeenCalled();
50         });
51
52 });