From 2022e5ce5a03788a6edc5761c495cfadc5ded485 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 9 Nov 2021 15:22:22 +0000 Subject: Align ui-react file in policy-clamp and policy-gui When the ui-react code was transferred to policy-gui, the white space was cleaned up and reformatted. This makes it difficult to track the real functional changes if any between ui-react in policy-clamp and policy-gui. This review brings the white space changes into ui-react in policy-clamp to make file comparisons easier. Issue-ID: POLICY-3358 Change-Id: Ic303e71b341e5c0f7ca0de0ed4c4962ebf2f988a Signed-off-by: liamfallon --- .../dialogs/Loop/CreateLoopModal.test.js | 72 ++++++++++++---------- 1 file changed, 40 insertions(+), 32 deletions(-) (limited to 'runtime/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js') diff --git a/runtime/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js b/runtime/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js index 8ef53b412..3d9483334 100644 --- a/runtime/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js +++ b/runtime/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js @@ -27,7 +27,10 @@ import LoopService from '../../../api/LoopService'; import TemplateService from '../../../api/TemplateService'; let errorMessage = ''; -window.alert = jest.fn().mockImplementation((mesg) => { errorMessage = mesg ; return }); +window.alert = jest.fn().mockImplementation((mesg) => { + errorMessage = mesg; + return +}); describe('Verify CreateLoopModal', () => { @@ -35,7 +38,7 @@ describe('Verify CreateLoopModal', () => { it('Test the render method', async () => { const flushPromises = () => new Promise(setImmediate); TemplateService.getAllLoopTemplates = jest.fn().mockImplementation(() => { - return Promise.resolve([{"name":"template1"},{"name":"template2"}]); + return Promise.resolve([{ "name": "template1" }, { "name": "template2" }]); }); TemplateService.getLoopNames = jest.fn().mockImplementation(() => { return Promise.resolve([]); @@ -45,21 +48,25 @@ describe('Verify CreateLoopModal', () => { expect(component).toMatchSnapshot(); await flushPromises(); component.update(); - expect(component.state('templateNames')).toStrictEqual([{"label": "template1", "value": "template1", "templateObject": {"name": "template1"}}, {"label": "template2", "value": "template2","templateObject": {"name": "template2"}}]); + expect(component.state('templateNames')).toStrictEqual([{ "label": "template1", "value": "template1", "templateObject": { "name": "template1" } }, { + "label": "template2", + "value": "template2", + "templateObject": { "name": "template2" } + }]); }); it('handleDropdownListChange event', async () => { - const flushPromises = () => new Promise(setImmediate); + const flushPromises = () => new Promise(setImmediate); const component = shallow(); - component.find('StateManager').simulate('change', {value: 'template1', templateObject: {"name":"template1"} }); + component.find('StateManager').simulate('change', { value: 'template1', templateObject: { "name": "template1" } }); await flushPromises(); component.update(); expect(component.state('chosenTemplateName')).toEqual("template1"); expect(component.state('fakeLoopCacheWithTemplate').getLoopTemplate()['name']).toEqual("template1"); expect(component.state('fakeLoopCacheWithTemplate').getLoopName()).toEqual("fakeLoop"); - component.find('StateManager').simulate('change',{value: 'template2', templateObject: {"name":"template2"} }); + component.find('StateManager').simulate('change', { value: 'template2', templateObject: { "name": "template2" } }); await flushPromises(); component.update(); expect(component.state('chosenTemplateName')).toEqual("template2"); @@ -70,12 +77,12 @@ describe('Verify CreateLoopModal', () => { it('handleModelName event', async () => { const flushPromises = () => new Promise(setImmediate); TemplateService.getAllLoopTemplates = jest.fn().mockImplementation(() => { - return Promise.resolve([{"name":"template1"},{"name":"template2"}]); + return Promise.resolve([{ "name": "template1" }, { "name": "template2" }]); }); TemplateService.getLoopNames = jest.fn().mockImplementation(() => { return Promise.resolve([]); }); - const event = {target: {value : "model1"} }; + const event = { target: { value: "model1" } }; const component = shallow(); await flushPromises(); component.find('input').simulate('change', event); @@ -84,21 +91,21 @@ describe('Verify CreateLoopModal', () => { }); it('Test handleClose', () => { - const historyMock = { push: jest.fn() }; - const handleClose = jest.spyOn(CreateLoopModal.prototype,'handleClose'); - const component = shallow() + const historyMock = { push: jest.fn() }; + const handleClose = jest.spyOn(CreateLoopModal.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([ '/']); - + expect(historyMock.push.mock.calls[0]).toEqual(['/']); + handleClose.mockClear(); }); it('Test handleCreate Fail', () => { - const handleCreate = jest.spyOn(CreateLoopModal.prototype,'handleCreate'); + const handleCreate = jest.spyOn(CreateLoopModal.prototype, 'handleCreate'); const component = shallow() component.find('[variant="primary"]').prop('onClick')(); @@ -110,32 +117,33 @@ describe('Verify CreateLoopModal', () => { }); it('Test handleCreate Suc', async () => { - const flushPromises = () => new Promise(setImmediate); + const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; - const loadLoopFunction = jest.fn(); - + const loadLoopFunction = jest.fn(); + LoopService.createLoop = jest.fn().mockImplementation(() => { - return Promise.resolve({ - ok: true, - status: 200, - json: () => {} - }); - }); - - const handleCreate = jest.spyOn(CreateLoopModal.prototype,'handleCreate'); - const component = shallow() + return Promise.resolve({ + ok: true, + status: 200, + json: () => { + } + }); + }); + + const handleCreate = jest.spyOn(CreateLoopModal.prototype, 'handleCreate'); + const component = shallow() component.setState({ - modelName: "modelNameTest", - chosenTemplateName: "template1" - }); + modelName: "modelNameTest", + chosenTemplateName: "template1" + }); component.find('[variant="primary"]').prop('onClick')(); - await flushPromises(); - component.update(); + await flushPromises(); + component.update(); expect(handleCreate).toHaveBeenCalledTimes(1); expect(component.state('show')).toEqual(false); - expect(historyMock.push.mock.calls[0]).toEqual([ '/']); + expect(historyMock.push.mock.calls[0]).toEqual(['/']); handleCreate.mockClear(); }); -- cgit 1.2.3-korg