aboutsummaryrefslogtreecommitdiffstats
path: root/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js
diff options
context:
space:
mode:
authorbrunomilitzer <bruno.militzer@est.tech>2021-11-03 11:30:46 +0000
committerbrunomilitzer <bruno.militzer@est.tech>2021-11-03 11:36:04 +0000
commit33391192adecdf86da3547f024ff82fb0cf85535 (patch)
treec44374098647759480821c74122faa8267b8b24f /gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js
parent28d5047cecd111e380fe78d2d1d7e4756b78ed12 (diff)
UPDATED Jest Unit Tests for Monitoring Functionality
Updated Unit Tests to cover monitoring functionality Issue-ID: POLICY-3561 Change-Id: I8434cf5d60463d60175ef6e48f0e75e8c4f656da Signed-off-by: brunomilitzer <bruno.militzer@est.tech>
Diffstat (limited to 'gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js')
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js53
1 files changed, 45 insertions, 8 deletions
diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js
index cce6225..ea98073 100644
--- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js
+++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/MonitorInstantiation.test.js
@@ -17,40 +17,77 @@
* ============LICENSE_END=========================================================
*/
-import { shallow } from "enzyme";
+import React from "react";
+import { mount, shallow } from "enzyme";
import toJson from "enzyme-to-json";
+import { act } from "react-dom/test-utils";
import { createMemoryHistory } from "history";
-import React from "react";
import MonitorInstantiation from "./MonitorInstantiation";
-import { act } from "react-dom/test-utils";
+import ControlLoopService from "../../../api/ControlLoopService";
+import clLoopList from "./testFiles/monitoringControlLoopList.json";
+
+const logSpy = jest.spyOn(console, 'error')
+const history = createMemoryHistory();
+
+describe('Verify MonitorInstantiation', () => {
+ const flushPromises = () => new Promise(setImmediate);
-describe('Verify MonitoringInstantiation', () => {
- const container = shallow(<MonitorInstantiation />);
- const containerWithHistory = shallow(<MonitorInstantiation history={ createMemoryHistory() }/>);
+ beforeEach(() => {
+ logSpy.mockClear();
+ });
it("renders correctly", () => {
+ const container = shallow(<MonitorInstantiation />);
expect(toJson(container)).toMatchSnapshot();
});
it('should have a Button element', () => {
+ const container = shallow(<MonitorInstantiation />);
expect(container.find('Button').length).toEqual(1);
});
it('handleClose called when bottom button clicked', () => {
+ const container = shallow(<MonitorInstantiation history={ history } />);
const logSpy = jest.spyOn(console, 'log');
act(() => {
- containerWithHistory.find('[variant="secondary"]').simulate('click');
+ container.find('[variant="secondary"]').simulate('click');
expect(logSpy).toHaveBeenCalledWith('handleClose called');
});
});
it('handleClose called when top-right button clicked', () => {
+ const container = shallow(<MonitorInstantiation history={ history } />);
const logSpy = jest.spyOn(console, 'log');
act(() => {
- containerWithHistory.find('[size="xl"]').get(0).props.onHide();
+ container.find('[size="xl"]').get(0).props.onHide();
expect(logSpy).toHaveBeenCalledWith('handleClose called');
});
});
+
+ it('Check useEffect is being called', async () => {
+ jest.resetAllMocks();
+ jest.spyOn(ControlLoopService, 'getControlLoopInstantiation')
+ .mockImplementationOnce(async () => {
+ return Promise.resolve({
+ ok: true,
+ status: 200,
+ text: () => "OK",
+ json: () => {
+ return Promise.resolve(clLoopList);
+ }
+ });
+ });
+
+ const component = mount(<MonitorInstantiation />);
+ const useEffect = jest.spyOn(React, "useEffect");
+
+ await act(async () => {
+ await flushPromises()
+ component.update();
+ await expect(useEffect).toHaveBeenCalled();
+ });
+ component.unmount();
+ });
});