summaryrefslogtreecommitdiffstats
path: root/gui-clamp
diff options
context:
space:
mode:
authorbrunomilitzer <bruno.militzer@est.tech>2022-01-27 17:51:58 +0000
committerbrunomilitzer <bruno.militzer@est.tech>2022-01-28 13:58:53 +0000
commitf8ec2dcdcec8a686d3e58d82a99aa097df2f0c41 (patch)
treedc981ad80437976d89662e01139cc26c6da463e4 /gui-clamp
parent9957cf988f2199d9d0ff3838e7f90e70d9cb6ae8 (diff)
Added Menu and Loop Jest Tests
Issue-ID: POLICY-3876 Change-Id: I5f4d80aefdff8b837a40742b66727b888e985b86 Signed-off-by: brunomilitzer <bruno.militzer@est.tech>
Diffstat (limited to 'gui-clamp')
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js4
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.test.js32
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js7
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js135
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Policy/toscaModels.test.json23
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesData.test.json92
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesList.test.json94
-rw-r--r--gui-clamp/ui-react/src/components/menu/MenuBar.test.js46
8 files changed, 415 insertions, 18 deletions
diff --git a/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js b/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js
index 0d20341..32ae209 100644
--- a/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js
+++ b/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights
- * reserved.
+ * Copyright (C) 2020 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.
diff --git a/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.test.js b/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.test.js
index 79267af..ef57998 100644
--- a/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.test.js
+++ b/gui-clamp/ui-react/src/components/dialogs/Loop/ModifyLoopModal.test.js
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights
- * reserved.
+ * Copyright (C) 2020 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.
@@ -28,15 +28,18 @@ import LoopService from '../../../api/LoopService';
import PolicyToscaService from '../../../api/PolicyToscaService';
describe('Verify ModifyLoopModal', () => {
+ const toscaPolicyModels = [{
+ "policyModelType": "test",
+ "policyAcronym": "test",
+ "version": "1.0.0",
+ "updatedBy": "",
+ "updatedDate": ""
+ }];
+ const selectedPolicyModels = [];
+
beforeEach(() => {
PolicyToscaService.getToscaPolicyModels = jest.fn().mockImplementation(() => {
- return Promise.resolve([{
- "policyModelType": "test",
- "policyAcronym": "test",
- "version": "1.0.0",
- "updatedBy": "",
- "updatedDate": ""
- }]);
+ return Promise.resolve(toscaPolicyModels);
});
PolicyToscaService.getToscaPolicyModelYaml = jest.fn().mockImplementation(() => {
return Promise.resolve("OK");
@@ -62,7 +65,6 @@ describe('Verify ModifyLoopModal', () => {
}
});
const historyMock = { push: jest.fn() };
- const flushPromises = () => new Promise(setImmediate);
it('Test handleClose', () => {
const handleClose = jest.spyOn(ModifyLoopModal.prototype, 'handleClose');
@@ -106,4 +108,14 @@ describe('Verify ModifyLoopModal', () => {
instance.handleYamlContent(event);
expect(component.state('content')).toEqual("testValue");
});
+
+ it('Test initializeToscaPolicyModelsInfo', () => {
+ const component = mount(<ModifyLoopModal loopCache={ loopCache }/>)
+ component.setState({
+ toscaPolicyModelsData: toscaPolicyModels,
+ selectedPolicyModelsData: selectedPolicyModels
+ });
+ expect(component.state('toscaPolicyModelsData')).toEqual(toscaPolicyModels);
+ expect(component.state('selectedPolicyModelsData')).toEqual(selectedPolicyModels);
+ });
});
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
index f571bc1..0aed5f4 100644
--- a/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* ONAP POLICY-CLAMP
* ================================================================================
- * Copyright (C) 2021 AT&T Intellectual Property. All rights
- * reserved.
+ * Copyright (C) 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.
@@ -44,11 +44,9 @@ import DehazeIcon from '@material-ui/icons/Dehaze';
import ArrowForwardIosIcon from '@material-ui/icons/ArrowForwardIos';
import AddIcon from '@material-ui/icons/Add';
import PublishIcon from '@material-ui/icons/Publish';
-import Switch from '@material-ui/core/Switch';
import MaterialTable from "material-table";
import PolicyService from '../../../api/PolicyService';
import PolicyToscaService from '../../../api/PolicyToscaService';
-import Select from '@material-ui/core/Select';
import Alert from 'react-bootstrap/Alert';
import Tabs from 'react-bootstrap/Tabs';
import Tab from 'react-bootstrap/Tab';
@@ -251,6 +249,7 @@ export default class ViewAllPolicies extends React.Component {
}
handleClose() {
+ console.log("handleClose called");
this.setState({ show: false });
this.props.history.push('/')
}
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js
new file mode 100644
index 0000000..d477c9a
--- /dev/null
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/ViewAllPolicies.test.js
@@ -0,0 +1,135 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+import {shallow} from "enzyme";
+import React from "react";
+import ViewAllPolicies from "./ViewAllPolicies";
+import fs from "fs";
+import PolicyToscaService from "../../../api/PolicyToscaService";
+import PolicyService from "../../../api/PolicyService";
+import CreateLoopModal from "../Loop/CreateLoopModal";
+
+describe('Verify ViewAllPolicies', () => {
+ let toscaPolicyModels = fs.readFileSync('src/components/dialogs/Policy/toscaData.test.json', {
+ encoding: 'utf8',
+ flag: 'r'
+ });
+ let toscaPoliciesList = fs.readFileSync('src/components/dialogs/Policy/toscaPoliciesList.test.json', {
+ encoding: 'utf8',
+ flag: 'r'
+ });
+
+ it('Test handleClose', () => {
+ const historyMock = {push: jest.fn()};
+ const handleClose = jest.spyOn(ViewAllPolicies.prototype, 'handleClose');
+ const component = shallow(<ViewAllPolicies history={historyMock}/>);
+
+ component.find('[variant="secondary"]').prop('onClick')();
+
+ expect(handleClose).toHaveBeenCalledTimes(1);
+ expect(component.state('show')).toEqual(false);
+ expect(historyMock.push.mock.calls[0]).toEqual(['/']);
+
+ handleClose.mockClear();
+ });
+
+ it('handleClose called when top-right button clicked', () => {
+ const historyMock = {push: jest.fn()};
+ const handleClose = jest.spyOn(ViewAllPolicies.prototype, 'handleClose');
+ const component = shallow(<ViewAllPolicies history={historyMock}/>);
+
+ component.find('[size="xl"]').get(0).props.onHide();
+
+ expect(handleClose).toHaveBeenCalledTimes(1);
+ expect(component.state('show')).toEqual(false);
+ expect(historyMock.push.mock.calls[0]).toEqual(['/']);
+
+ handleClose.mockClear();
+ });
+
+ it('Test getAllToscaModels', () => {
+ PolicyToscaService.getToscaPolicyModels = jest.fn().mockImplementation(() => {
+ return Promise.resolve(toscaPolicyModels);
+ });
+
+ const getAllToscaModels = jest.spyOn(ViewAllPolicies.prototype, 'getAllToscaModels');
+ shallow(<ViewAllPolicies/>);
+
+ expect(getAllToscaModels).toHaveBeenCalledTimes(1);
+ });
+
+ it('Test setToscaModelsListData', async () => {
+ PolicyToscaService.getToscaPolicyModel = jest.fn().mockImplementation(() => {
+ return Promise.resolve(toscaPolicyModels);
+ });
+
+ const component = shallow(<ViewAllPolicies/>);
+ component.setState({toscaModelsListData: toscaPolicyModels})
+ expect(component.state('toscaModelsListData')).toEqual(toscaPolicyModels);
+ });
+
+ it('Test getAllPolicies', () => {
+ PolicyService.getPoliciesList = jest.fn().mockImplementation(() => {
+ return Promise.resolve(toscaPoliciesList);
+ });
+
+ const getAllPolicies = jest.spyOn(ViewAllPolicies.prototype, 'getAllPolicies');
+ shallow(<ViewAllPolicies/>);
+
+ expect(getAllPolicies).toHaveBeenCalledTimes(1);
+ });
+
+ it('Test setPoliciesListData', async () => {
+ PolicyService.getPoliciesList = jest.fn().mockImplementation(() => {
+ return Promise.resolve(toscaPoliciesList);
+ });
+
+ const component = shallow(<ViewAllPolicies/>);
+ component.setState({policiesListData: toscaPoliciesList});
+ component.setState({policiesListDataFiltered: toscaPoliciesList});
+
+ expect(component.state('policiesListData')).toEqual(toscaPoliciesList);
+ expect(component.state('policiesListDataFiltered')).toEqual(toscaPoliciesList);
+ });
+
+ it('Test handleDeletePolicy event rowdata', async () => {
+ const rowData = {
+ type: 'onap.policies.monitoring.tcagen2',
+ type_version: '1.0.0',
+ name: 'MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0',
+ version: '1.0.0'
+ }
+
+ PolicyService.deletePolicy = await jest.fn().mockImplementation(() => {
+ return Promise.resolve({});
+ });
+
+ const event = { target: {value: 'event'}}
+ const component = shallow(<CreateLoopModal/>);
+
+ component.setState({showSuccessAlert: true});
+ component.setState({showMessage: 'Policy successfully Deleted'});
+
+ component.find('input').simulate('click', event, rowData);
+ component.update();
+
+ expect(component.state('showSuccessAlert')).toEqual(true);
+ expect(component.state('showMessage')).toEqual('Policy successfully Deleted');
+ });
+});
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/toscaModels.test.json b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaModels.test.json
new file mode 100644
index 0000000..aa757a8
--- /dev/null
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaModels.test.json
@@ -0,0 +1,23 @@
+[
+ {
+ "policyModelType": "onap.policies.controlloop.guard.common.Blacklist",
+ "version": "1.0.0",
+ "policyAcronym": "Blacklist",
+ "policyPdpGroup": {
+ "supportedPdpGroups": [
+ {
+ "controlloop": [
+ "xacml"
+ ]
+ }
+ ]
+ },
+ "createdDate": "2021-06-17T15:15:11.250177Z",
+ "updatedDate": "2021-06-17T15:15:11.450816Z",
+ "updatedBy": "Not found",
+ "createdBy": "Not found",
+ "tableData": {
+ "id": 0
+ }
+ }
+] \ No newline at end of file
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesData.test.json b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesData.test.json
new file mode 100644
index 0000000..9305243
--- /dev/null
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesData.test.json
@@ -0,0 +1,92 @@
+[
+ {
+ "type": "onap.policies.monitoring.tcagen2",
+ "type_version": "1.0.0",
+ "properties": {
+ "tca.policy": {
+ "domain": "measurementsForVfScaling",
+ "metricsPerEventName": [
+ {
+ "policyScope": "DCAE",
+ "thresholds": [
+ {
+ "version": "1.0.2",
+ "severity": "MAJOR",
+ "thresholdValue": 200,
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "LOOP_test",
+ "direction": "LESS_OR_EQUAL",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta"
+ }
+ ],
+ "eventName": "vLoadBalancer",
+ "policyVersion": "v0.0.1",
+ "controlLoopSchemaType": "VM",
+ "policyName": "DCAE.Config_tca-hi-lo"
+ }
+ ]
+ }
+ },
+ "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "policy-version": "1.0.0"
+ },
+ "pdpGroupInfo": [
+ {
+ "monitoring": {
+ "name": "monitoring",
+ "description": "This group should be used for managing all monitoring related policies and pdps",
+ "pdpGroupState": "ACTIVE",
+ "properties": {},
+ "pdpSubgroups": [
+ {
+ "pdpType": "xacml",
+ "supportedPolicyTypes": [
+ {
+ "name": "onap.policies.monitoring.*",
+ "version": "1.0.0"
+ },
+ {
+ "name": "onap.policies.Naming",
+ "version": "1.0.0"
+ }
+ ],
+ "policies": [
+ {
+ "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "version": "1.0.0"
+ }
+ ],
+ "currentInstanceCount": 0,
+ "desiredInstanceCount": 1,
+ "properties": {},
+ "pdpInstances": [
+ {
+ "instanceId": "monitoring-f8287777-5f3e-4f0f-b21b-d8829c93f57b",
+ "pdpState": "ACTIVE",
+ "healthy": "HEALTHY",
+ "message": "Pdp Heartbeat",
+ "lastUpdate": "2021-09-29T02:51:21Z"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ],
+ "supportedPdpGroups": [
+ {
+ "monitoring": [
+ "xacml"
+ ]
+ }
+ ],
+ "supportedPdpGroupsString": "monitoring/xacml\r\n",
+ "pdpGroupInfoString": "monitoring/xacml (ACTIVE)\r\n",
+ "tableData": {
+ "id": 0
+ }
+ }
+] \ No newline at end of file
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesList.test.json b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesList.test.json
new file mode 100644
index 0000000..0da8beb
--- /dev/null
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/toscaPoliciesList.test.json
@@ -0,0 +1,94 @@
+{
+ "policies": [
+ {
+ "type": "onap.policies.monitoring.tcagen2",
+ "type_version": "1.0.0",
+ "properties": {
+ "tca.policy": {
+ "domain": "measurementsForVfScaling",
+ "metricsPerEventName": [
+ {
+ "policyScope": "DCAE",
+ "thresholds": [
+ {
+ "version": "1.0.2",
+ "severity": "MAJOR",
+ "thresholdValue": 200,
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "LOOP_test",
+ "direction": "LESS_OR_EQUAL",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta"
+ }
+ ],
+ "eventName": "vLoadBalancer",
+ "policyVersion": "v0.0.1",
+ "controlLoopSchemaType": "VM",
+ "policyName": "DCAE.Config_tca-hi-lo"
+ }
+ ]
+ }
+ },
+ "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "policy-version": "1.0.0"
+ },
+ "pdpGroupInfo": [
+ {
+ "monitoring": {
+ "name": "monitoring",
+ "description": "This group should be used for managing all monitoring related policies and pdps",
+ "pdpGroupState": "ACTIVE",
+ "properties": {},
+ "pdpSubgroups": [
+ {
+ "pdpType": "xacml",
+ "supportedPolicyTypes": [
+ {
+ "name": "onap.policies.monitoring.*",
+ "version": "1.0.0"
+ },
+ {
+ "name": "onap.policies.Naming",
+ "version": "1.0.0"
+ }
+ ],
+ "policies": [
+ {
+ "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "version": "1.0.0"
+ }
+ ],
+ "currentInstanceCount": 0,
+ "desiredInstanceCount": 1,
+ "properties": {},
+ "pdpInstances": [
+ {
+ "instanceId": "monitoring-f8287777-5f3e-4f0f-b21b-d8829c93f57b",
+ "pdpState": "ACTIVE",
+ "healthy": "HEALTHY",
+ "message": "Pdp Heartbeat",
+ "lastUpdate": "2021-09-29T02:51:21Z"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ],
+ "supportedPdpGroups": [
+ {
+ "monitoring": [
+ "xacml"
+ ]
+ }
+ ],
+ "supportedPdpGroupsString": "monitoring/xacml\r\n",
+ "pdpGroupInfoString": "monitoring/xacml (ACTIVE)\r\n",
+ "tableData": {
+ "id": 0
+ }
+ }
+ ]
+} \ No newline at end of file
diff --git a/gui-clamp/ui-react/src/components/menu/MenuBar.test.js b/gui-clamp/ui-react/src/components/menu/MenuBar.test.js
index 81117bb..1e6dd1c 100644
--- a/gui-clamp/ui-react/src/components/menu/MenuBar.test.js
+++ b/gui-clamp/ui-react/src/components/menu/MenuBar.test.js
@@ -2,8 +2,8 @@
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights
- * reserved.
+ * 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.
@@ -23,6 +23,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import MenuBar from './MenuBar';
+import DropdownItem from "react-bootstrap/DropdownItem";
describe('Verify MenuBar', () => {
@@ -43,4 +44,45 @@ describe('Verify MenuBar', () => {
component.setProps({ loopName: "Empty (NO loop loaded yet)" });
expect(component.state('disabled')).toBe(true);
});
+
+ it('Find 20 DropdownItem', () => {
+ const component = shallow(<MenuBar />)
+ expect(component.find('DropdownItem').length).toEqual(20);
+ });
+
+ it('Finds POLICY Framework Menu', () => {
+ const component = shallow(<MenuBar />).childAt(0).dive();
+ expect(component.find({ tile: 'POLICY Framework' }));
+ });
+
+ it('Finds POLICY Framework Menu', () => {
+ const component = shallow(<MenuBar />).childAt(1).dive();
+ expect(component.find({ tile: 'CLAMP Options' }));
+ });
+
+ it('Finds POLICY Framework Menu', () => {
+ const component = shallow(<MenuBar />).childAt(2).dive();
+ expect(component.find({ tile: 'LOOP Instance' }));
+ });
+
+ it('Finds POLICY Framework Menu', () => {
+ const component = shallow(<MenuBar />).childAt(3).dive();
+ expect(component.find({ tile: 'LOOP Operations' }));
+ });
+
+ it('Finds POLICY Framework Menu', () => {
+ const component = shallow(<MenuBar />).childAt(4).dive();
+ expect(component.find({ tile: 'TOSCA Control Loop' }));
+ });
+
+ it('Finds POLICY Framework Menu', () => {
+ const component = shallow(<MenuBar />).childAt(5).dive();
+ expect(component.find({ tile: 'Help' }));
+ });
+
+ it('Finds StyledNavLink', () => {
+ const component = shallow(<MenuBar />);
+ console.log(component.debug());
+ expect(component.find('Styled(NavLink)').length).toEqual(2);
+ });
});