Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame^] | 1 | import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 2 | import {HttpClientTestingModule} from '@angular/common/http/testing'; |
| 3 | import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; |
| 4 | import {SearchComponent} from "./search.component"; |
| 5 | import {FormsModule, ReactiveFormsModule} from "@angular/forms"; |
| 6 | |
| 7 | describe('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 | }); |