summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/components/logic/hierarchy-navigtion/hierarchy-navigation.component.spec.ts
blob: fc76463970e54678f0dfbcd342e2588418926795 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { async, ComponentFixture } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ConfigureFn, configureTests } from '../../../../../jest/test-config.helper';
import 'jest-dom/extend-expect';
import {HierarchyNavigationComponent} from "./hierarchy-navigation.component";
import {HierarchyDisplayOptions} from "./hierarchy-display-options";


describe('hierarchyNavigationComponent', () => {
  let fixture: ComponentFixture<HierarchyNavigationComponent>;
    let hierarchyDisplayOptions: HierarchyDisplayOptions;
  beforeEach(
    async(() => {
      const configure: ConfigureFn = testBed => {
        testBed.configureTestingModule({
          declarations: [HierarchyNavigationComponent]
        });
      };

      configureTests(configure).then(testBed => {
        fixture = testBed.createComponent(HierarchyNavigationComponent);
        hierarchyDisplayOptions = new HierarchyDisplayOptions("id", "name", "children");
          fixture.componentInstance.displayOptions = hierarchyDisplayOptions;
          fixture.detectChanges();
          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"}];
          fixture.detectChanges();
      });
    })
  );

  it('should have a selected class after user click on a tree node',
    () => {
        let firstNodeElement = fixture.debugElement.query(By.css('.node-item'));
        fixture.componentInstance.updateSelected.subscribe((item) => {
            fixture.componentInstance.selectedItem = item.id;
            fixture.detectChanges();
        });
        firstNodeElement.nativeElement.click();
        fixture.whenStable().then(() => {
            expect(firstNodeElement.children[0].nativeElement).toHaveClass('selected');
        });
    });

    it('should call onClick function when user click on a tree node',
        () => {
            spyOn(fixture.componentInstance, 'onClick');
            let firstNodeElement = fixture.debugElement.query(By.css('.node-item')).nativeElement;
            firstNodeElement.click();
            expect(fixture.componentInstance.onClick).toHaveBeenCalled();
        });

});