summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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();
+ });
+ });
+
});