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";
10 describe('filter-properties-assignemnt component', () => {
12 let fixture: ComponentFixture<FilterPropertiesAssignmentComponent>;
17 const configure: ConfigureFn = testBed => {
18 testBed.configureTestingModule({
19 declarations: [FilterPropertiesAssignmentComponent],
21 schemas: [NO_ERRORS_SCHEMA],
26 configureTests(configure).then(testBed => {
27 fixture = testBed.createComponent(FilterPropertiesAssignmentComponent);
34 it('should match current snapshot of artifact-tab component', () => {
35 expect(fixture).toMatchSnapshot();
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 = {};
44 fixture.componentInstance.filterData = filterData;
45 fixture.componentInstance.typesOptions = typesOptions;
46 fixture.componentInstance.selectedTypes = selectedTypes;
48 fixture.componentInstance.selectAll();
50 let expectedRes = {"option1": false,"option2": false,"option3": false};
51 expect(fixture.componentInstance.selectedTypes).toEqual(expectedRes);
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');
61 expect(fixture.componentInstance.allSelected).toBe(false);
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');
70 expect(fixture.componentInstance.allSelected).toBe(true);
73 it ('on clearAll', () => {
74 let filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
75 filterData.propertyName = 'testVal';
76 let selectedTypes:Object = {"option1": true,"option2": false,"option3": true};
78 fixture.componentInstance.filterData = filterData;
79 fixture.componentInstance.selectedTypes = selectedTypes;
80 fixture.componentInstance.allSelected = true;
82 fixture.componentInstance.clearAll();
84 expect(fixture.componentInstance.filterData.propertyName).toBe('');
85 expect(fixture.componentInstance.allSelected).toBe(false);
88 it ('someTypesSelectedAndThereIsPropertyName return True', ()=> {
89 let res = fixture.componentInstance.someTypesSelectedAndThereIsPropertyName();
91 expect(res).toBe(true)
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';
99 fixture.componentInstance.selectedTypes = selectedTypes;
100 fixture.componentInstance.filterData = filterData;
102 let res = fixture.componentInstance.someTypesSelectedAndThereIsPropertyName();
104 expect(res).toBe(null)
109 let filterData:FilterPropertiesAssignmentData = new FilterPropertiesAssignmentData();
110 filterData.selectedTypes = ["CP"];
111 fixture.componentInstance.filterData = filterData;
113 let componentType: string = 'resource';
114 fixture.componentInstance.componentType = componentType;
116 let selectedTypes:Object = {"option1": true,"CP": true,"option3": true};
117 fixture.componentInstance.selectedTypes = selectedTypes;
120 let filterPopover: PopoverComponent = new PopoverComponent(temp , temp );
121 fixture.componentInstance.filterPopover = filterPopover;
122 fixture.componentInstance.filterPopover.hide = jest.fn();
124 fixture.componentInstance.search();
126 expect(fixture.componentInstance.filterData.selectedTypes).toEqual(["CP"]);
127 expect(fixture.componentInstance.filterPopover.hide).toHaveBeenCalled();
132 let filterPopover: PopoverComponent = new PopoverComponent(temp , temp );
133 fixture.componentInstance.filterPopover = filterPopover;
134 fixture.componentInstance.filterPopover.hide = jest.fn();
136 fixture.componentInstance.close();
138 expect(fixture.componentInstance.filterPopover.hide).toHaveBeenCalled();