Skip to content

Commit

Permalink
fix(invalid_test): show error popup if test data is invalid (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
anusha5695 committed Oct 26, 2020
1 parent 60b1d7f commit fa93612
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
11 changes: 11 additions & 0 deletions ui/constants/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const EMPTY_STRING = "";
const ERROR_TITLE = "Error";
const INVALID_TEST_MESSAGE = "Oh no, I can't render this test, please use the API.";
const OK_BUTTON_MESSAGE = "OK";

export {
EMPTY_STRING,
ERROR_TITLE,
INVALID_TEST_MESSAGE,
OK_BUTTON_MESSAGE,
}
7 changes: 4 additions & 3 deletions ui/src/features/components/ErrorDialog/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import { OK_BUTTON_MESSAGE, EMPTY_STRING, ERROR_TITLE } from '../../../../constants/constants';

export default (props) => {
const { closeDialog, showMessage } = props;
const actions = [
<FlatButton
label='OK'
label={OK_BUTTON_MESSAGE}
primary
onClick={closeDialog}
/>
Expand All @@ -16,7 +17,7 @@ export default (props) => {
}
return (
<Dialog
title={'Error'}
title={ERROR_TITLE}
actions={actions}
modal={false}
open
Expand All @@ -30,7 +31,7 @@ export default (props) => {
}

const displayError = (message) => {
return '' + message;
return EMPTY_STRING + message;
};

const displayDescription = (message) => {
Expand Down
49 changes: 40 additions & 9 deletions ui/src/features/get-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import { ReactTableComponent } from '../components/ReactTable';
import { getColumns } from './configurationColumn';
import Button from '../components/Button';
import ErrorDialog from './components/ErrorDialog';
import ActionErrorPopup from './components/ActionErrorPopup';
import _ from 'lodash';

import { isTestValid } from '../validators/validate-test';
import { INVALID_TEST_MESSAGE } from '../../constants/constants'
const noDataMsg = 'There is no data to display.';
const errorMsgGetTests = 'Error occurred while trying to get all tests.';
const columnsNames = ['name', 'description', 'updated_at', 'type', 'run_test', 'report', 'edit', 'raw', 'clone', 'delete'];
Expand All @@ -43,6 +45,7 @@ class getTests extends React.Component {
testToDelete: undefined,
createTest: false,
testForEdit: null,
testActionError: null,
sortedTests: [],
sortHeader: ''
}
Expand All @@ -59,7 +62,11 @@ class getTests extends React.Component {
data && this.onRunTest(data);
} else if (path === '/tests/:testId/edit') {
const data = this.props.tests.find((test) => test.id === params.testId);
data && this.onEdit(data);
if (!isTestValid(data)) {
this.setTestActionError({errorMessage : INVALID_TEST_MESSAGE });
} else {
this.onEdit(data);
}
}
}
}
Expand Down Expand Up @@ -118,13 +125,32 @@ class getTests extends React.Component {
this.setState({ openViewTest: data });
};

updateTestActionError = ({ errorMessage }) => {
this.setState({
testActionError: errorMessage,
});
};

setTestActionError = ({ errorMessage }) => {
this.updateTestActionError({ errorMessage: errorMessage })
};

resetTestActionError = () => {
this.updateTestActionError({ errorMessage: null })
};

onEdit = (data) => {
const { match: { params, path }, history } = this.props;
if (path !== '/tests/:testId/edit') {
history.replace(`/tests/${data.id}/edit`)
if (!isTestValid(data)) {
this.setTestActionError({ errorMessage : INVALID_TEST_MESSAGE });
}
else {
if (path !== '/tests/:testId/edit') {
history.replace(`/tests/${data.id}/edit`)
}
this.setState({ createTest: true, testForEdit: data });
// this.props.chooseTest(data);
}
this.setState({ createTest: true, testForEdit: data });
// this.props.chooseTest(data);
};

onReportView = (data) => {
Expand Down Expand Up @@ -197,10 +223,16 @@ class getTests extends React.Component {
}

onCloseErrorDialog = () => {
this.resetTestActionError();
this.props.cleanAllErrors();
};
onClone = (data) => {
this.setState({ createTest: true, testForClone: data });
if (!isTestValid(data)) {
this.setTestActionError({ errorMessage: INVALID_TEST_MESSAGE });
}
else {
this.setState({ createTest: true, testForClone: data });
}
};
generateFeedbackMessage = () => {
const { createJobSuccess, deleteTestSuccess } = this.props;
Expand Down Expand Up @@ -228,7 +260,7 @@ class getTests extends React.Component {
onClone: this.onClone
});
const feedbackMsg = this.generateFeedbackMessage();
const error = errorOnDeleteTest;
const error = this.state.testActionError || errorOnDeleteTest;
return (
<Page title={'Tests'} description={DESCRIPTION}>
<Button className={style['create-button']} onClick={() => {
Expand Down Expand Up @@ -272,7 +304,6 @@ class getTests extends React.Component {
onRequestClose={this.handleSnackbarClose}
/>}
{error && <ErrorDialog closeDialog={this.onCloseErrorDialog} showMessage={error} />}

</Page>
)
}
Expand Down
15 changes: 15 additions & 0 deletions ui/src/validators/validate-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createStateForEditTest } from '../features/components/TestForm/utils';

const isTestValid = (test) => {
try {
createStateForEditTest(test);
return true;
}
catch (e) {
return false;
}
}

export {
isTestValid,
}

0 comments on commit fa93612

Please sign in to comment.