Hide Templates entry point when no instances 07/100007/3
authorYoav Schneiderman <yoav.schneiderman@intl.att.com>
Sun, 5 Jan 2020 13:03:16 +0000 (15:03 +0200)
committerYoav Schneiderman <yoav.schneiderman@intl.att.com>
Mon, 6 Jan 2020 11:04:17 +0000 (13:04 +0200)
Issue-ID: VID-741
Signed-off-by: Yoav Schneiderman <yoav.schneiderman@intl.att.com>
Change-Id: I9f2c1879b30ed15b227cdd6189d14ef988bc3b1e
Signed-off-by: Yoav Schneiderman <yoav.schneiderman@intl.att.com>
13 files changed:
vid-webpack-master/cypress/integration/iFrames/instantiation.templates.modal.e2e.ts
vid-webpack-master/cypress/integration/iFrames/service.popup.e2e.ts
vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/objectToModelTree/objectToModelTree.service.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.component.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.service.spec.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/generic-form-popup.service.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/genericFormServices/service/service.popup.service.spec.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/instantiationTemplatesModal/instantiation.templates.modal.service.spec.ts
vid-webpack-master/src/app/shared/components/genericFormPopup/instantiationTemplatesModal/instantiation.templates.modal.service.ts
vid-webpack-master/src/app/shared/components/spinner/spinner.component.ts
vid-webpack-master/src/app/shared/services/featureFlag/feature-flags.service.ts
vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts
vid-webpack-master/src/app/vlanTagging/network-selector/network-selector.component.ts

index 73d3115..0db1b09 100644 (file)
@@ -71,7 +71,7 @@ describe('Template', () => {
 
     cy.route(Cypress.config('baseUrl') + "/getuserID", 'us16807000');
 
-    cy.openPopupIframe('/app/ui/#/servicePopup?serviceModelId=2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd&isCreate=true');
+    cy.openPopupIframe('/app/ui/#/servicePopup?serviceModelId=2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd&isCreate=true&hasTemplate=true');
 
   });
 
@@ -117,10 +117,15 @@ describe('Template', () => {
     cy.getElementByDataTestsId('filterByUserIdTestId').click();
     cy.get('.member-table-row').should('have.length', 1);
 
+
+    // navigate to service modal -> should show Template button
+    cy.getElementByDataTestsId('startFromScratchButton').click().then(()=>{
+      cy.getElementByDataTestsId('templateButton').should('be.visible')
+    });
+
   });
 
   it('clicking on load template button, go to expected url', function () {
-
     cy.getElementByDataTestsId('templateButton').contains('Template')
     .getElementByDataTestsId('templateButton').click({force: true}) // Open template Modal
 
index 83e6b4d..4b27ad0 100644 (file)
@@ -30,6 +30,17 @@ describe('Service popup', function () {
       });
     });
 
+    it('a-la-carte service instantiation popup should show Template button ', function () {
+      cy.readFile('cypress/support/jsonBuilders/mocks/jsons/emptyServiceRedux.json').then((res1) => {
+        res1.service.serviceHierarchy["2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd"].service.vidNotions.instantiationType = 'ALaCarte';
+        res1.global.flags = {};
+        res1.global.flags["FLAG_2004_INSTANTIATION_TEMPLATES_POPUP"] = true;
+        cy.setReduxState(<any>res1);
+        cy.openPopupIframe('/app/ui/#/servicePopup?serviceModelId=2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd&isCreate=true&hasTemplate=true');
+        cy.getElementByDataTestsId('templateButton').should('be.visible')
+      });
+    });
+
     it('a-la-carte service instantiation popup has Instance name as required', function () {
       cy.readFile('cypress/support/jsonBuilders/mocks/jsons/emptyServiceRedux.json').then((res1) => {
         res1.service.serviceHierarchy["2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd"].service.vidNotions.instantiationType = 'ALaCarte';
@@ -39,6 +50,7 @@ describe('Service popup', function () {
         cy.openPopupIframe('/app/ui/#/servicePopup?serviceModelId=2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd&isCreate=true');
         cy.isElementContainsAttr('form-set', 'disabled');
         cy.get('label').contains('Instance name:').should('have.class', 'required');
+        cy.getElementByDataTestsId('templateButton').should('not.be.visible')
       });
     });
 
index eb60865..9063e67 100644 (file)
@@ -8,7 +8,7 @@ import * as _ from "lodash";
 import {NgRedux} from "@angular-redux/store";
 import {AppState} from "../../store/reducers";
 import {ServicePopupService} from "./genericFormServices/service/service.popup.service";
-import {ActivatedRoute} from "@angular/router";
+import {ActivatedRoute, Router} from "@angular/router";
 import {AaiService} from "../../services/aaiService/aai.service";
 import {GenericFormPopupService} from "./generic-form-popup.service";
 import {FormControlModel} from "../../models/formControlModels/formControl.model";
@@ -53,7 +53,7 @@ export class GenericFormPopupComponent extends DialogComponent<PopupModel, boole
   hasGeneralApiError: boolean = false;
   parentElementClassName = 'content';
   errorMsg = 'Page contains errors. Please see details next to the relevant fields.';
-
+  serviceModelId : string;
   servicesQty = 1;
   quantityOptions = _.range(1, 51)
 
@@ -65,6 +65,7 @@ export class GenericFormPopupComponent extends DialogComponent<PopupModel, boole
               private _aaiService: AaiService,
               private _dialogService: DialogService,
               private _route: ActivatedRoute,
+              private _router : Router,
               private _genericFormPopupService: GenericFormPopupService) {
     super(dialogService);
   }
@@ -86,9 +87,9 @@ export class GenericFormPopupComponent extends DialogComponent<PopupModel, boole
     this._route
       .queryParams
       .subscribe(params => {
-        console.log('changed');
-        if (params['serviceModelId'] && params['isCreate'] == "true") {
-          this.onInitForCreateNewServicePopup();
+        this.serviceModelId = params['serviceModelId'];
+        if (this.serviceModelId && params['isCreate'] == "true") {
+          this.onInitForCreateNewServicePopup(params['hasTemplate']);
         }
       });
 
@@ -106,7 +107,7 @@ export class GenericFormPopupComponent extends DialogComponent<PopupModel, boole
     }
   }
 
