From 315fbead01457331c75b67ffcf0e17fcfb16a58c Mon Sep 17 00:00:00 2001 From: lapentafd Date: Wed, 2 Mar 2022 14:35:12 +0000 Subject: Code Coverage in gui ui react Issue-ID: POLICY-3351 Signed-off-by: lapentafd Change-Id: I0a2ada8e19619eaf95012300c7a3c2c6013f2495 --- .../src/components/dialogs/PerformActions.test.js | 26 +++++++++++ .../components/dialogs/Policy/PolicyModal.test.js | 50 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) (limited to 'gui-clamp/ui-react') diff --git a/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js b/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js index 74c9145..e5a2f9f 100644 --- a/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js +++ b/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -92,4 +93,29 @@ describe('Verify PerformActions', () => { expect(historyMock.push.mock.calls[0]).toEqual(['/']); }); + it('Test the delete method action', async () => { + const flushPromises = () => new Promise(setImmediate); + const historyMock = { push: jest.fn() }; + const updateLoopFunction = jest.fn(); + const showSucAlert = jest.fn(); + const showFailAlert = jest.fn(); + const setBusyLoading = jest.fn(); + const clearBusyLoading = jest.fn(); + + LoopActionService.refreshStatus = jest.fn().mockImplementation(() => { + return Promise.resolve({ + ok: true, + status: 200, + json: () => { + } + }); + }); + const component = shallow() + await flushPromises(); + component.update(); + + expect(historyMock.push.mock.calls[0]).toEqual(['/']); + }); }); diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js index 2cb1af5..0f7d528 100644 --- a/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js +++ b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights * reserved. + * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,10 +55,27 @@ describe('Verify PolicyModal', () => { }] }; + const loopCacheStrMC = { + "name": "MICROSERVICE_type_tca", + "microServicePolicies": [{ + "name": "MICROSERVICE_type", + "configurationsJson": { + "operational_policy": { + "acm": {}, + "policies": [] + } + }, + "policyModel": { "policyPdpGroup": { "supportedPdpGroups": [{ "monitoring": ["xacml"] }] } }, + "jsonRepresentation": { "schema": {} } + }] + }; + const loopCache = new LoopCache(loopCacheStr); const historyMock = { push: jest.fn() }; const flushPromises = () => new Promise(setImmediate); const match = { params: { policyName: "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", policyInstanceType: OnapConstant.operationalPolicyType } } + const loopCacheMicroService = new LoopCache(loopCacheStrMC); + const matchMicroService = { params: { policyName: "MICROSERVICE_type", policyInstanceType: OnapConstant.microServiceType } } it('Test handleClose', () => { const handleClose = jest.spyOn(PolicyModal.prototype, 'handleClose'); @@ -85,6 +103,20 @@ describe('Verify PolicyModal', () => { expect(historyMock.push.mock.calls[0]).toEqual(['/']); }); + it('Test handleSave MicroService', async () => { + const loadLoopFunctionMC = jest.fn(); + const handleSaveMC = jest.spyOn(PolicyModal.prototype, 'handleSave'); + const componentMC = mount() + componentMC.find('[variant="primary"]').get(0).props.onClick(); + await flushPromises(); + componentMC.update(); + + expect(handleSaveMC).toHaveBeenCalledTimes(2); //The 1st call it's done in the previous test + expect(componentMC.state('show')).toEqual(false); + expect(historyMock.push.mock.calls[0]).toEqual(['/']); + }); + it('Test handleRefresh', async () => { LoopService.refreshOperationalPolicyJson = jest.fn().mockImplementation(() => { return Promise.resolve(loopCacheStr); @@ -103,6 +135,24 @@ describe('Verify PolicyModal', () => { expect(component.state('showMessage')).toEqual("Successfully refreshed"); }); + it('Test handleRefresh MicroService Fail', async () => { + LoopService.refreshOperationalPolicyJson = jest.fn().mockImplementation(() => { + return Promise.resolve(loopCacheStrMC); + }); + const updateLoopFunction = jest.fn(); + const handleRefresh = jest.spyOn(PolicyModal.prototype, 'handleRefresh'); + const component = mount() + + component.find('[variant="primary"]').get(1).props.onClick(); + await flushPromises(); + component.update(); + + expect(handleRefresh).toHaveBeenCalledTimes(2); + expect(component.state('show')).toEqual(true); + expect(component.state('showSucAlert')).toEqual(false); + expect(component.state('showMessage')).toEqual("Refreshing of UI failed"); + }); + it('Test handlePdpGroupChange', () => { const component = mount() component.setState({ -- cgit 1.2.3-korg