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 4003b4d..86ec666 100644 (file)
@@ -1,10 +1,10 @@
 import {LogService} from "../../../../utils/log/log.service";
 import {NgRedux} from "@angular-redux/store";
 import {
-  BasicControlGenerator,
+  ControlGeneratorUtil,
   SDN_C_PRE_LOAD,
   SUPPLEMENTARY_FILE
-} from "../../../genericForm/formControlsServices/basic.control.generator";
+} from "../../../genericForm/formControlsServices/control.generator.util.service";
 import {AaiService} from "../../../../services/aaiService/aai.service";
 import {HttpClient} from "@angular/common/http";
 import {GenericFormService} from "../../../genericForm/generic-form.service";
@@ -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";
@@ -25,6 +24,8 @@ import {VfModuleActions} from "../../../../storeUtil/utils/vfModule/vfModule.act
 import {ServiceActions} from "../../../../storeUtil/utils/service/service.actions";
 import {FormControlModel} from "../../../../models/formControlModels/formControl.model";
 import * as _ from "lodash";
+import {SharedControllersService} from "../../../genericForm/formControlsServices/sharedControlles/shared.controllers.service";
+import {ModalService} from "../../../customModal/services/modal.service";
 
 class MockModalService<T> {}
 
@@ -67,12 +68,14 @@ describe('VFModule popup service', () => {
   let fb: FormBuilder;
   let iframeService: IframeService;
   let store : NgRedux<AppState>;
+  let _sharedTreeService : SharedTreeService;
 
   beforeAll(done => (async () => {
     TestBed.configureTestingModule({
       providers: [
         VfModuleUpgradePopupService,
-        BasicControlGenerator,
+        ControlGeneratorUtil,
+        SharedControllersService,
         VfModuleControlGenerator,
         DefaultDataGeneratorService,
         GenericFormService,
@@ -85,7 +88,7 @@ describe('VFModule popup service', () => {
         {provide: FeatureFlagsService, useClass: MockFeatureFlagsService},
         {provide: NgRedux, useClass: MockReduxStore},
         {provide: HttpClient, useClass: MockAppStore},
-        {provide: SdcUiServices.ModalService, useClass: MockModalService}
+        {provide: ModalService, useClass: MockModalService}
       ]
     });
     await TestBed.compileComponents();
@@ -96,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'
     };
@@ -126,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', ()=> {
@@ -189,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: {
@@ -201,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"
     };
 
@@ -220,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);
   });
 });