-  private onInitForCreateNewServicePopup() {
+  private onInitForCreateNewServicePopup(hasTemplate : boolean) {
     this._genericFormPopupService.initReduxOnCreateNewService().then((serviceModelId: string) => {
       this.uuidData = <any>{
         bulkSize: 1,
@@ -115,8 +116,8 @@ export class GenericFormPopupComponent extends DialogComponent<PopupModel, boole
         serviceId: serviceModelId,
         popupService: this._servicePopupService,
       };
-      this.showTemplateBtn = !!this._store.getState().global.flags["FLAG_2004_INSTANTIATION_TEMPLATES_POPUP"];
 
+      this.showTemplateBtn = this._genericFormPopupService.shouldShowTemplateBtn(hasTemplate);
       this.isShowPreviousInstantiationBtn = !!this._store.getState().global.flags["FLAG_2004_TEMP_BUTTON_TO_INSTANTIATION_STATUS_FILTER"];
 
       this.uuidData.popupService.closeDialogEvent.subscribe((that) => {
@@ -154,7 +155,7 @@ export class GenericFormPopupComponent extends DialogComponent<PopupModel, boole
 
 
   openTemplateModal = (): void => {
-    this._dialogService.addDialog(InstantiationTemplatesModalComponent, {});
+    this._router.navigate(['/instantiationTemplatesPopup'], { queryParams: { serviceModelId: this.serviceModelId}, queryParamsHandling: 'merge' });
   }
 
 }
index ac417ed..53f345a 100644 (file)
@@ -22,6 +22,8 @@ import {VfModuleControlGenerator} from "../genericForm/formControlsServices/vfMo
 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';
 
 class MockAppStore<T>{
   getState() {
@@ -951,6 +953,8 @@ describe('Generic Form popup Service', () => {
   let servicePopupService : ServicePopupService;
   let _aaiService : AaiService;
   let _activatedRoute : ActivatedRoute;
+  let _store : NgRedux<AppState>;
+  let _featureFlagsService : FeatureFlagsService;
 
   beforeAll(done => (async () => {
     TestBed.configureTestingModule({
@@ -972,7 +976,7 @@ describe('Generic Form popup Service', () => {
         VfModulePopupService,
         VfModuleUpgradePopupService,
         VfModuleControlGenerator,
-        {provide:FeatureFlagsService, useClass: MockFeatureFlagsService},
+        FeatureFlagsService,
         {provide: ActivatedRoute, useClass: ActivatedRouteMock},
         {provide: NgRedux, useClass: MockAppStore}]
     });
@@ -987,7 +991,8 @@ describe('Generic Form popup Service', () => {
     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));
 
 
@@ -1065,5 +1070,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 template', true , true, true],
+    ['shouldShowTemplateBtn : should return false if flag is false and has template',false , true, false],
+    ['shouldShowTemplateBtn : should return false if flag is true and has no template',true , false, false],
+    ['shouldShowTemplateBtn : should return false if flag is false and has no template',false , false, false]];
+  each(shouldShowTemplateBtnDataProvider).test('%s', (desc : string, flag : boolean, hasTemplate : boolean, expected : boolean ) => {
+    spyOn(_featureFlagsService, 'getFlagState').and.returnValue(flag)
+
+    const result: boolean = service.shouldShowTemplateBtn(hasTemplate);
+    expect(result).toEqual(expected);
+  });
 });
index 6636a54..2998ba9 100644 (file)
@@ -10,6 +10,7 @@ import {UUIDData} from "./generic-form-popup.component";
 import {FormPopupDetails} from "../../models/formControlModels/formPopupDetails.model";
 import {Subject} from "rxjs";
 import {deleteAllServiceInstances} from "../../storeUtil/utils/service/service.actions";
+import {FeatureFlagsService, Features} from "../../services/featureFlag/feature-flags.service";
 
 @Injectable()
 export class GenericFormPopupService {
@@ -17,6 +18,7 @@ export class GenericFormPopupService {
               private _store: NgRedux<AppState>,
               private _servicePopupService : ServicePopupService,
               public _activatedRoute : ActivatedRoute,
+              private _featureFlagsService : FeatureFlagsService,
               private _aaiService : AaiService){
 
   }
@@ -90,4 +92,14 @@ export class GenericFormPopupService {
   }
 
   refreshModalCheckForGeneralErrorTrigger : Subject<boolean> = new Subject<boolean>();
+
+
+
+  shouldShowTemplateBtn = (hasTemplate: boolean) : boolean => {
+    const instantiationTemplateFlag =  this._featureFlagsService.getFlagState(Features.FLAG_2004_INSTANTIATION_TEMPLATES_POPUP);
+    if(instantiationTemplateFlag){
+      return hasTemplate;
+    }
+    return false;
+  }
 }
index 0ce051c..3a106ec 100644 (file)
@@ -2172,7 +2172,6 @@ describe('Service popup service', () => {
 
   test('getDynamicInputs should return list of controls' ,() => {
     const result:  FormControlModel[] = service.getDynamicInputs('6b528779-44a3-4472-bdff-9cd15ec93450');
-    console.log(result);
     expect(result.length).toEqual(4);
     expect(result[0].controlName).toEqual('2017488_pasqualevpe0_ASN_1');
     expect(result[1].controlName).toEqual('2017488_pasqualevpe0_ASN_2');
index 308597a..61f75e8 100644 (file)
@@ -173,7 +173,7 @@ describe('instantiation templates modal service', () => {
 
     service.navigateToNewServiceModal(serviceModelId);
 
-    expect(_router.navigate).toBeCalledWith(["/servicePopup"], {"queryParams": {"isCreate": true, "serviceModelId": serviceModelId}, "queryParamsHandling": "merge"});
+    expect(_router.navigate).toBeCalledWith(["/servicePopup"], {"queryParams": {"isCreate": true, "serviceModelId": serviceModelId, hasTemplate : true}, "queryParamsHandling": "merge"});
   })
 
 });
index c175918..c7c198f 100644 (file)
@@ -30,7 +30,7 @@ export class InstantiationTemplatesModalService {
 
 
   navigateToNewServiceModal(serviceModelId: string) {
-     this._router.navigate(['/servicePopup'], { queryParams: { serviceModelId: serviceModelId, isCreate:true}, queryParamsHandling: 'merge' });
+     this._router.navigate(['/servicePopup'], { queryParams: { serviceModelId: serviceModelId, isCreate:true, hasTemplate : true}, queryParamsHandling: 'merge' });
   }
 
 }
index 94a0e1c..ebaca62 100644 (file)
@@ -29,7 +29,6 @@ export class SpinnerComponent{
       }else {
         delete this.requestMap[requestUrl]
       }
-      console.log(this.requestMap);
       this.show = !_.isEmpty(this.requestMap) && this.requestMap !== undefined;
 
     })
index 74fcd8f..cccade8 100644 (file)
@@ -16,6 +16,7 @@ export enum Features {
   FLAG_2004_INSTANTIATION_STATUS_FILTER ='FLAG_2004_INSTANTIATION_STATUS_FILTER',
   FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE = 'FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE',
   FLAG_2004_TEMP_BUTTON_TO_INSTANTIATION_STATUS_FILTER ='FLAG_2004_TEMP_BUTTON_TO_INSTANTIATION_STATUS_FILTER',
+  FLAG_2004_INSTANTIATION_TEMPLATES_POPUP = 'FLAG_2004_INSTANTIATION_TEMPLATES_POPUP'
 }
 
 @Injectable()
index 9b3a287..91b749e 100644 (file)
@@ -251,7 +251,6 @@ test('#DELETE_ACTION_VF_MODULE_INSTANCE', () => {
       serviceId: 'serviceModelId'
     }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1'];
 
-  console.log(vfModule.action);
   expect(vfModule).toBeDefined();
   expect(vfModule.isMissingData).toBeTruthy();
   expect(vfModule.action).toEqual(ServiceInstanceActions.None_Delete);
@@ -287,7 +286,6 @@ test('#UNDO_DELETE_ACTION_VF_MODULE_INSTANCE', () => {
       serviceId: 'serviceModelId'
     }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1'];
 
-  console.log(vfModule.action);
   expect(vfModule).toBeDefined();
   expect(vfModule.action).toEqual(ServiceInstanceActions.None);
 });
index d3df926..c0aeb0b 100644 (file)
@@ -26,7 +26,6 @@ export class NetworkSelectorComponent implements OnInit {
   constructor(store: NgRedux<AppState>) {
     this.localStore = store;
     this.groupSelection = {};
-    console.log(store);
   }
 
   getValueOfLabelInGroup(group: any, label: string){