Merge "Product family ID on VNF should be mandatory"
[vid.git] / vid-webpack-master / src / app / shared / components / genericFormPopup / generic-form-popup.service.spec.ts
index fa77bed..e69cd56 100644 (file)
@@ -5,7 +5,7 @@ import {GenericFormPopupService} from "./generic-form-popup.service";
 import {IframeService} from "../../utils/iframe.service";
 import {NgRedux} from "@angular-redux/store";
 import {ServicePopupService} from "./genericFormServices/service/service.popup.service";
-import {BasicControlGenerator} from "../genericForm/formControlsServices/basic.control.generator";
+import {ControlGeneratorUtil} from "../genericForm/formControlsServices/control.generator.util.service";
 import {AaiService} from "../../services/aaiService/aai.service";
 import {ServiceControlGenerator} from "../genericForm/formControlsServices/service.control.generator";
 import {GenericFormService} from "../genericForm/generic-form.service";
@@ -17,9 +17,14 @@ import {UUIDData} from "./generic-form-popup.component";
 import {ITreeNode} from "angular-tree-component/dist/defs/api";
 import {NetworkPopupService} from "./genericFormServices/network/network.popup.service";
 import {NetworkControlGenerator} from "../genericForm/formControlsServices/networkGenerator/network.control.generator";
-import {VfModulePopuopService} from "./genericFormServices/vfModule/vfModule.popuop.service";
+import {VfModulePopupService} from "./genericFormServices/vfModule/vfModule.popup.service";
 import {VfModuleControlGenerator} from "../genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator";
 import {FeatureFlagsService} from "../../services/featureFlag/feature-flags.service";
+import {VfModuleUpgradePopupService} from "./genericFormServices/vfModuleUpgrade/vfModule.upgrade.popuop.service";
+import {SharedControllersService} from "../genericForm/formControlsServices/sharedControlles/shared.controllers.service";
+import {AppState} from "../../store/reducers";
+import each from 'jest-each';
+import {SharedTreeService} from "../../../drawingBoard/service-planning/objectsToTree/shared.tree.service";
 
 class MockAppStore<T>{
   getState() {
@@ -32,9 +37,6 @@ class MockAppStore<T>{
           "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
           "FLAG_SHOW_VERIFY_SERVICE": false,
           "FLAG_SERVICE_MODEL_CACHE": true,
-          "CREATE_INSTANCE_TEST": false,
-          "FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD": false,
-          "EMPTY_DRAWING_BOARD_TEST": false,
           "FLAG_ADD_MSO_TESTAPI_FIELD": true
         },
         "type": "[FLAGS] Update"
@@ -948,10 +950,12 @@ describe('Generic Form popup Service', () => {
   let form : FormGroup;
   let fb : FormBuilder;
   let netwokPopupService : NetworkPopupService;
-  let vfModulePopupService : VfModulePopuopService;
+  let vfModulePopupService : VfModulePopupService;
   let servicePopupService : ServicePopupService;
   let _aaiService : AaiService;
   let _activatedRoute : ActivatedRoute;
+  let _store : NgRedux<AppState>;
+  let _featureFlagsService : FeatureFlagsService;
 
   beforeAll(done => (async () => {
     TestBed.configureTestingModule({
@@ -960,7 +964,8 @@ describe('Generic Form popup Service', () => {
         FormBuilder,
         IframeService,
         ServicePopupService,
-        BasicControlGenerator,
+        ControlGeneratorUtil,
+        SharedControllersService,
         ServiceControlGenerator,
         GenericFormService,
         LogService,
@@ -969,9 +974,11 @@ describe('Generic Form popup Service', () => {
         AaiService,
         NetworkPopupService,
         NetworkControlGenerator,
-        VfModulePopuopService,
+        VfModulePopupService,
+        VfModuleUpgradePopupService,
         VfModuleControlGenerator,
-        {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
+        FeatureFlagsService,
+        SharedTreeService,
         {provide: ActivatedRoute, useClass: ActivatedRouteMock},
         {provide: NgRedux, useClass: MockAppStore}]
     });
@@ -982,11 +989,12 @@ describe('Generic Form popup Service', () => {
     httpMock = injector.get(HttpTestingController);
     fb = injector.get(FormBuilder);
     netwokPopupService = injector.get(NetworkPopupService);
-    vfModulePopupService = injector.get(VfModulePopuopService);
+    vfModulePopupService = injector.get(VfModulePopupService);
     servicePopupService = injector.get(ServicePopupService);
     _aaiService = injector.get(AaiService);
     _activatedRoute = injector.get(ActivatedRoute);
-
+    _store = injector.get(NgRedux);
+    _featureFlagsService = injector.get(FeatureFlagsService);
   })().then(done).catch(done.fail));
 
 
@@ -1064,5 +1072,18 @@ describe('Generic Form popup Service', () => {
   test('initReduxOnCreateNewService',() => {
     jest.spyOn(_aaiService, 'getServiceModelById');
     service.initReduxOnCreateNewService();
-  })
+  });
+
+
+  const shouldShowTemplateBtnDataProvider = [
+    ['shouldShowTemplateBtn : should return true if flag is true and has instantiation template', true , true, true],
+    ['shouldShowTemplateBtn : should return false if flag is false and has instantiation template',false , true, false],
+    ['shouldShowTemplateBtn : should return false if flag is true and has no instantiation template',true , false, false],
+    ['shouldShowTemplateBtn : should return false if flag is false and has no instantiation template',false , false, false]];
+  each(shouldShowTemplateBtnDataProvider).test('%s', (desc : string, flag : boolean, isInstantiationTemplateExists : boolean, expected : boolean ) => {
+    spyOn(_featureFlagsService, 'getFlagState').and.returnValue(flag)
+
+    const result: boolean = service.shouldShowTemplateBtn(isInstantiationTemplateExists);
+    expect(result).toEqual(expected);
+  });
 });