From 2f5b2cdb2a7650d6bd41d1b20ec0813cad7989ed Mon Sep 17 00:00:00 2001 From: xuegao Date: Mon, 6 Jan 2020 16:13:46 +0100 Subject: Add button to refresh op policy UI Add the button on Operational Policy UI to refresh the json representation. Issue-ID: CLAMP-584 Change-Id: I3ae6ca0207bf9ca84f1e1dc6b3aed42b90298d8e Signed-off-by: xuegao --- .../OperationalPolicy/OperationalPolicyModal.js | 28 ++++++++++++++++++++-- .../OperationalPolicyModal.test.js | 15 +++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) (limited to 'ui-react/src/components/dialogs') diff --git a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js index c7363f6e5..dc7c0a489 100644 --- a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js +++ b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js @@ -25,6 +25,7 @@ import React from 'react' import Button from 'react-bootstrap/Button'; import Modal from 'react-bootstrap/Modal'; import styled from 'styled-components'; +import LoopCache from '../../../api/LoopCache'; import LoopService from '../../../api/LoopService'; import JSONEditor from '@json-editor/json-editor'; @@ -45,6 +46,7 @@ export default class OperationalPolicyModal extends React.Component { this.handleClose = this.handleClose.bind(this); this.handleSave = this.handleSave.bind(this); this.renderJsonEditor = this.renderJsonEditor.bind(this); + this.handleRefresh = this.handleRefresh.bind(this); this.setDefaultJsonEditorOptions(); } @@ -122,6 +124,25 @@ export default class OperationalPolicyModal extends React.Component { }) } + handleRefresh() { + LoopService.refreshOpPolicyJson(this.state.loopCache.getLoopName()).then(data => { + var newLoopCache = new LoopCache(data); + var schema_json = newLoopCache.getOperationalPolicyJsonSchema(); + var operationalPoliciesData = newLoopCache.getOperationalPoliciesNoJsonSchema(); + document.getElementById("editor").innerHTML = ""; + this.setState({ + loopCache: newLoopCache, + jsonEditor: new JSONEditor(document.getElementById("editor"), + { schema: schema_json.schema, startval: operationalPoliciesData }) + }) + this.props.updateLoopFunction(data); + + }) + .catch(error => { + console.error("Error while refreshing the Operational Policy Json Representation"); + }); + } + render() { return ( @@ -135,10 +156,13 @@ export default class OperationalPolicyModal extends React.Component { + + + diff --git a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js index 522a3f681..c10c6ff0a 100644 --- a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js +++ b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js @@ -57,7 +57,7 @@ describe('Verify OperationalPolicyModal', () => { const handleClose = jest.spyOn(OperationalPolicyModal.prototype,'handleClose'); const component = mount() - component.find('[variant="secondary"]').prop('onClick')(); + component.find('[variant="secondary"]').get(0).props.onClick(); expect(handleClose).toHaveBeenCalledTimes(1); expect(component.state('show')).toEqual(false); @@ -78,4 +78,17 @@ describe('Verify OperationalPolicyModal', () => { expect(component.state('show')).toEqual(false); 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() + + 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 -- cgit 1.2.3-korg