mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-02-12 09:46:46 +00:00
Bug fixes for Script Unit Test user interface -- don't bug out on invalid json.
This commit is contained in:
parent
75bd973ae0
commit
db29bcde57
@ -70,10 +70,10 @@ export default function ProcessModelEditDiagram() {
|
|||||||
|
|
||||||
interface ScriptUnitTestResult {
|
interface ScriptUnitTestResult {
|
||||||
result: boolean;
|
result: boolean;
|
||||||
context: object;
|
context?: object;
|
||||||
error: string;
|
error?: string;
|
||||||
line_number: number;
|
line_number?: number;
|
||||||
offset: number;
|
offset?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [currentScriptUnitTest, setCurrentScriptUnitTest] =
|
const [currentScriptUnitTest, setCurrentScriptUnitTest] =
|
||||||
@ -468,6 +468,16 @@ export default function ProcessModelEditDiagram() {
|
|||||||
|
|
||||||
const runCurrentUnitTest = () => {
|
const runCurrentUnitTest = () => {
|
||||||
if (currentScriptUnitTest && scriptElement) {
|
if (currentScriptUnitTest && scriptElement) {
|
||||||
|
let inputJson = '';
|
||||||
|
let expectedJson = '';
|
||||||
|
try {
|
||||||
|
inputJson = JSON.parse(currentScriptUnitTest.inputJson.value);
|
||||||
|
expectedJson = JSON.parse(currentScriptUnitTest.expectedOutputJson.value);
|
||||||
|
} catch (e) {
|
||||||
|
setScriptUnitTestResult({ result:false, error:"The JSON provided contains a formatting error."})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
resetUnitTextResult();
|
resetUnitTextResult();
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: `/process-models/${modifiedProcessModelId}/script-unit-tests/run`,
|
path: `/process-models/${modifiedProcessModelId}/script-unit-tests/run`,
|
||||||
@ -476,10 +486,8 @@ export default function ProcessModelEditDiagram() {
|
|||||||
postBody: {
|
postBody: {
|
||||||
bpmn_task_identifier: (scriptElement as any).id,
|
bpmn_task_identifier: (scriptElement as any).id,
|
||||||
python_script: scriptText,
|
python_script: scriptText,
|
||||||
input_json: JSON.parse(currentScriptUnitTest.inputJson.value),
|
input_json: inputJson,
|
||||||
expected_output_json: JSON.parse(
|
expected_output_json: expectedJson
|
||||||
currentScriptUnitTest.expectedOutputJson.value
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -488,19 +496,20 @@ export default function ProcessModelEditDiagram() {
|
|||||||
const unitTestFailureElement = () => {
|
const unitTestFailureElement = () => {
|
||||||
if (
|
if (
|
||||||
scriptUnitTestResult &&
|
scriptUnitTestResult &&
|
||||||
scriptUnitTestResult.result === false &&
|
scriptUnitTestResult.result === false
|
||||||
!scriptUnitTestResult.line_number
|
|
||||||
) {
|
) {
|
||||||
let errorStringElement = null;
|
let errorMessage = '';
|
||||||
if (scriptUnitTestResult.error) {
|
if (scriptUnitTestResult.context) {
|
||||||
errorStringElement = (
|
errorMessage = 'Unexpected result. Please see the comparison below.';
|
||||||
<span>
|
} else if (scriptUnitTestResult.line_number) {
|
||||||
Received error when running script:{' '}
|
errorMessage = `Error encountered running the script. Please check the code around line ${ scriptUnitTestResult.line_number}`
|
||||||
{JSON.stringify(scriptUnitTestResult.error)}
|
} else {
|
||||||
</span>
|
errorMessage = `Error encountered running the script. ${JSON.stringify(scriptUnitTestResult.error)}`
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
let errorStringElement = <span>{ errorMessage }</span>;
|
||||||
|
|
||||||
let errorContextElement = null;
|
let errorContextElement = null;
|
||||||
|
|
||||||
if (scriptUnitTestResult.context) {
|
if (scriptUnitTestResult.context) {
|
||||||
errorStringElement = (
|
errorStringElement = (
|
||||||
<span>Unexpected result. Please see the comparison below.</span>
|
<span>Unexpected result. Please see the comparison below.</span>
|
||||||
@ -571,16 +580,22 @@ export default function ProcessModelEditDiagram() {
|
|||||||
</Col>
|
</Col>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const inputJson = JSON.stringify(
|
let inputJson = currentScriptUnitTest.inputJson.value;
|
||||||
JSON.parse(currentScriptUnitTest.inputJson.value),
|
let outputJson = currentScriptUnitTest.expectedOutputJson.value;
|
||||||
null,
|
try {
|
||||||
' '
|
inputJson = JSON.stringify(
|
||||||
);
|
JSON.parse(currentScriptUnitTest.inputJson.value),
|
||||||
const outputJson = JSON.stringify(
|
null,
|
||||||
JSON.parse(currentScriptUnitTest.expectedOutputJson.value),
|
' '
|
||||||
null,
|
);
|
||||||
' '
|
outputJson = JSON.stringify(
|
||||||
);
|
JSON.parse(currentScriptUnitTest.expectedOutputJson.value),
|
||||||
|
null,
|
||||||
|
' '
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
// Attemping to format the json failed -- it's invalid.
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user