Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / components / logic / filter-properties-assignment / filter-properties-assignment.component.spec.ts
1 import {async, ComponentFixture} from "@angular/core/testing";
2 import {FilterPropertiesAssignmentComponent} from "./filter-properties-assignment.component";
3 import {ConfigureFn, configureTests} from "../../../../../jest/test-config.helper";
4 import {NO_ERRORS_SCHEMA} from "@angular/core";
5 import {FilterPropertiesAssignmentData} from "../../../../models/filter-properties-assignment-data";
6 import {PopoverComponent} from "../../ui/popover/popover.component";
7
8
9
10 describe('filter-properties-assignemnt component', () => {
11
12     let fixture: ComponentFixture<FilterPropertiesAssignmentComponent>;
13
14     beforeEach(
15         async(() => {
16
17             const configure: ConfigureFn = testBed => {
18                 testBed.configureTestingModule({
19                     declarations: [FilterPropertiesAssignmentComponent],
20                     imports: [],
21                     schemas: [NO_ERRORS_SCHEMA],
22                     providers: [],
23                 });
24             };
25
26             configureTests(configure).then(testBed => {
27                 fixture = testBed.createComponent(FilterPropertiesAssignmentComponent);
28
29             });
30         })
31     );
32
33
34     it('should match current snapshot of artifact-tab component', () => {
35         expect(fixture).toMatchSnapshot();
36     });
37
38     it('on selectAll', () => {
39         let filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
40         filterData.propertyName = 'testVal';
41         let typesOptions:Array<string> = ['option1', 'option2', 'option3'];
42         let selectedTypes:Object = {};
43
44         fixture.componentInstance.filterData = filterData;
45         fixture.componentInstance.typesOptions = typesOptions;
46         fixture.componentInstance.selectedTypes = selectedTypes;
47
48         fixture.componentInstance.selectAll();
49
50         let expectedRes = {"option1": false,"option2": false,"option3": false};
51         expect(fixture.componentInstance.selectedTypes).toEqual(expectedRes);
52     });
53
54
55     it ('on onTypeSelected allSelected set to False', () => {
56         let selectedTypes:Object = {"option1": true,"option2": false,"option3": true};
57         fixture.componentInstance.selectedTypes = selectedTypes;
58         fixture.componentInstance.allSelected = true;
59         fixture.componentInstance.onTypeSelected('option2');
60
61         expect(fixture.componentInstance.allSelected).toBe(false);
62     });
63
64     it ('on onTypeSelected allSelected remains True', () => {
65         let selectedTypes:Object = {"option1": true,"option2": true,"option3": true};
66         fixture.componentInstance.selectedTypes = selectedTypes;
67         fixture.componentInstance.allSelected = true;
68         fixture.componentInstance.onTypeSelected('option2');
69
70         expect(fixture.componentInstance.allSelected).toBe(true);
71     });
72
73     it ('on clearAll', () => {
74         let filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
75         filterData.propertyName = 'testVal';
76         let selectedTypes:Object = {"option1": true,"option2": false,"option3": true};
77
78         fixture.componentInstance.filterData = filterData;
79         fixture.componentInstance.selectedTypes = selectedTypes;
80         fixture.componentInstance.allSelected = true;
81
82         fixture.componentInstance.clearAll();
83
84         expect(fixture.componentInstance.filterData.propertyName).toBe('');
85         expect(fixture.componentInstance.allSelected).toBe(false);
86     });
87
88     it ('someTypesSelectedAndThereIsPropertyName return True', ()=> {
89         let res = fixture.componentInstance.someTypesSelectedAndThereIsPropertyName();
90
91         expect(res).toBe(true)
92     });
93
94     it ('someTypesSelectedAndThereIsPropertyName return Null', ()=> {
95         let selectedTypes:Object = {"option1": true,"option2": false,"option3": true};
96         let filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
97         filterData.propertyName = 'testVal';
98
99         fixture.componentInstance.selectedTypes = selectedTypes;
100         fixture.componentInstance.filterData = filterData;
101
102         let res = fixture.componentInstance.someTypesSelectedAndThereIsPropertyName();
103
104         expect(res).toBe(null)
105     });
106
107     it ('search', ()=> {
108
109         let filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
110         filterData.selectedTypes = ["CP"];
111         fixture.componentInstance.filterData = filterData;
112
113         let componentType: string = 'resource';
114         fixture.componentInstance.componentType = componentType;
115
116         let selectedTypes:Object = {"option1": true,"CP": true,"option3": true};
117         fixture.componentInstance.selectedTypes = selectedTypes;
118
119         let temp:any;
120         let filterPopover: PopoverComponent = new PopoverComponent(temp , temp );
121         fixture.componentInstance.filterPopover = filterPopover;
122         fixture.componentInstance.filterPopover.hide = jest.fn();
123
124         fixture.componentInstance.search();
125
126         expect(fixture.componentInstance.filterData.selectedTypes).toEqual(["CP"]);
127         expect(fixture.componentInstance.filterPopover.hide).toHaveBeenCalled();
128     });
129
130     it('close', () => {
131         let temp:any;
132         let filterPopover: PopoverComponent = new PopoverComponent(temp , temp );
133         fixture.componentInstance.filterPopover = filterPopover;
134         fixture.componentInstance.filterPopover.hide = jest.fn();
135
136         fixture.componentInstance.close();
137
138         expect(fixture.componentInstance.filterPopover.hide).toHaveBeenCalled();
139     });
140
141 });