aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2022-03-10 15:44:31 +0000
committerGerrit Code Review <gerrit@onap.org>2022-03-10 15:44:31 +0000
commit1e95c73cef25b524bc1f5791d4578332670202f7 (patch)
tree6e6e1e84dd8443545a47e04afed714d047d547f6
parent208b24fb8df657fd194f36045e07ffad47f5a4d9 (diff)
parent5d87357d69ec81962fd6128a8aa12086b97f199f (diff)
Merge "Added Jest Tests for Overall Coverage"
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.js8
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.test.js63
2 files changed, 59 insertions, 12 deletions
diff --git a/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.js b/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.js
index 2dc2cb3..5181b64 100644
--- a/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.js
+++ b/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.js
@@ -65,11 +65,9 @@ const InstancePropertiesModal = (props) => {
const [instancePropertiesGlobal, setInstancePropertiesGlobal] = useState({});
const [serviceTemplateResponseOk, setServiceTemplateResponseOk] = useState(true);
const [instancePropertiesResponseOk, setInstancePropertiesResponseOk] = useState(true);
- const [instanceName, setInstanceName] = useState('')
+ const [instanceName, setInstanceName] = useState('');
useEffect(async () => {
- setJsonEditor(null);
-
const toscaTemplateResponse = await ACMService.getToscaTemplate(templateName, templateVersion)
.catch(error => error.message);
@@ -111,8 +109,8 @@ const InstancePropertiesModal = (props) => {
}
const handleSave = async () => {
- console.log("handleSave called");
- if (instanceName !== '' || instanceName.length > 0) {
+ if (instanceName !== '' || instanceName !== undefined || instanceName.length > 0) {
+ console.log("handleSave called");
console.log("instanceName to be saved is: " + instanceName);
diff --git a/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.test.js b/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.test.js
index 5c617bf..5b60bce 100644
--- a/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.test.js
+++ b/gui-clamp/ui-react/src/components/dialogs/ACM/InstancePropertiesModal.test.js
@@ -17,14 +17,19 @@
* ============LICENSE_END=========================================================
*/
-import { mount, shallow } from "enzyme";
+import {shallow} from "enzyme";
import React from "react";
import InstancePropertiesModal from "./InstancePropertiesModal";
import toJson from "enzyme-to-json";
import { createMemoryHistory } from "history";
import { act } from "react-dom/test-utils";
+import ACMService from "../../../api/ACMService";
+import fullTemp from "./testFiles/fullTemplate.json";
+import instanceProps from "./testFiles/instanceProps.json";
-let logSpy = jest.spyOn(console, 'log')
+const instanceProperties = JSON.parse(JSON.stringify(instanceProps))
+const fullTemplate = JSON.parse(JSON.stringify(fullTemp))
+let logSpy = jest.spyOn(console, 'log');
describe('Verify InstancePropertiesModal', () => {
@@ -66,7 +71,10 @@ describe('Verify InstancePropertiesModal', () => {
});
it('handleCreateUpdateToscaInstanceProperties called when save button clicked', () => {
- const component = mount(<InstancePropertiesModal />)
+ const component = shallow(<InstancePropertiesModal />);
+
+ const instanceNameState = jest.spyOn(React, "useState");
+ instanceNameState.mockImplementation(instanceName => [instanceName, 'Test']);
act(() => {
component.find('[variant="primary"]').simulate('click');
@@ -76,7 +84,7 @@ describe('Verify InstancePropertiesModal', () => {
it('handleClose called when close button clicked', () => {
const history = createMemoryHistory();
- const component = mount(<InstancePropertiesModal history={ history }/>)
+ const component = shallow(<InstancePropertiesModal history={ history }/>)
act(() => {
component.find('[variant="secondary"]').simulate('click');
@@ -85,7 +93,7 @@ describe('Verify InstancePropertiesModal', () => {
});
it('handleSave called when save button clicked', () => {
- const component = mount(<InstancePropertiesModal />)
+ const component = shallow(<InstancePropertiesModal />)
act(() => {
component.find('[variant="primary"]').simulate('click');
@@ -95,9 +103,50 @@ describe('Verify InstancePropertiesModal', () => {
it('Check useEffect is being called', async () => {
const useEffect = jest.spyOn(React, "useEffect");
- mount(<InstancePropertiesModal />)
- await act(async () => {
+ const component = shallow(<InstancePropertiesModal />)
+ act(async () => {
+ expect(useEffect).toHaveBeenCalled();
+ component.update()
+ });
+ });
+
+ it('Check useEffect is being called', async () => {
+ const useEffect = jest.spyOn(React, "useEffect");
+ const component = shallow(<InstancePropertiesModal />)
+ act(async () => {
expect(useEffect).toHaveBeenCalled();
+ component.update();
});
});
+
+ it('getToscaTemplate gets called in useEffect with error', async() => {
+ const fetchMock = jest.spyOn(ACMService, 'getToscaTemplate').mockImplementation(() => Promise.resolve({
+ ok: false,
+ status: 200,
+ text: () => "OK",
+ json: () => fullTemplate
+ }))
+
+ const component = shallow(<InstancePropertiesModal/>)
+ act(async () => {
+ expect(fetchMock).toHaveBeenCalled();
+ component.update();
+ });
+ });
+
+ it('getCommonOrInstanceProperties gets called in useEffect with error', async() => {
+ const fetchMock = jest.spyOn(ACMService, 'getCommonOrInstanceProperties').mockImplementation(() => Promise.resolve({
+ ok: false,
+ status: 200,
+ text: () => "OK",
+ json: () => instanceProperties
+ }))
+
+ const component = shallow(<InstancePropertiesModal/>)
+ act(async () => {
+ expect(fetchMock).toHaveBeenCalled();
+ component.update();
+ });
+ });
+
});