Create SVG in UI
[clamp.git] / ui-react / src / components / dialogs / Loop / OpenLoopModal.test.js
index 208c947..1865869 100644 (file)
 import React from 'react';
 import { shallow } from 'enzyme';
 import OpenLoopModal from './OpenLoopModal';
+import LoopService from '../../../api/LoopService';
 
 describe('Verify OpenLoopModal', () => {
 
   beforeEach(() => {
       fetch.resetMocks();
-          fetch.mockResponseOnce(JSON.stringify([
+      fetch.mockResponse(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', () => {
 
@@ -41,15 +42,24 @@ describe('Verify OpenLoopModal', () => {
     expect(component).toMatchSnapshot();
   });
 
-  it('Onchange event', () => {
+  it('Onchange event', async () => {
+    const flushPromises = () => new Promise(setImmediate);
+    LoopService.getLoop = jest.fn().mockImplementation(() => {
+               return Promise.resolve({
+                       ok: true,
+                       status: 200,
+                       json: () => {}
+               });
+       });
     const event = {value: 'LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3'};
     const component = shallow(<OpenLoopModal/>);
-
     component.find('StateManager').simulate('change', event);
+    await flushPromises();
     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');