From 560933802c75e62c7ba9199025edf871bc9a74d5 Mon Sep 17 00:00:00 2001 From: Alexey Sandler Date: Thu, 13 Feb 2020 09:53:14 +0200 Subject: create unit test for shouldShowUpgrade function Issue-ID: VID-758 Signed-off-by: Alexey Sandler Change-Id: I11790efb51007275b8b1331dbfd31ada7eabd3e2 Signed-off-by: Alexey Sandler --- .../objectsToTree/shared.tree.service.spec.ts | 29 ++++++++++++++++++++++ .../objectsToTree/shared.tree.service.ts | 12 ++++----- 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'vid-webpack-master/src') diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.spec.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.spec.ts index 8905d4110..3499377ac 100644 --- a/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.spec.ts +++ b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.spec.ts @@ -80,6 +80,7 @@ describe('Shared Tree Service', () => { let service: SharedTreeService; let _objectToInstanceTreeService: ObjectToInstanceTreeService; let store: NgRedux; + beforeAll(done => (async () => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule, NgReduxTestingModule, SdcUiComponentsModule], @@ -392,6 +393,34 @@ describe('Shared Tree Service', () => { 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 CustomizationUuid Differ is %s isShouldShowButtonGenericMustToBeCalled should return %s', ( + flag: boolean, + isThereAnUpdatedLatestVersion: boolean, + isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer: boolean, + isShouldShowButtonGenericMustToBeCalled: boolean + ) => { + let node = {}; + let serviceModelId : string = '08c5fa17-769a-4231-bd92-aed4b0ed086d'; + jest.spyOn(store, 'getState').mockReturnValue({ + global: { + "flags": { + "FLAG_FLASH_REPLACE_VF_MODULE": flag, + }, + } + }); + spyOn(service, 'isThereAnUpdatedLatestVersion').and.returnValue(isThereAnUpdatedLatestVersion); + spyOn(service, 'isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer').and.returnValue(isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer); + + expect(service.isVfMoudleCouldBeUpgraded(node, serviceModelId)).toEqual(isShouldShowButtonGenericMustToBeCalled); + }); + }); function getStore() { diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.ts index 9e7a0211e..de859e4ea 100644 --- a/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.ts +++ b/vid-webpack-master/src/app/drawingBoard/service-planning/objectsToTree/shared.tree.service.ts @@ -216,13 +216,13 @@ export class SharedTreeService { * should return true if customer can upgrade a VFM * ****************************************************/ shouldShowUpgrade(node, serviceModelId): boolean { - if (FeatureFlagsService.getFlagState(Features.FLAG_FLASH_REPLACE_VF_MODULE, this._store) && - (this.isThereAnUpdatedLatestVersion(serviceModelId)) || this.isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer(node, serviceModelId)) { - return this.shouldShowButtonGeneric(node, VNFMethods.UPGRADE, serviceModelId); - } - else { - return false + return (this.isVfMoudleCouldBeUpgraded(node, serviceModelId)) + && this.shouldShowButtonGeneric(node, VNFMethods.UPGRADE, serviceModelId) ; } + + isVfMoudleCouldBeUpgraded(node, serviceModelId): boolean{ + return (FeatureFlagsService.getFlagState(Features.FLAG_FLASH_REPLACE_VF_MODULE, this._store) && + ((this.isThereAnUpdatedLatestVersion(serviceModelId)) || this.isVfmoduleAlmostPartOfModelOnlyCustomizationUuidDiffer(node, serviceModelId))) } -- cgit 1.2.3-korg