X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ui-react%2Fsrc%2Fcomponents%2Fdialogs%2FOpenLoop%2FOpenLoopModal.test.js;h=5153de9567b7a715f02ffaa64f9fdc35d80150c6;hb=233e3cdba0aec0f0c21cc5986654feb33cb7eb3d;hp=6ba8f40a5a67abfba926bcc051c6de5ce8e3a5b7;hpb=58c7c977bed829fe010849cdf1b3f654c3c8cc02;p=clamp.git diff --git a/ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js b/ui-react/src/components/dialogs/OpenLoop/OpenLoopModal.test.js index 6ba8f40a..5153de95 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(); expect(component).toMatchSnapshot(); }); + it('Onchange event', () => { + const event = {value: 'LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3'}; + const component = shallow(); + 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() + + 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() + + 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(); + }); });