VID - Feature flag for PNF in modern UI
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / shared.tree.service.spec.ts
index d7697d6..9a35d48 100644 (file)
@@ -44,6 +44,7 @@ import {VfModuleUpgradePopupService} from "../../../shared/components/genericFor
 import {SharedControllersService} from "../../../shared/components/genericForm/formControlsServices/sharedControlles/shared.controllers.service";
 import {ModalService} from "../../../shared/components/customModal/services/modal.service";
 import {CreateDynamicComponentService} from "../../../shared/components/customModal/services/create-dynamic-component.service";
+import { PnfPopupService } from "../../../shared/components/genericFormPopup/genericFormServices/pnf/pnf.popup.service";
 
 class MockAppStore<T> {
   getState() {
@@ -80,6 +81,7 @@ describe('Shared Tree Service', () => {
   let service: SharedTreeService;
   let _objectToInstanceTreeService: ObjectToInstanceTreeService;
   let store: NgRedux<AppState>;
+
   beforeAll(done => (async () => {
     TestBed.configureTestingModule({
       imports: [HttpClientTestingModule, NgReduxTestingModule, SdcUiComponentsModule],
@@ -90,6 +92,7 @@ describe('Shared Tree Service', () => {
         DefaultDataGeneratorService,
         DialogService,
         VnfPopupService,
+        PnfPopupService,
         ControlGeneratorUtil,
         AaiService,
         LogService,
@@ -179,7 +182,7 @@ describe('Shared Tree Service', () => {
     let serviceModelFromHierarchy =
       getStore().service.serviceHierarchy["1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd"];
 
-    expect(service.modelByIdentifier(serviceModelFromHierarchy, modelTypeName, modelUniqueIdOrName))
+    expect(service.modelByIdentifiers(serviceModelFromHierarchy, modelTypeName, modelUniqueIdOrName))
       .toHaveProperty("modelCustomizationName", expectedModelCustomizationName);
   });
 
@@ -192,11 +195,11 @@ describe('Shared Tree Service', () => {
     let serviceModelFromHierarchy =
       getStore().service.serviceHierarchy["1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd"];
 
-    expect(service.modelByIdentifier(serviceModelFromHierarchy, modelTypeName, modelUniqueIdOrName))
+    expect(service.modelByIdentifiers(serviceModelFromHierarchy, modelTypeName, modelUniqueIdOrName))
       .toBeUndefined();
   });
 
-  test('openAuditInfoModal should open modal for failed instance', () => {
+  test('openAuditInfoModalInsideIframe should open modal for failed instance', () => {
     jest.spyOn(AuditInfoModalComponent.openInstanceAuditInfoModal, 'next');
 
     let modelInfoServiceMock: ILevelNodeInfo = new VnfModelInfo(null, null,
@@ -250,11 +253,11 @@ describe('Shared Tree Service', () => {
     let specificNetworkInfo = [
       ModelInformationItem.createInstance('Network role', "network role 1, network role 2")
     ];
-    const actualInfoModel: ComponentInfoModel = service.addGeneralInfoItems(specificNetworkInfo,ComponentInfoType.NETWORK, getNetworkModel(),getNetworkInstance());
+    const actualInfoModel: ComponentInfoModel = service.addGeneralInfoItems(specificNetworkInfo,ComponentInfoType.NETWORK, getNetworkModelInfoFromHierarchy(),getNetworkInstance());
 
     let expectedGeneralInfo = [
-      ModelInformationItem.createInstance('Model version', '37.0'),
-      ModelInformationItem.createInstance('Model customization ID', '94fdd893-4a36-4d70-b16a-ec29c54c184f'),
+      ModelInformationItem.createInstance('Model version', '2.0'),
+      ModelInformationItem.createInstance('Model customization ID', 'customization-id-from-hierarchy'),
       ModelInformationItem.createInstance('Instance ID', 'NETWORK4_INSTANCE_ID'),
       ModelInformationItem.createInstance('Instance type', 'CONTRAIL30_HIMELGUARD'),
       ModelInformationItem.createInstance('In maintenance', false),
@@ -263,25 +266,103 @@ describe('Shared Tree Service', () => {
     expect(actualInfoModel.modelInfoItems).toEqual(expectedGeneralInfo);
   });
 
+  each([
+    ['model version from hierarchy', null, getNetworkModelInfoFromHierarchy(), '2.0'],
+    ['undefined model', null, null, undefined],
+    ['model version from instance', getSelectedModelInfo(), null, '5.0'],
+    ['model version from instance', getSelectedModelInfo(), getNetworkModelInfoFromHierarchy(), '5.0'],
+  ]).
+  test ('getModelVersionEitherFromInstanceOrFromHierarchy should return %s ' ,
+    (description, instance, model, expectedResult) =>{
+    let actualResult = service.getModelVersionEitherFromInstanceOrFromHierarchy(instance, model);
+    expect(actualResult).toEqual(expectedResult);
+  });
+
+  each([
+    ['model CustomizationId from hierarchy', null, getNetworkModelInfoFromHierarchy(), 'customization-id-from-hierarchy'],
+    ['undefined model', null, null, undefined],
+    ['model CustomizationId from instance', getSelectedModelInfo(), null, 'model-customization-id-from-instance'],
+    ['model CustomizationId from instance', getSelectedModelInfo(), getNetworkModelInfoFromHierarchy(), 'model-customization-id-from-instance'],
+  ]).
+  test ('getCustomizationIdEitherFromInstanceOrFromHierarchy should return %s ' ,
+    (description, instance, model, expectedResult) =>{
+      let actualResult = service.getModelCustomizationIdEitherFromInstanceOrFromHierarchy(instance, model);
+      expect(actualResult).toEqual(expectedResult);
+    });
+
+  each([
+    ['UUID from instance', getSelectedModelInfo(), getNetworkModelInfoFromHierarchy(),"UUID-from-instance" ],
+    ['UUID from instance', getSelectedModelInfo(), null,"UUID-from-instance" ],
+    ['UUID from hierarchy', null, getNetworkModelInfoFromHierarchy(),"UUID-from-hierarchy" ],
+    ['UUID undefined', null, null, undefined],
+
+  ]).
+  test('getModelVersionIdEitherFromInstanceOrFromHierarchy should %s', (description, instance, model, expectedResult) => {
+    let actualUuid = service.getModelVersionIdEitherFromInstanceOrFromHierarchy(instance, model);
+    expect(actualUuid).toEqual(expectedResult);
+  });
+
+  each([
+    ['from instance', getSelectedModelInfo(), getNetworkModelInfoFromHierarchy(), 'invariantId-from-instance'],
+    ['from instance', getSelectedModelInfo(), null, 'invariantId-from-instance'],
+    ['from hierarchy', null, getNetworkModelInfoFromHierarchy(), 'invariantId-from-hierarchy'],
+    ['undefined', null, null, undefined],
+  ]).
+  test('getModelInvariantIdEitherFromInstanceOrFromHierarchy should return invariantId %s', (description, instance, model, expectedInvariantId) =>{
+    let actualInvariantId = service.getModelInvariantIdEitherFromInstanceOrFromHierarchy(instance, model);
+    expect(actualInvariantId).toEqual(expectedInvariantId);
+  });
 
   test('statusProperties should be prop on node according to node properties', () => {
-    let node = service.addingStatusProperty({orchStatus: 'completed', provStatus: 'inProgress', inMaint: false});
+
+    let node = service.addingStatusProperty({orchStatus: 'completed', provStatus: 'inProgress', type: 'VFmodule', instanceModelInfo:{modelVersion: '1'}, inMaint: false});
     expect(node.statusProperties).toBeDefined();
     expect(node.statusProperties).toEqual([Object({
-      key: 'Prov Status:',
+      key: 'Prov Status: ',
       value: 'inProgress',
       testId: 'provStatus'
-    }), Object({key: 'Orch Status:', value: 'completed', testId: 'orchStatus'})]);
-    node = service.addingStatusProperty({orchStatus: 'completed', provStatus: 'inProgress', inMaint: true});
+    }), Object({
+      key: 'Orch Status: ',
+      value: 'completed',
+      testId: 'orchStatus'
+    }),
+    Object({
+      key: 'Model Version: ',
+      value: '1',
+      testId: 'modelVersion'
+    })]);
+    node = service.addingStatusProperty({orchStatus: 'completed', provStatus: 'inProgress',type: 'VFmodule',  instanceModelInfo:{}, inMaint: true});
     expect(node.statusProperties).toEqual([Object({
-      key: 'Prov Status:',
+      key: 'Prov Status: ',
       value: 'inProgress',
       testId: 'provStatus'
-    }), Object({key: 'Orch Status:', value: 'completed', testId: 'orchStatus'}), Object({
+    }), Object({
+      key: 'Orch Status: ',
+      value: 'completed',
+      testId: 'orchStatus'
+    }), Object({
+      key: 'Model Version: ',
+      value: undefined,
+      testId: 'modelVersion'
+    }), Object({
       key: 'In-maintenance',
       value: '',
       testId: 'inMaint'
-    })]);
+    })
+]);
+  });
+  each([
+    ['version 2', '2', '2'],
+    ['undefined', null, undefined]
+  ]).
+  test('getNodeModelVersion should return %s',  (description, nodeVersion, expectedVersion) => {
+    let node = <any>{
+      instanceModelInfo:{
+        modelVersion: nodeVersion
+      }
+    };
+    let actualVersion = service.getNodeModelVersion(node);
+    expect(actualVersion).toEqual(expectedVersion);
   });
 
   each([
@@ -339,6 +420,123 @@ describe('Shared Tree Service', () => {
       expect(res).toBe(enabled);
     });
 
+
+  const isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDifferProvider = [
+    ['node is part of model, but vfmodule diff by customization',
+      true, 'mDNS 01222020 0', '9fdc68e9-9f53-431c-b8a2-7e337b9a0d0a', '82160e6e-d9c4-45ef-bd19-01573ab11b61'],
+
+    ['vnf model-name not found',
+      false, 'mDNS 01222020 1', '9fdc68e9-9f53-431c-b8a2-7e337b9a0d0a', '82160e6e-d9c4-45ef-bd19-01573ab11b61'],
+
+    ['vfmodule invariant-id not found',
+      false, 'mDNS 01222020 0', 'wrong invariant-id', '82160e6e-d9c4-45ef-bd19-01573ab11b61'],
+
+    ['vfmodule customization-id match',
+      false, 'mDNS 01222020 0', '9fdc68e9-9f53-431c-b8a2-7e337b9a0d0a', 'c9b32003-febc-44e0-a97f-7630fa7fa4a0'],
+  ];
+
+  each(isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDifferProvider).test('isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer: when  %s should return %s', (description, expected, vnfModelName, invariantUuid, customizationUuid) => {
+    const serviceModelId : string = 'a243da28-c11e-45a8-9f26-0284a9a789bc';
+    spyOn(store, 'getState').and.returnValue({
+      service : {
+        serviceHierarchy : {
+          [serviceModelId] : {
+            vnfs : {
+              [vnfModelName] : {
+                vfModules : {
+                  vfModuleModelName : {
+                    invariantUuid : invariantUuid,
+                    customizationUuid : customizationUuid
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    });
+
+    const node = <any>{
+      data:{
+        modelInvariantId : '9fdc68e9-9f53-431c-b8a2-7e337b9a0d0a',
+        modelCustomizationId : 'c9b32003-febc-44e0-a97f-7630fa7fa4a0',
+        modelName : 'vfModuleModelName'
+      },
+      parent : {
+        data : {
+          modelName : "mDNS 01222020 0"
+        }
+      }
+    };
+
+    const isDiffCustomizationUuidResponse : boolean = service.isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer(node, serviceModelId);
+    expect(isDiffCustomizationUuidResponse).toEqual(expected);
+  });
+
+  each([
+    [false, true, true, false],
+    [true, true, true, true],
+    [true, true, false, true],
+    [true, false, true, true],
+    [true, false, false, false],
+  ]).
+  test('when flag is %s the UpdatedLatestVersion is %s and Vfmodule not exists on hierarchy is %s isShouldShowButtonGenericMustToBeCalled should return %s', (
+     flag: boolean,
+     isThereAnUpdatedLatestVersion: boolean,
+     isVfModuleCustomizationIdNotExistsOnModel: boolean,
+     isShouldShowButtonGenericMustToBeCalled: boolean
+     ) => {
+      let node = <any>  {};
+      let serviceModelId : string = '08c5fa17-769a-4231-bd92-aed4b0ed086d';
+      jest.spyOn(store, 'getState').mockReturnValue(<any>{
+        global: {
+          "flags": {
+            "FLAG_FLASH_REPLACE_VF_MODULE": flag,
+          },
+        }
+      });
+      spyOn(service, 'isThereAnUpdatedLatestVersion').and.returnValue(isThereAnUpdatedLatestVersion);
+      spyOn(service, 'isVfModuleCustomizationIdNotExistsOnModel').and.returnValue(isVfModuleCustomizationIdNotExistsOnModel);
+
+      expect(service.isVfMoudleCouldBeUpgraded(node, serviceModelId)).toEqual(isShouldShowButtonGenericMustToBeCalled);
+    });
+
+  each([
+    ['Vfm customization uuid not exists in model', 'not-existing-customization-uuid', 'service-model-id', true],
+    ['Vfm customization uuid exists in model', 'existing-customization-uuid', 'service-model-id', false]
+  ]).
+  test('%s when vfModuleNode is  %s and serviceModelId is %s ', (
+    description,
+    modelCustomizationId,
+    serviceModelId: string,
+    isExistsOnHierarchy: boolean,
+    ) => {
+
+    const vfModuleNode = { data: {
+        modelCustomizationId : modelCustomizationId
+      }};
+
+    jest.spyOn(store, 'getState').mockReturnValue(<any>{
+      service : {
+        "serviceHierarchy": {
+          [serviceModelId]: {
+            "vfModules": {
+              "module-1": {
+                "customizationUuid": "3d7f41c8-333b-4fee-b50d-5687e9c2170f",
+              },
+              "module-2": {
+                "customizationUuid": "existing-customization-uuid",
+              }
+            }
+          }
+        }
+      }
+    });
+    expect(service.isVfModuleCustomizationIdNotExistsOnModel(vfModuleNode, serviceModelId)).toEqual(isExistsOnHierarchy);
+
+
+  });
+
 });
 
 function getStore() {
@@ -1388,62 +1586,30 @@ function getStore() {
   }
 }
 
-function getNetworkModel(){
-  return {
-    "customizationUuid":"94fdd893-4a36-4d70-b16a-ec29c54c184f",
-    "name":"ExtVL",
-    "version":"37.0",
-    "description":"ECOMP generic virtual link (network) base type for all other service-level and global networks",
-    "uuid":"ddc3f20c-08b5-40fd-af72-c6d14636b986",
-    "invariantUuid":"379f816b-a7aa-422f-be30-17114ff50b7c",
-    "max":1,
-    "min":0,
-    "isEcompGeneratedNaming":false,
-    "type":"VL",
-    "modelCustomizationName":"ExtVL 0",
-    "roles":["network role 1"," network role 2"],
-    "properties":{
-      "network_role":"network role 1, network role 2",
-      "network_assignments":
-        "{is_external_network=false, ipv4_subnet_default_assignment={min_subnets_count=1}, ecomp_generated_network_assignment=false, ipv6_subnet_default_assignment={min_subnets_count=1}}",
-      "exVL_naming":"{ecomp_generated_naming=true}","network_flows":"{is_network_policy=false, is_bound_to_vpn=false}",
-      "network_homing":"{ecomp_selected_instance_node_target=false}"
-    }
-  };
 
+function getNetworkModelInfoFromHierarchy(){
+  return {
+    "version": "2.0",
+    "customizationUuid":"customization-id-from-hierarchy",
+    "uuid": "UUID-from-hierarchy",
+    "invariantUuid": "invariantId-from-hierarchy"
+  }
 }
 
+function getSelectedModelInfo() {
+  return {
+    "instanceModelInfo": {
+      "modelVersion": "5.0",
+      "modelCustomizationId": "model-customization-id-from-instance",
+      "modelVersionId": "UUID-from-instance",
+      "modelInvariantId": "invariantId-from-instance"
+    }
+  }
+}
 function getNetworkInstance() {
   return {
-    "modelCustomizationId": "94fdd893-4a36-4d70-b16a-ec29c54c184f",
-    "modelId": "ddc3f20c-08b5-40fd-af72-c6d14636b986",
-    "modelUniqueId": "94fdd893-4a36-4d70-b16a-ec29c54c184f",
-    "missingData": true,
-    "id": "NETWORK4_INSTANCE_ID",
-    "action": "None",
-    "orchStatus": "Created",
-    "provStatus": "preprov",
     "inMaint": false,
     "instanceId": "NETWORK4_INSTANCE_ID",
     "instanceType": "CONTRAIL30_HIMELGUARD",
-    "instanceName": "NETWORK4_INSTANCE_NAME",
-    "name": "NETWORK4_INSTANCE_NAME",
-    "modelName": "ExtVL 0",
-    "type": "VL",
-    "isEcompGeneratedNaming": false,
-    "networkStoreKey": "NETWORK4_INSTANCE_ID",
-    "typeName": "N",
-    "menuActions": {"edit": {}, "showAuditInfo": {}, "duplicate": {}, "remove": {}, "delete": {}, "undoDelete": {}},
-    "isFailed": false,
-    "statusMessage": "",
-    "statusProperties": [{"key": "Prov Status:", "value": "preprov", "testId": "provStatus"}, {
-      "key": "Orch Status:",
-      "value": "Created",
-      "testId": "orchStatus"
-    }],
-    "trackById": "1wvr73xl999",
-    "parentType": "",
-    "componentInfoType": "Network",
-    "errors": {}
   };
 }