summaryrefslogtreecommitdiffstats
path: root/gui-clamp/ui-react/src/components/dialogs
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2022-03-02 14:35:12 +0000
committerlapentafd <francesco.lapenta@est.tech>2022-03-02 16:42:17 +0000
commit315fbead01457331c75b67ffcf0e17fcfb16a58c (patch)
tree8328968c7fe6b0fe2fdc1469ef5d57c1e14b000b /gui-clamp/ui-react/src/components/dialogs
parent68d8522852e49d5553418cc19981fda25cf90d7e (diff)
Code Coverage in gui ui react
Issue-ID: POLICY-3351 Signed-off-by: lapentafd <francesco.lapenta@est.tech> Change-Id: I0a2ada8e19619eaf95012300c7a3c2c6013f2495
Diffstat (limited to 'gui-clamp/ui-react/src/components/dialogs')
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js26
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js50
2 files changed, 76 insertions, 0 deletions
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(<PerformActions loopCache={ loopCache }
+ loopAction="delete" history={ historyMock } updateLoopFunction={ updateLoopFunction } showSucAlert={ showSucAlert } showFailAlert={ showFailAlert }
+ setBusyLoading={ setBusyLoading } clearBusyLoading={ clearBusyLoading }/>)
+ 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(<PolicyModal history={ historyMock }
+ loopCache={ loopCacheMicroService } match={ matchMicroService } loadLoopFunction={ loadLoopFunctionMC }/>)
+ 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(<PolicyModal loopCache={ loopCacheMicroService } match={ matchMicroService } updateLoopFunction={ updateLoopFunction }/>)
+
+ 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(<PolicyModal loopCache={ loopCache } match={ match }/>)
component.setState({