From cc5fe51690dc1f780c6b7cd1168e59dedc3b245f Mon Sep 17 00:00:00 2001 From: xuegao Date: Mon, 6 Apr 2020 13:13:52 +0200 Subject: Update suc alert color Update the back groud color for succesful alert messages. Issue-ID: CLAMP-815 Change-Id: I97a621e31f2eb850eae30da3754afd3cd4ddb34a Signed-off-by: xuegao --- ui-react/src/LoopUI.js | 39 +++++++++----- ui-react/src/LoopUI.test.js | 18 +++++-- ui-react/src/__snapshots__/LoopUI.test.js.snap | 63 +++++++++++++++------- ui-react/src/__snapshots__/OnapClamp.test.js.snap | 63 +++++++++++++++------- .../src/components/dialogs/Loop/DeployLoopModal.js | 6 +-- .../dialogs/Loop/DeployLoopModal.test.js | 5 +- .../OperationalPolicy/OperationalPolicyModal.js | 2 +- ui-react/src/components/dialogs/PerformActions.js | 4 +- .../src/components/dialogs/PerformActions.test.js | 10 ++-- ui-react/src/components/dialogs/RefreshStatus.js | 4 +- .../src/components/dialogs/RefreshStatus.test.js | 10 ++-- 11 files changed, 147 insertions(+), 77 deletions(-) (limited to 'ui-react') diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js index bc3f2355e..5e2da79c6 100644 --- a/ui-react/src/LoopUI.js +++ b/ui-react/src/LoopUI.js @@ -109,7 +109,8 @@ export default class LoopUI extends React.Component { userName: null, loopName: OnapConstants.defaultLoopName, loopCache: new LoopCache({}), - showAlert: false + showSucAlert: false, + showFailAlert: false }; constructor() { @@ -119,7 +120,8 @@ export default class LoopUI extends React.Component { this.updateLoopCache = this.updateLoopCache.bind(this); this.loadLoop = this.loadLoop.bind(this); this.closeLoop = this.closeLoop.bind(this); - this.showAlert = this.showAlert.bind(this); + this.showSucAlert = this.showSucAlert.bind(this); + this.showFailAlert = this.showFailAlert.bind(this); this.disableAlert = this.disableAlert.bind(this); } @@ -168,9 +170,14 @@ export default class LoopUI extends React.Component { renderAlertBar() { return ( - +
+ {this.state.showMessage} + + {this.state.showMessage} + +
); } @@ -223,12 +230,16 @@ export default class LoopUI extends React.Component { console.info(this.state.loopName+" loop loaded successfully"); } - showAlert(message) { - this.setState ({ showAlert: true, showMessage:message }); + showSucAlert(message) { + this.setState ({ showSucAlert: true, showMessage:message }); } + showFailAlert(message) { + this.setState ({ showFailAlert: true, showMessage:message }); + } + disableAlert() { - this.setState ({ showAlert: false }); + this.setState ({ showSucAlert: false, showFailAlert: false }); } loadLoop(loopName) { @@ -258,7 +269,7 @@ export default class LoopUI extends React.Component { ()} /> ()} /> ()} /> + render={(routeProps) => ()} /> ()} /> ()} /> ()} /> @@ -268,13 +279,13 @@ export default class LoopUI extends React.Component { ()} /> - ()} /> - ()} /> - ()} /> - ()} /> - ()} /> - ()} /> - ()} /> + ()} /> + ()} /> + ()} /> + ()} /> + ()} /> + ()} /> + ()} /> {this.renderAlertBar()} diff --git a/ui-react/src/LoopUI.test.js b/ui-react/src/LoopUI.test.js index d1b76aa9a..6885e7932 100644 --- a/ui-react/src/LoopUI.test.js +++ b/ui-react/src/LoopUI.test.js @@ -66,7 +66,8 @@ describe('Verify LoopUI', () => { const component = shallow() component.setState({ loopName: "testLoopName", - showAlert: false + showSucAlert: false, + showFailAlert: false }); await flushPromises(); expect(component).toMatchSnapshot(); @@ -158,15 +159,22 @@ describe('Verify LoopUI', () => { test('Test alert methods', () => { const component = shallow() - expect(component.state('showAlert')).toEqual(false); + expect(component.state('showSucAlert')).toEqual(false); const instance = component.instance(); - instance.showAlert("testAlert"); - expect(component.state('showAlert')).toEqual(true); + instance.showSucAlert("testAlert"); + expect(component.state('showSucAlert')).toEqual(true); + expect(component.state('showFailAlert')).toEqual(false); expect(component.state('showMessage')).toEqual("testAlert"); instance.disableAlert(); - expect(component.state('showAlert')).toEqual(false); + expect(component.state('showSucAlert')).toEqual(false); + expect(component.state('showFailAlert')).toEqual(false); + + instance.showFailAlert("testAlert2"); + expect(component.state('showSucAlert')).toEqual(false); + expect(component.state('showFailAlert')).toEqual(true); + expect(component.state('showMessage')).toEqual("testAlert2"); }) }); diff --git a/ui-react/src/__snapshots__/LoopUI.test.js.snap b/ui-react/src/__snapshots__/LoopUI.test.js.snap index 9de232dd6..e523de948 100644 --- a/ui-react/src/__snapshots__/LoopUI.test.js.snap +++ b/ui-react/src/__snapshots__/LoopUI.test.js.snap @@ -89,27 +89,50 @@ exports[`Verify LoopUI Test the render method 1`] = ` render={[Function]} /> - + + variant="success" + /> + + - + + variant="success" + /> + + { LoopActionService.performAction(loopName, "deploy").then(pars => { - this.props.showAlert("Action deploy successfully performed"); + this.props.showSucAlert("Action deploy successfully performed"); // refresh status and update loop logs this.refreshStatus(loopName); }) .catch(error => { - this.props.showAlert("Action deploy failed"); + this.props.showFailAlert("Action deploy failed"); // refresh status and update loop logs this.refreshStatus(loopName); }); @@ -103,7 +103,7 @@ export default class DeployLoopModal extends React.Component { this.props.updateLoopFunction(data); }) .catch(error => { - this.props.showAlert("Refresh status failed"); + this.props.showFailAlert("Refresh status failed"); }); } handleChange(event) { diff --git a/ui-react/src/components/dialogs/Loop/DeployLoopModal.test.js b/ui-react/src/components/dialogs/Loop/DeployLoopModal.test.js index 5f1dcd5fc..84dbfd1f6 100644 --- a/ui-react/src/components/dialogs/Loop/DeployLoopModal.test.js +++ b/ui-react/src/components/dialogs/Loop/DeployLoopModal.test.js @@ -63,7 +63,8 @@ describe('Verify DeployLoopModal', () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); - const showAlert = jest.fn(); + const showSucAlert = jest.fn(); + const showFailAlert = jest.fn(); const handleSave = jest.spyOn(DeployLoopModal.prototype,'handleSave'); LoopService.updateGlobalProperties = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -88,7 +89,7 @@ describe('Verify DeployLoopModal', () => { }); const component = shallow() + loopCache={loopCache} updateLoopFunction={updateLoopFunction} showSucAlert={showSucAlert} showFailAlert={showFailAlert} />) component.find('[variant="primary"]').prop('onClick')(); await flushPromises(); diff --git a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js index 89e70795e..149639cbc 100644 --- a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js +++ b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js @@ -56,7 +56,7 @@ export default class OperationalPolicyModal extends React.Component { if (errors.length !== 0) { console.error("Errors detected during config policy data validation ", errors); - this.props.showAlert(errors); + this.props.showFailAlert(errors); } else { console.info("NO validation errors found in config policy data"); diff --git a/ui-react/src/components/dialogs/PerformActions.js b/ui-react/src/components/dialogs/PerformActions.js index 66b192863..cf5a3c20e 100644 --- a/ui-react/src/components/dialogs/PerformActions.js +++ b/ui-react/src/components/dialogs/PerformActions.js @@ -52,12 +52,12 @@ export default class PerformActions extends React.Component { const loopName = this.state.loopName; LoopActionService.performAction(loopName, action).then(pars => { - this.props.showAlert("Action " + action + " successfully performed"); + this.props.showSucAlert("Action " + action + " successfully performed"); // refresh status and update loop logs this.refreshStatus(loopName); }) .catch(error => { - this.props.showAlert("Action " + action + " failed"); + this.props.showFailAlert("Action " + action + " failed"); // refresh status and update loop logs this.refreshStatus(loopName); }); diff --git a/ui-react/src/components/dialogs/PerformActions.test.js b/ui-react/src/components/dialogs/PerformActions.test.js index 0b0786290..b833a929d 100644 --- a/ui-react/src/components/dialogs/PerformActions.test.js +++ b/ui-react/src/components/dialogs/PerformActions.test.js @@ -36,7 +36,8 @@ describe('Verify PerformActions', () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); - const showAlert = jest.fn(); + const showSucAlert = jest.fn(); + const showFailAlert = jest.fn(); LoopActionService.refreshStatus = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -46,7 +47,7 @@ describe('Verify PerformActions', () => { }); }); const component = shallow() + loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} showSucAlert={showSucAlert} showFailAlert={showFailAlert} />) await flushPromises(); component.update(); @@ -57,7 +58,8 @@ describe('Verify PerformActions', () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); - const showAlert = jest.fn(); + const showSucAlert = jest.fn(); + const showFailAlert = jest.fn(); LoopActionService.performAction = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -74,7 +76,7 @@ describe('Verify PerformActions', () => { }); }); const component = shallow() + loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} showSucAlert={showSucAlert} showFailAlert={showFailAlert} />) await flushPromises(); component.update(); diff --git a/ui-react/src/components/dialogs/RefreshStatus.js b/ui-react/src/components/dialogs/RefreshStatus.js index 64b35d99b..bb0939152 100644 --- a/ui-react/src/components/dialogs/RefreshStatus.js +++ b/ui-react/src/components/dialogs/RefreshStatus.js @@ -44,12 +44,12 @@ export default class RefreshStatus extends React.Component { componentDidMount() { // refresh status and update loop logs LoopActionService.refreshStatus(this.state.loopName).then(data => { - this.props.showAlert("Status successfully refreshed"); + this.props.showSucAlert("Status successfully refreshed"); this.props.updateLoopFunction(data); this.props.history.push('/'); }) .catch(error => { - this.props.showAlert("Status refreshing failed"); + this.props.showFailAlert("Status refreshing failed"); this.props.history.push('/'); }); } diff --git a/ui-react/src/components/dialogs/RefreshStatus.test.js b/ui-react/src/components/dialogs/RefreshStatus.test.js index 3038eb321..e08c50d2e 100644 --- a/ui-react/src/components/dialogs/RefreshStatus.test.js +++ b/ui-react/src/components/dialogs/RefreshStatus.test.js @@ -35,9 +35,10 @@ describe('Verify RefreshStatus', () => { it('Test refresh status failed', async () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; - const showAlert = jest.fn(); + const showSucAlert = jest.fn(); + const showFailAlert = jest.fn(); - const component = shallow() + const component = shallow() await flushPromises(); component.update(); @@ -48,7 +49,8 @@ describe('Verify RefreshStatus', () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); - const showAlert = jest.fn(); + const showSucAlert = jest.fn(); + const showFailAlert = jest.fn(); LoopActionService.refreshStatus = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -59,7 +61,7 @@ describe('Verify RefreshStatus', () => { }); const component = shallow() + loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} showSucAlert={showSucAlert} showFailAlert={showFailAlert} />) await flushPromises(); component.update(); -- cgit 1.2.3-korg