1 import {ArtifactFormComponent} from "./artifact-form.component";
2 import {async, ComponentFixture} from "@angular/core/testing";
3 import {ConfigureFn, configureTests} from "../../../../../jest/test-config.helper";
4 import {NO_ERRORS_SCHEMA} from "@angular/core";
5 import {TranslateModule} from "../../../shared/translator/translate.module";
6 import {CacheService} from "../../../services/cache.service";
7 import {TranslateService} from "../../../shared/translator/translate.service";
8 import {ArtifactModel} from "../../../../models/artifacts";
9 import {IDropDownOption} from "onap-ui-angular/dist/form-elements/dropdown/dropdown-models";
10 import {Observable, Subject} from "rxjs";
11 import {getValue} from "@ngxs/store";
14 describe('artifact form component', () => {
16 let fixture: ComponentFixture<ArtifactFormComponent>;
17 let cacheServiceMock: Partial<CacheService>;
18 let onValidationChangeMock: Partial<Subject<boolean>>;
20 let artifactModel = new ArtifactModel();
26 onValidationChangeMock = {
37 const configure: ConfigureFn = testBed => {
38 testBed.configureTestingModule({
39 declarations: [ArtifactFormComponent],
40 imports: [TranslateModule],
41 schemas: [NO_ERRORS_SCHEMA],
43 {provide: CacheService, useValue: cacheServiceMock},
44 {provide: TranslateService, useValue: {}}
49 configureTests(configure).then(testBed => {
50 fixture = testBed.createComponent(ArtifactFormComponent);
56 it('should verify initArtifactTypes for DEPLOYMENT and ArtifactType = HEAT_ENV', () =>{
58 cacheServiceMock.get.mockImplementation(() =>{
62 resourceInstanceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
68 fixture.componentInstance.artifactType = 'DEPLOYMENT';
69 fixture.componentInstance.artifact = artifactModel;
70 fixture.componentInstance.artifact.artifactType = 'HEAT_ENV';
72 fixture.componentInstance.initArtifactTypes();
74 expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
78 it('should verify initArtifactTypes for DEPLOYMENT and ComponentType = RESOURCE', () =>{
80 cacheServiceMock.get.mockImplementation(() =>{
84 resourceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
90 fixture.componentInstance.artifactType = 'DEPLOYMENT';
91 fixture.componentInstance.artifact = artifactModel;
92 fixture.componentInstance.componentType = 'RESOURCE';
94 fixture.componentInstance.initArtifactTypes();
96 expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
100 it('should verify initArtifactTypes for DEPLOYMENT and NOT ComponentType = RESOURCE OR NOT ArtifactType = HEAT_ENV', () =>{
102 cacheServiceMock.get.mockImplementation(() =>{
106 serviceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
112 fixture.componentInstance.artifactType = 'DEPLOYMENT';
113 fixture.componentInstance.artifact = artifactModel;
114 // fixture.componentInstance.componentType = 'RESOURCE';
116 fixture.componentInstance.initArtifactTypes();
118 expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
122 it('should verify initArtifactTypes for INFORMATION', () =>{
124 cacheServiceMock.get.mockImplementation(() =>{
127 other: [{name: "Val1"}, {name: "ExpectedValToBeSelected"}, {name: "Val3"}]
132 fixture.componentInstance.artifactType = 'INFORMATIONAL';
133 fixture.componentInstance.artifact = artifactModel;
134 fixture.componentInstance.artifact.artifactType = 'ExpectedValToBeSelected';
136 fixture.componentInstance.initArtifactTypes();
138 expect(fixture.componentInstance.selectedFileType).toEqual({"label": "ExpectedValToBeSelected", "value": "ExpectedValToBeSelected"});
143 it('should match current snapshot of artifact form component', () => {
144 expect(fixture).toMatchSnapshot();
147 it('should verify onUploadFile -> file gets file name', () => {
149 filename:'dummyFileName'
152 fixture.componentInstance.verifyTypeAndFileWereFilled = jest.fn();
153 fixture.componentInstance.artifact = artifactModel;
154 fixture.componentInstance.onUploadFile(file);
156 expect(fixture.componentInstance.artifact.artifactName).toBe('dummyFileName');
158 const spy1 = jest.spyOn(fixture.componentInstance,'verifyTypeAndFileWereFilled');
159 expect(spy1).toHaveBeenCalled();
162 it('should verify onUploadFile -> file is null', () => {
164 fixture.componentInstance.artifact = artifactModel;
165 fixture.componentInstance.onUploadFile(file);
167 expect(fixture.componentInstance.artifact.artifactName).toBe(null);
170 it('should verify onTypeChange -> verifyTypeAndFileWereFilled is being called', () => {
171 let selectedFileType:IDropDownOption;
172 selectedFileType = {"label": "dummyLabel", "value": "dummyValue"};
173 fixture.componentInstance.verifyTypeAndFileWereFilled = jest.fn();
175 fixture.componentInstance.artifact = artifactModel;
176 fixture.componentInstance.onTypeChange(selectedFileType);
178 const spy1 = jest.spyOn(fixture.componentInstance,'verifyTypeAndFileWereFilled');
179 expect(spy1).toHaveBeenCalled();
182 it('should verify onDescriptionChange -> verifyTypeAndFileWereFilled is being called', () => {
183 fixture.componentInstance.verifyTypeAndFileWereFilled = jest.fn();
184 fixture.componentInstance.onValidationChange.next = jest.fn(() => true);
186 fixture.componentInstance.artifact = artifactModel;
187 fixture.componentInstance.onDescriptionChange();
189 const spy1 = jest.spyOn(fixture.componentInstance,'verifyTypeAndFileWereFilled');
190 expect(spy1).toHaveBeenCalled();
193 it('should verify onLabelChange -> verifyTypeAndFileWereFilled is being called', () => {
194 fixture.componentInstance.verifyTypeAndFileWereFilled = jest.fn();
195 fixture.componentInstance.onValidationChange.next = jest.fn(() => true);
197 fixture.componentInstance.artifact = artifactModel;
198 fixture.componentInstance.onLabelChange(true);
200 const spy1 = jest.spyOn(fixture.componentInstance,'verifyTypeAndFileWereFilled');
201 expect(spy1).toHaveBeenCalled();
204 it('should verify verifyTypeAndFileWereFilled -> verify branch this.artifact.artifactType !== \'DEPLOYMENT\' ==>> onValidationChange.next(false)', () => {
205 fixture.componentInstance.artifact = artifactModel;
206 fixture.componentInstance.artifact.artifactType = 'NOT_DEPLOYMENT';
207 fixture.componentInstance.artifact.mandatory = true;
208 fixture.componentInstance.descriptionIsValid = false;
210 let onValidationChangeResult;
212 fixture.componentInstance.onValidationChange.subscribe((data) => {
213 onValidationChangeResult = data;
214 // console.log("Subscriber got data >>>>> "+ data);
217 fixture.componentInstance.verifyTypeAndFileWereFilled();
219 expect(onValidationChangeResult).toBe(false);
222 it('should verify verifyTypeAndFileWereFilled -> verify branch this.artifact.artifactType !== \'DEPLOYMENT\' ==>> onValidationChange.next(true)', () => {
223 fixture.componentInstance.artifact = artifactModel;
224 fixture.componentInstance.artifact.artifactType = 'NOT_DEPLOYMENT';
225 fixture.componentInstance.artifact.mandatory = true;
226 fixture.componentInstance.artifact.artifactName = 'Something';
227 fixture.componentInstance.descriptionIsValid = true;
229 let onValidationChangeResult;
231 fixture.componentInstance.onValidationChange.subscribe((data) => {
232 onValidationChangeResult = data;
233 // console.log("Subscriber got data >>>>> "+ data);
236 fixture.componentInstance.verifyTypeAndFileWereFilled();
238 expect(onValidationChangeResult).toBe(true);