Skip to content

Commit

Permalink
added error handling for invalid input on solve; added cypress test f…
Browse files Browse the repository at this point in the history
…or invalid input
  • Loading branch information
MichaelPesce committed Jul 7, 2022
1 parent 56e9cef commit 21dfa32
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
26 changes: 26 additions & 0 deletions electron/cypress/e2e/InvalidFlowsheetInput.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe('Invalid Input Test', () => {
it('test negative input for recovery rate', () => {
//load webpage
cy.visit('/')

//click example ro flowsheet
cy.findByRole('link', { name: /example ro flowsheet/i}).click()

//enter negative value for recovery rate
var recovery_textbox = cy.get('#outlined-basicRecovery')
recovery_textbox.click({force:true})
recovery_textbox = cy.get('#outlined-basicRecovery')
recovery_textbox.type('{backspace}{backspace}{backspace}-10')

//click on save
cy.findAllByRole('button', { name: /save/i}).eq(0).click()

//click on solve
cy.findAllByRole('button', { name: /solve/i}).eq(0).click()

//find error message
cy.findByRole('alert')

})

})
2 changes: 1 addition & 1 deletion electron/ui/src/components/InputWrapper/InputWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function InputWrapper(props) {
}

return <Tooltip title={fieldData.description}>
<TextField id="outlined-basic"
<TextField id={"outlined-basic"+fieldData.display_name}
label={fieldData.display_name}
variant="outlined"
size="small"
Expand Down
7 changes: 5 additions & 2 deletions electron/ui/src/components/SolveDialog/SolveDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Box from '@mui/material/Box';
import { solve } from "../../services/output.service";

export default function SolveDialog(props) {
const { open, handleSolved, flowsheetData, id } = props;
const { open, handleSolved, handleError, flowsheetData, id } = props;

useEffect(()=>{
if(open)
Expand All @@ -20,7 +20,10 @@ export default function SolveDialog(props) {
.then((outputData)=>{
console.log("outputData",outputData);
handleSolved(outputData);
});
}).catch(e => {
console.log("caught error: "+e)
handleError()
});
//},3000);
}
},[open]);
Expand Down
2 changes: 1 addition & 1 deletion electron/ui/src/tests/SolveDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ const id = 1;
test('test input accordion', () => {

render( <SolveDialog open={solveDialogOpen} handleSolved={mockhandleSolved} flowsheetData={flowsheetData} id={id}></SolveDialog> )
///flow_vol/i

//test for component elements
screen.getAllByRole('presentation', { name: ""});
screen.getByRole('dialog', { name: ""});
Expand Down
23 changes: 22 additions & 1 deletion electron/ui/src/views/FlowsheetConfig/FlowsheetConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function FlowsheetConfig() {
const [solveDialogOpen, setSolveDialogOpen] = useState(false);
const [outputData, setOutputData] = useState(null);
const [openSuccessSaveSnackbar, setOpenSuccessSaveSnackbar] = React.useState(false);
const [openErrorSnackbar, setOpenErrorSnackbar] = useState(false);

useEffect(()=>{
//console.log("params.id",params.id);
Expand Down Expand Up @@ -118,6 +119,12 @@ export default function FlowsheetConfig() {
setSolveDialogOpen(false);
};

const handleError = () => {
console.log("handle error");

setOpenErrorSnackbar(true);
setSolveDialogOpen(false);
};

const handleSave = (data) => {
console.log("handle save.....",data);
Expand All @@ -134,6 +141,9 @@ export default function FlowsheetConfig() {
setOpenSuccessSaveSnackbar(false);
};

const handleErrorSnackbarClose = () => {
setOpenErrorSnackbar(false);
};

const handleReset = () => {
console.log("reset. id:", params.id)
Expand Down Expand Up @@ -182,13 +192,24 @@ export default function FlowsheetConfig() {
</Box>
)
}
<SolveDialog open={solveDialogOpen} handleSolved={handleSolved} flowsheetData={flowsheetData} id={params.id}></SolveDialog>
<SolveDialog open={solveDialogOpen} handleSolved={handleSolved} handleError={handleError} flowsheetData={flowsheetData} id={params.id}></SolveDialog>
<Snackbar
open={openSuccessSaveSnackbar}
autoHideDuration={2000}
onClose={handleSuccessSaveSnackbarClose}
message="Changes saved!"
/>
<Snackbar
open={openSuccessSaveSnackbar}
autoHideDuration={2000}
onClose={handleSuccessSaveSnackbarClose}
message="Changes saved!"
/>
<Snackbar open={openErrorSnackbar} autoHideDuration={3000} onClose={handleErrorSnackbarClose}>
<Alert onClose={handleErrorSnackbarClose} severity="error">
Error: Data Input Infeasible
</Alert>
</Snackbar>
</Container>

);
Expand Down

0 comments on commit 21dfa32

Please sign in to comment.