Fix crash at SDC deploy
[clamp.git] / ui-react / src / components / dialogs / OperationalPolicy / OperationalPolicyModal.test.js
index da60b67..4c11ce5 100644 (file)
@@ -28,46 +28,46 @@ import LoopCache from '../../../api/LoopCache';
 describe('Verify OperationalPolicyModal', () => {
     beforeEach(() => {
         fetch.resetMocks();
-               fetch.mockImplementation(() => {
-                       return Promise.resolve({
-                               ok: true,
-                               status: 200,
-                               text: () => "OK"
-                       });
-               });
+        fetch.mockImplementation(() => {
+            return Promise.resolve({
+                ok: true,
+                status: 200,
+                text: () => "OK"
+            });
+        });
     })
     const loopCache = new LoopCache({
             "name": "LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca",
             "operationalPolicies": [{
                 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
                 "configurationsJson": {
-                    "guard_policies": {},
                     "operational_policy": {
                         "controlLoop": {},
                         "policies": []
                     }
-                }
-             }],
-            "operationalPolicySchema": {"schema": {}}
+                },
+                "jsonRepresentation" : {"schema": {}}
+             }]
     });
     const historyMock = { push: jest.fn() };
     const flushPromises = () => new Promise(setImmediate);
-       
+
     it('Test handleClose', () => {
       const handleClose = jest.spyOn(OperationalPolicyModal.prototype,'handleClose');
       const component = mount(<OperationalPolicyModal history={historyMock} loopCache={loopCache}/>)
 
-      component.find('[variant="secondary"]').prop('onClick')();
+      component.find('[variant="secondary"]').get(0).props.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([ '/']);
     });
 
     it('Test handleSave', async () => {
         const loadLoopFunction = jest.fn();
         const handleSave = jest.spyOn(OperationalPolicyModal.prototype,'handleSave');
-        const component = mount(<OperationalPolicyModal history={historyMock} loopCache={loopCache} loadLoopFunction={loadLoopFunction} />)
+        const component = mount(<OperationalPolicyModal history={historyMock} 
+                          loopCache={loopCache} loadLoopFunction={loadLoopFunction} />)
 
         component.find('[variant="primary"]').prop('onClick')();
         await flushPromises();
@@ -75,6 +75,19 @@ describe('Verify OperationalPolicyModal', () => {
 
         expect(handleSave).toHaveBeenCalledTimes(1);
         expect(component.state('show')).toEqual(false);
-        expect(historyMock.push.mock.calls[0]).toEqual([ '/', ]);
+        expect(historyMock.push.mock.calls[0]).toEqual([ '/']);
+    });
+
+    it('Test handleRefresh', async () => {
+        const updateLoopFunction = jest.fn();
+        const handleRefresh = jest.spyOn(OperationalPolicyModal.prototype,'handleRefresh');
+        const component = mount(<OperationalPolicyModal loopCache={loopCache} updateLoopFunction={updateLoopFunction} />)
+
+        component.find('[variant="secondary"]').get(1).props.onClick();
+        await flushPromises();
+        component.update();
+
+        expect(handleRefresh).toHaveBeenCalledTimes(1);
+        expect(component.state('show')).toEqual(true);
     });
 });
\ No newline at end of file