summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/search/search.component.spec.ts
blob: 754dd669083ebe3d2a458ec632ded30302ace198 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core";
import {SearchComponent} from "./search.component";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";

describe('Spinner component', () => {

  let component: SearchComponent;
  let fixture: ComponentFixture<SearchComponent>;

  beforeAll(done => (async () => {
    TestBed.configureTestingModule({
      imports: [FormsModule, ReactiveFormsModule, HttpClientTestingModule],
      providers: [],
      declarations: [SearchComponent],
      schemas: [CUSTOM_ELEMENTS_SCHEMA]
    });
    await TestBed.compileComponents();

    fixture = TestBed.createComponent(SearchComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();

  })().then(done).catch(done.fail));


  test('component should be defined', () => {
    expect(component).toBeDefined();
  });

  test('searchTree should return all nodes that include some text: with text', () => {
    component.nodes = [
      {
        name: 'name_1'
      },
      {
        name: 'name_2'
      },
      {
        name: 'name_3'
      },
      {
        name: 'name_3'
      }];
    jest.spyOn(component.updateNodes, 'emit');
    spyOn(component, 'expandParentByNodeId').and.stub();
    component.searchTree('name_1');

    expect(component.updateNodes.emit).toHaveBeenCalledWith({
      nodes: [
        {
          name: 'name_1'
        },
        {
          name: 'name_2'
        },
        {
          name: 'name_3'
        },
        {
          name: 'name_3'
        }],
      filterValue: 'name_1'
    });
  });

  test('searchTree should return all nodes that include some text: without text', () => {
    component.nodes = [
      {
        name: 'name_1',
        children: [
          {
            name: 'name_child_1'
          }
        ]
      },
      {
        name: 'name_2'
      },
      {
        name: 'name_3'
      },
      {
        name: 'name_4'
      }];
    jest.spyOn(component.updateNodes, 'emit');
    spyOn(component, 'expandParentByNodeId').and.stub();
    component.searchTree('');

    expect(component.updateNodes.emit).toHaveBeenCalled();
  });
});