From 358dda975be66999db4abbe185e348763cdb24f9 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Tue, 26 Nov 2019 10:18:03 +0200 Subject: Extract concatSupplementaryFile out of VFM controller Issue-ID: VID-603 Signed-off-by: Eylon Malin Change-Id: I7522442e5ae3109ac1abeca1f82b2a980a10e30d --- .../basic.control.generator.spec.ts | 21 +++++++++++++++++++++ .../formControlsServices/basic.control.generator.ts | 5 +++++ .../vfModuleGenerator/vfModule.control.generator.ts | 9 ++------- 3 files changed, 28 insertions(+), 7 deletions(-) (limited to 'vid-webpack-master/src/app') diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts index 8705fa8ff..e97ed9ca3 100644 --- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts +++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts @@ -53,5 +53,26 @@ describe('Basic Control Generator', () => { expect(suppFileForInstance.hiddenFile.length).toBeGreaterThanOrEqual(1); expect(suppFileForInstance.hiddenFile[0].validations[0].validatorName).toEqual("isFileTooBig"); }); + + test('concatSupplementaryFile add SupplementaryFile control and hidden file', () => { + + //given + const instance = {}; + const controls = [service.getLegacyRegion(instance)]; + expect(controls).toHaveLength(1); + + //when + const result = service.concatSupplementaryFile(controls, instance); + + //then + expect(controls).toHaveLength(1); //original controls remain the same + + expect(result.map((control) => {return control.controlName})).toEqual([ + "legacyRegion", + "supplementaryFile", + "supplementaryFile_hidden", + "supplementaryFile_hidden_content" + ]); + }); }); diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts index 0261a72a4..f7075e7d8 100644 --- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts +++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts @@ -239,6 +239,11 @@ export class BasicControlGenerator { return initialInstanceName; } + concatSupplementaryFile(originalArray: FormControlModel[], vfModuleInstance): FormControlModel[] { + let suppFileInput: FileFormControl = (this.getSupplementaryFile(vfModuleInstance)); + return originalArray.concat([suppFileInput], suppFileInput.hiddenFile); + } + getSupplementaryFile(instance: any): FileFormControl { return new FileFormControl({ controlName: SUPPLEMENTARY_FILE, diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts index a2dd52197..762cb41dd 100644 --- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts +++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts @@ -105,9 +105,7 @@ export class VfModuleControlGenerator { result = this.pushInstanceAndVGToForm(result, vfModuleInstance, serviceId, vnfModel, false); } if(this.store.getState().global.flags['FLAG_SUPPLEMENTARY_FILE']) { - let suppFileInput:FileFormControl = (this._basicControlGenerator.getSupplementaryFile(vfModuleInstance)); - result.push(suppFileInput); - result = result.concat(suppFileInput.hiddenFile); + result = this._basicControlGenerator.concatSupplementaryFile(result, vfModuleInstance); } return result; } @@ -142,12 +140,9 @@ export class VfModuleControlGenerator { result.push(this.getRollbackOnFailureControl(vfModuleInstance, result)); result.push(this.getSDNCControl(vfModuleInstance, result)); if(this.store.getState().global.flags['FLAG_SUPPLEMENTARY_FILE']) { - let suppFileInput:FileFormControl = (this._basicControlGenerator.getSupplementaryFile(vfModuleInstance)); - result.push(suppFileInput); - result = result.concat(suppFileInput.hiddenFile); + result = this._basicControlGenerator.concatSupplementaryFile(result, vfModuleInstance); } return result; - } getInstanceName(instance: any, serviceId: string, isEcompGeneratedNaming: boolean): FormControlModel { -- cgit 1.2.3-korg