blob: 754dd669083ebe3d2a458ec632ded30302ace198 [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {ComponentFixture, TestBed} from '@angular/core/testing';
2import {HttpClientTestingModule} from '@angular/common/http/testing';
3import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core";
4import {SearchComponent} from "./search.component";
5import {FormsModule, ReactiveFormsModule} from "@angular/forms";
6
7describe('Spinner component', () => {
8
9 let component: SearchComponent;
10 let fixture: ComponentFixture<SearchComponent>;
11
12 beforeAll(done => (async () => {
13 TestBed.configureTestingModule({
14 imports: [FormsModule, ReactiveFormsModule, HttpClientTestingModule],
15 providers: [],
16 declarations: [SearchComponent],
17 schemas: [CUSTOM_ELEMENTS_SCHEMA]
18 });
19 await TestBed.compileComponents();
20
21 fixture = TestBed.createComponent(SearchComponent);
22 component = fixture.componentInstance;
23 fixture.detectChanges();
24
25 })().then(done).catch(done.fail));
26
27
28 test('component should be defined', () => {
29 expect(component).toBeDefined();
30 });
31
32 test('searchTree should return all nodes that include some text: with text', () => {
33 component.nodes = [
34 {
35 name: 'name_1'
36 },
37 {
38 name: 'name_2'
39 },
40 {
41 name: 'name_3'
42 },
43 {
44 name: 'name_3'
45 }];
46 jest.spyOn(component.updateNodes, 'emit');
47 spyOn(component, 'expandParentByNodeId').and.stub();
48 component.searchTree('name_1');
49
50 expect(component.updateNodes.emit).toHaveBeenCalledWith({
51 nodes: [
52 {
53 name: 'name_1'
54 },
55 {
56 name: 'name_2'
57 },
58 {
59 name: 'name_3'
60 },
61 {
62 name: 'name_3'
63 }],
64 filterValue: 'name_1'
65 });
66 });
67
68 test('searchTree should return all nodes that include some text: without text', () => {
69 component.nodes = [
70 {
71 name: 'name_1',
72 children: [
73 {
74 name: 'name_child_1'
75 }
76 ]
77 },
78 {
79 name: 'name_2'
80 },
81 {
82 name: 'name_3'
83 },
84 {
85 name: 'name_4'
86 }];
87 jest.spyOn(component.updateNodes, 'emit');
88 spyOn(component, 'expandParentByNodeId').and.stub();
89 component.searchTree('');
90
91 expect(component.updateNodes.emit).toHaveBeenCalled();
92 });
93});