From 21dfa3207ab55e147566da1f4cf51ed3395226eb Mon Sep 17 00:00:00 2001 From: Michael Pesce Date: Thu, 7 Jul 2022 09:07:10 -0400 Subject: [PATCH] added error handling for invalid input on solve; added cypress test for invalid input --- .../cypress/e2e/InvalidFlowsheetInput.cy.js | 26 +++++++++++++++++++ .../components/InputWrapper/InputWrapper.js | 2 +- .../src/components/SolveDialog/SolveDialog.js | 7 +++-- electron/ui/src/tests/SolveDialog.test.js | 2 +- .../views/FlowsheetConfig/FlowsheetConfig.js | 23 +++++++++++++++- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 electron/cypress/e2e/InvalidFlowsheetInput.cy.js diff --git a/electron/cypress/e2e/InvalidFlowsheetInput.cy.js b/electron/cypress/e2e/InvalidFlowsheetInput.cy.js new file mode 100644 index 0000000000..e7f5237879 --- /dev/null +++ b/electron/cypress/e2e/InvalidFlowsheetInput.cy.js @@ -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') + + }) + +}) \ No newline at end of file diff --git a/electron/ui/src/components/InputWrapper/InputWrapper.js b/electron/ui/src/components/InputWrapper/InputWrapper.js index d0e46c70f9..a61ada3dd0 100644 --- a/electron/ui/src/components/InputWrapper/InputWrapper.js +++ b/electron/ui/src/components/InputWrapper/InputWrapper.js @@ -36,7 +36,7 @@ export default function InputWrapper(props) { } return - { if(open) @@ -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]); diff --git a/electron/ui/src/tests/SolveDialog.test.js b/electron/ui/src/tests/SolveDialog.test.js index 26f4c7ca15..cb0a3d1a47 100644 --- a/electron/ui/src/tests/SolveDialog.test.js +++ b/electron/ui/src/tests/SolveDialog.test.js @@ -561,7 +561,7 @@ const id = 1; test('test input accordion', () => { render( ) -///flow_vol/i + //test for component elements screen.getAllByRole('presentation', { name: ""}); screen.getByRole('dialog', { name: ""}); diff --git a/electron/ui/src/views/FlowsheetConfig/FlowsheetConfig.js b/electron/ui/src/views/FlowsheetConfig/FlowsheetConfig.js index ba1d435136..df933d1eac 100644 --- a/electron/ui/src/views/FlowsheetConfig/FlowsheetConfig.js +++ b/electron/ui/src/views/FlowsheetConfig/FlowsheetConfig.js @@ -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); @@ -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); @@ -134,6 +141,9 @@ export default function FlowsheetConfig() { setOpenSuccessSaveSnackbar(false); }; + const handleErrorSnackbarClose = () => { + setOpenErrorSnackbar(false); + }; const handleReset = () => { console.log("reset. id:", params.id) @@ -182,13 +192,24 @@ export default function FlowsheetConfig() { ) } - + + + + + Error: Data Input Infeasible + + );