summaryrefslogtreecommitdiffstats
path: root/ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2019-10-01 15:34:53 +0200
committerxuegao <xg353y@intl.att.com>2019-10-01 15:34:53 +0200
commit233e3cdba0aec0f0c21cc5986654feb33cb7eb3d (patch)
tree686fa173440210eb34555f458d37c3518a7c4125 /ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js
parent58c7c977bed829fe010849cdf1b3f654c3c8cc02 (diff)
Add react ui tests
Add more tests for react UI. Issue-ID: CLAMP-509 Change-Id: I58f6408bcd8667fa8b16b0b2f31f8287bdfac8c9 Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js')
-rw-r--r--ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js50
1 files changed, 44 insertions, 6 deletions
diff --git a/ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js b/ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js
index 6ba8f40a5..5153de956 100644
--- a/ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js
+++ b/ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js
@@ -27,19 +27,57 @@ import OpenLoopModal from './OpenLoopModal';
describe('Verify OpenLoopModal', () => {
beforeEach(() => {
- fetch.resetMocks()
- })
-
- it('Test the render method', () => {
- fetch.mockResponseOnce(JSON.stringify([
+ fetch.resetMocks();
+ fetch.mockResponseOnce(JSON.stringify([
"LOOP_gmtAS_v1_0_ResourceInstanceName1_tca",
"LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3",
"LOOP_gmtAS_v1_0_ResourceInstanceName2_tca_2"
- ]))
+ ]));
+ })
+
+ it('Test the render method', () => {
const component = shallow(<OpenLoopModal/>);
expect(component).toMatchSnapshot();
});
+ it('Onchange event', () => {
+ const event = {value: 'LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3'};
+ const component = shallow(<OpenLoopModal/>);
+ const forms = component.find('StateManager');
+
+ component.find('StateManager').simulate('change', event);
+ component.update();
+ expect(component.state('chosenLoopName')).toEqual("LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3");
+ });
+
+ it('Test handleClose', () => {
+ const historyMock = { push: jest.fn() };
+ const handleClose = jest.spyOn(OpenLoopModal.prototype,'handleClose');
+ const component = shallow(<OpenLoopModal 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('Test handleSubmit', () => {
+ const historyMock = { push: jest.fn() };
+ const loadLoopFunction = jest.fn();
+ const handleOpen = jest.spyOn(OpenLoopModal.prototype,'handleOpen');
+ const component = shallow(<OpenLoopModal history={historyMock} loadLoopFunction={loadLoopFunction}/>)
+
+ component.find('[variant="primary"]').prop('onClick')();
+
+ expect(handleOpen).toHaveBeenCalledTimes(1);
+ expect(component.state('show')).toEqual(false);
+ expect(historyMock.push.mock.calls[0]).toEqual([ '/', ]);
+
+ handleOpen.mockClear();
+ });
});