Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / components / forms / env-params / env-params.component.spec.ts
1 import {async, ComponentFixture} from "@angular/core/testing";
2 import {EnvParamsComponent} from "./env-params.component";
3 import {SdcUiServices, SdcUiCommon} from "onap-ui-angular";
4 import {ConfigureFn, configureTests} from "../../../../../jest/test-config.helper";
5 import {NgxDatatableModule} from "@swimlane/ngx-datatable";
6 import {NO_ERRORS_SCHEMA} from "@angular/core";
7 import {ArtifactModel} from "../../../../models/artifacts";
8 import { CacheService } from '../../../services/cache.service';
9
10 describe('environment parameters component', () => {
11
12     let fixture: ComponentFixture<EnvParamsComponent>;
13     let popoverServiceMock: Partial<SdcUiServices.PopoverService>;
14     let regexPatterns: any;
15
16     let artifactModel = new ArtifactModel();
17
18     let mockHeatParameters = [
19         {currentValue: "1", defaultValue: null, description: "Description 1", empty:false, name: "Param1", ownerId: null, type: "string", uniqueId: null, envDisplayName:null, version: null, filterTerm:null},
20         {currentValue: "2", defaultValue: null, description: "Description 2", empty:false, name: "Param2", ownerId: null, type: "string", uniqueId: null, envDisplayName:null, version: null, filterTerm:null},
21         {currentValue: "3", defaultValue: null, description: "Description 3", empty:false, name: "Param3", ownerId: null, type: "string", uniqueId: null, envDisplayName:null, version: null, filterTerm:null}
22         ];
23
24     let keyboardEvent = new KeyboardEvent("keyup");
25
26     beforeEach(
27         async(() => {
28
29             popoverServiceMock = {
30                 createPopOver : jest.fn()
31             }
32
33             const configure: ConfigureFn = testBed => {
34                 testBed.configureTestingModule({
35                     declarations: [EnvParamsComponent],
36                     imports: [NgxDatatableModule],
37                     schemas: [NO_ERRORS_SCHEMA],
38                     providers: [
39                         { provide: SdcUiServices.PopoverService, useValue: popoverServiceMock },
40                         { provide: CacheService, useValue: { get: jest.fn() } }
41                     ],
42                 });
43             };
44
45             configureTests(configure).then(testBed => {
46                 fixture = testBed.createComponent(EnvParamsComponent);
47             });
48         })
49     );
50
51     it('should match current snapshot of env-params component', () => {
52         expect(fixture).toMatchSnapshot();
53     });
54
55     it('should clear CurrentValue for a given name in the heat parameter', () => {
56          fixture.componentInstance.artifact = artifactModel;
57          fixture.componentInstance.artifact.heatParameters = mockHeatParameters;
58          expect(fixture.componentInstance.artifact.heatParameters.length).toBe(3);
59          expect(fixture.componentInstance.artifact.heatParameters[0].currentValue).toBe("1");
60          fixture.componentInstance.clearCurrentValue("Param1");
61          expect(fixture.componentInstance.artifact.heatParameters[0].currentValue).toBe("");
62     });
63
64     it("should update filter heatParameters so there won''t be any value to be displayed", () => {
65
66         fixture.componentInstance.artifact = artifactModel;
67         fixture.componentInstance.artifact.heatParameters = mockHeatParameters;
68         fixture.componentInstance.ngOnInit();
69
70         let event = {
71              target : {
72                 value: 'paramNotExist'
73              }
74         }
75
76         expect(fixture.componentInstance.artifact.heatParameters.length).toBe(3);
77         fixture.componentInstance.updateFilter(event);
78         expect(fixture.componentInstance.artifact.heatParameters.length).toBe(0);
79     });
80
81     it("should update filter heatParameters so there will be only 1 value to be displayed", () => {
82
83         fixture.componentInstance.artifact = artifactModel;
84         fixture.componentInstance.artifact.heatParameters = mockHeatParameters;
85         fixture.componentInstance.ngOnInit();
86
87         let event = {
88             target : {
89                 value: 'param1'
90             }
91         }
92
93         expect(fixture.componentInstance.artifact.heatParameters.length).toBe(3);
94         fixture.componentInstance.updateFilter(event);
95         expect(fixture.componentInstance.artifact.heatParameters.length).toBe(1);
96     });
97
98 });