set default values in VFM Upgrade popup
[vid.git] / vid-webpack-master / src / app / shared / components / genericFormPopup / genericFormServices / vfModuleUpgrade / vfModule.upgrade.popup.service.spec.ts
index 94def92..86ec666 100644 (file)
@@ -13,7 +13,6 @@ import {IframeService} from "../../../../utils/iframe.service";
 import {DefaultDataGeneratorService} from "../../../../services/defaultDataServiceGenerator/default.data.generator.service";
 import {BasicPopupService} from "../basic.popup.service";
 import {VfModuleControlGenerator} from "../../../genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator";
-import {SdcUiServices} from "onap-ui-angular";
 import {FeatureFlagsService} from "../../../../services/featureFlag/feature-flags.service";
 import {getTestBed, TestBed} from "@angular/core/testing";
 import {UpgradeFormControlNames, VfModuleUpgradePopupService} from "./vfModule.upgrade.popuop.service";
@@ -69,6 +68,7 @@ describe('VFModule popup service', () => {
   let fb: FormBuilder;
   let iframeService: IframeService;
   let store : NgRedux<AppState>;
+  let _sharedTreeService : SharedTreeService;
 
   beforeAll(done => (async () => {
     TestBed.configureTestingModule({
@@ -99,8 +99,12 @@ describe('VFModule popup service', () => {
     defaultDataGeneratorService = injector.get(DefaultDataGeneratorService);
     fb = injector.get(FormBuilder);
     iframeService = injector.get(IframeService);
+    _sharedTreeService = injector.get(SharedTreeService);
     store = injector.get(NgRedux);
     service.uuidData = {
+      vfModule: {
+        data: {}
+      },
       modelName: 'vfModuleName',
       vFModuleStoreKey: 'vfModuleId'
     };
@@ -129,19 +133,24 @@ describe('VFModule popup service', () => {
     }
   }
 
-  test('get controls should return retainAssignments control with true value', ()=> {
-    getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_ASSIGNMENTS, true, true);
+  test('get controls should return retainAssignments control with false', ()=> {
+    getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_ASSIGNMENTS, false, true);
   });
 
-  test('get controls should return retainVolumeGroup control with true value', ()=> {
-    getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_VOLUME_GROUPS, true, true);
+  test('get controls should return retainVolumeGroup control with false', ()=> {
+    getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_VOLUME_GROUPS, false, true);
   });
 
-  test('get controls should NOT return retainVolumeGroup control with true value', ()=> {
-    let stateCopy =_.cloneDeep(store.getState());
-    stateCopy.service.serviceHierarchy['serviceId'].vfModules['vfModuleName'].volumeGroupAllowed = false;
-    jest.spyOn(store, 'getState').mockReturnValue(stateCopy);
-    getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_VOLUME_GROUPS, null, false);
+  [true, false].forEach(notExistsOnModel => {
+    test(`retainVolumeGroup control is shown when vfModule not from model (notExistsOnModel=${notExistsOnModel})`, () => {
+      let stateCopy = _.cloneDeep(store.getState());
+      stateCopy.service.serviceHierarchy['serviceId'].vfModules['vfModuleName'].volumeGroupAllowed = false;
+      jest.spyOn(store, 'getState').mockReturnValue(stateCopy);
+
+      jest.spyOn(_sharedTreeService, 'isVfModuleCustomizationIdNotExistsOnModel').mockReturnValue(notExistsOnModel);
+
+      getControlByNameAndCheckValue(UpgradeFormControlNames.RETAIN_VOLUME_GROUPS, false, notExistsOnModel);
+    });
   });
 
   test('get controls should contain SUPPLEMENTARY_FILE controller', ()=> {
@@ -192,7 +201,7 @@ describe('VFModule popup service', () => {
     };
     form.controls = {
       supplementaryFile_hidden_content : {
-        value: '{"c": "c", "d": 1}'
+        value: '[{"name": "c", "value": "c"}, {"name": "d", "value": "1"}]'
         },
       supplementaryFile_hidden : {
         value: {
@@ -204,7 +213,7 @@ describe('VFModule popup service', () => {
     let expectedMergePayload = {
       a: "value",
       b: "another",
-      supplementaryFileContent: {c: "c", d: 1},
+      supplementaryFileContent: [{"name": "c", "value": "c"}, {"name": "d", "value": "1"}],
       supplementaryFileName: "name"
     };
 
@@ -223,7 +232,7 @@ describe('VFModule popup service', () => {
   });
 
 
-  test( 'get controls should return usePreload with false value', () => {
-    getControlByNameAndCheckValue(SDN_C_PRE_LOAD, false, true);
+  test( 'get controls should return usePreload with true value', () => {
+    getControlByNameAndCheckValue(SDN_C_PRE_LOAD, true, true);
   });
 });