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';
10 describe('environment parameters component', () => {
12 let fixture: ComponentFixture<EnvParamsComponent>;
13 let popoverServiceMock: Partial<SdcUiServices.PopoverService>;
14 let regexPatterns: any;
16 let artifactModel = new ArtifactModel();
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}
24 let keyboardEvent = new KeyboardEvent("keyup");
29 popoverServiceMock = {
30 createPopOver : jest.fn()
33 const configure: ConfigureFn = testBed => {
34 testBed.configureTestingModule({
35 declarations: [EnvParamsComponent],
36 imports: [NgxDatatableModule],
37 schemas: [NO_ERRORS_SCHEMA],
39 { provide: SdcUiServices.PopoverService, useValue: popoverServiceMock },
40 { provide: CacheService, useValue: { get: jest.fn() } }
45 configureTests(configure).then(testBed => {
46 fixture = testBed.createComponent(EnvParamsComponent);
51 it('should match current snapshot of env-params component', () => {
52 expect(fixture).toMatchSnapshot();
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("");
64 it("should update filter heatParameters so there won''t be any value to be displayed", () => {
66 fixture.componentInstance.artifact = artifactModel;
67 fixture.componentInstance.artifact.heatParameters = mockHeatParameters;
68 fixture.componentInstance.ngOnInit();
72 value: 'paramNotExist'
76 expect(fixture.componentInstance.artifact.heatParameters.length).toBe(3);
77 fixture.componentInstance.updateFilter(event);
78 expect(fixture.componentInstance.artifact.heatParameters.length).toBe(0);
81 it("should update filter heatParameters so there will be only 1 value to be displayed", () => {
83 fixture.componentInstance.artifact = artifactModel;
84 fixture.componentInstance.artifact.heatParameters = mockHeatParameters;
85 fixture.componentInstance.ngOnInit();
93 expect(fixture.componentInstance.artifact.heatParameters.length).toBe(3);
94 fixture.componentInstance.updateFilter(event);
95 expect(fixture.componentInstance.artifact.heatParameters.length).toBe(1);