Merge branch 'main' of github.com:sartography/spiff-arena into main

This commit is contained in:
Dan 2022-12-21 12:53:03 -05:00
commit 2912c5fed3
2 changed files with 111 additions and 55 deletions

View File

@ -1669,7 +1669,7 @@ def script_unit_test_create(
extension_elements = None extension_elements = None
extension_elements_array = script_task_element.xpath( extension_elements_array = script_task_element.xpath(
"//bpmn:extensionElements", ".//bpmn:extensionElements",
namespaces={"bpmn": "http://www.omg.org/spec/BPMN/20100524/MODEL"}, namespaces={"bpmn": "http://www.omg.org/spec/BPMN/20100524/MODEL"},
) )
if len(extension_elements_array) == 0: if len(extension_elements_array) == 0:

View File

@ -6,11 +6,20 @@ import {
useSearchParams, useSearchParams,
} from 'react-router-dom'; } from 'react-router-dom';
// @ts-ignore // @ts-ignore
import { Button, Modal, Stack, Content } from '@carbon/react'; import {
Button,
Modal,
Content,
Tabs,
TabList,
Tab,
TabPanels,
TabPanel,
} from '@carbon/react';
import Row from 'react-bootstrap/Row'; import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col'; import Col from 'react-bootstrap/Col';
import Editor from '@monaco-editor/react'; import Editor, { DiffEditor } from '@monaco-editor/react';
import MDEditor from '@uiw/react-md-editor'; import MDEditor from '@uiw/react-md-editor';
import ReactDiagramEditor from '../components/ReactDiagramEditor'; import ReactDiagramEditor from '../components/ReactDiagramEditor';
@ -401,6 +410,13 @@ export default function ProcessModelEditDiagram() {
}; };
}; };
const jsonEditorOptions = () => {
return Object.assign(generalEditorOptions(), {
minimap: { enabled: false },
folding: true,
});
};
const setPreviousScriptUnitTest = () => { const setPreviousScriptUnitTest = () => {
resetUnitTextResult(); resetUnitTextResult();
const newScriptIndex = currentScriptUnitTestIndex - 1; const newScriptIndex = currentScriptUnitTestIndex - 1;
@ -495,11 +511,32 @@ export default function ProcessModelEditDiagram() {
} }
let errorContextElement = null; let errorContextElement = null;
if (scriptUnitTestResult.context) { if (scriptUnitTestResult.context) {
errorStringElement = (
<span>Unexpected result. Please see the comparison below.</span>
);
let outputJson = '{}';
if (currentScriptUnitTest) {
outputJson = JSON.stringify(
JSON.parse(currentScriptUnitTest.expectedOutputJson.value),
null,
' '
);
}
const contextJson = JSON.stringify(
scriptUnitTestResult.context,
null,
' '
);
errorContextElement = ( errorContextElement = (
<span> <DiffEditor
Received unexpected output:{' '} height={200}
{JSON.stringify(scriptUnitTestResult.context)} width="auto"
</span> originalLanguage="json"
modifiedLanguage="json"
options={Object.assign(jsonEditorOptions(), {})}
original={outputJson}
modified={contextJson}
/>
); );
} }
return ( return (
@ -543,19 +580,29 @@ export default function ProcessModelEditDiagram() {
</Col> </Col>
); );
} }
const inputJson = JSON.stringify(
JSON.parse(currentScriptUnitTest.inputJson.value),
null,
' '
);
const outputJson = JSON.stringify(
JSON.parse(currentScriptUnitTest.expectedOutputJson.value),
null,
' '
);
return ( return (
<main> <main>
<Content> <Content>
<Row> <Row>
<Col xs={8}> <Col xs={8}>
<Button variant="link" disabled style={{ fontSize: '1.5em' }}> <Button variant="link" disabled>
Unit Test: {currentScriptUnitTest.id} Unit Test: {currentScriptUnitTest.id}
</Button> </Button>
</Col> </Col>
<Col xs={1}> <Col xs={1}>
<Button <Button
data-qa="unit-test-previous-button" data-qa="unit-test-previous-button"
style={{ fontSize: '1.5em' }}
onClick={setPreviousScriptUnitTest} onClick={setPreviousScriptUnitTest}
variant="link" variant="link"
disabled={previousButtonDisable} disabled={previousButtonDisable}
@ -586,61 +633,45 @@ export default function ProcessModelEditDiagram() {
</Col> </Col>
<Col xs={1}>{scriptUnitTestResultBoolElement}</Col> <Col xs={1}>{scriptUnitTestResultBoolElement}</Col>
</Row> </Row>
</Content> <Row>
<Stack orientation="horizontal" gap={3}> <Col>{unitTestFailureElement()}</Col>
{unitTestFailureElement()} </Row>
</Stack> <Row>
<Stack orientation="horizontal" gap={3}> <Col>
<Stack>
<div>Input Json:</div> <div>Input Json:</div>
<div> <div>
<Editor <Editor
height={200} height={500}
width="auto"
defaultLanguage="json" defaultLanguage="json"
options={Object.assign(generalEditorOptions(), { options={Object.assign(jsonEditorOptions(), {})}
minimap: { enabled: false }, value={inputJson}
})}
value={currentScriptUnitTest.inputJson.value}
onChange={handleEditorScriptTestUnitInputChange} onChange={handleEditorScriptTestUnitInputChange}
/> />
</div> </div>
</Stack> </Col>
<Stack> <Col>
<div>Expected Output Json:</div> <div>Expected Output Json:</div>
<div> <div>
<Editor <Editor
height={200} height={500}
width="auto"
defaultLanguage="json" defaultLanguage="json"
options={Object.assign(generalEditorOptions(), { options={Object.assign(jsonEditorOptions(), {})}
minimap: { enabled: false }, value={outputJson}
})}
value={currentScriptUnitTest.expectedOutputJson.value}
onChange={handleEditorScriptTestUnitOutputChange} onChange={handleEditorScriptTestUnitOutputChange}
/> />
</div> </div>
</Stack> </Col>
</Stack> </Row>
</Content>
</main> </main>
); );
} }
return null; return null;
}; };
const scriptEditor = () => { const scriptEditor = () => {
let scriptName = '';
if (scriptElement) {
scriptName = (scriptElement as any).di.bpmnElement.name;
}
return ( return (
<Modal
open={showScriptEditor}
modalHeading={`Editing Script: ${scriptName}`}
primaryButtonText="Close"
onRequestSubmit={handleScriptEditorClose}
size="lg"
onRequestClose={handleScriptEditorClose}
>
<Editor <Editor
height={500} height={500}
width="auto" width="auto"
@ -650,7 +681,32 @@ export default function ProcessModelEditDiagram() {
onChange={handleEditorScriptChange} onChange={handleEditorScriptChange}
onMount={handleEditorDidMount} onMount={handleEditorDidMount}
/> />
{scriptUnitTestEditorElement()} );
};
const scriptEditorAndTests = () => {
let scriptName = '';
if (scriptElement) {
scriptName = (scriptElement as any).di.bpmnElement.name;
}
return (
<Modal
open={showScriptEditor}
modalHeading={`Editing Script: ${scriptName}`}
primaryButtonText="Close"
onRequestSubmit={handleScriptEditorClose}
size="lg"
onRequestClose={handleScriptEditorClose}
>
<Tabs>
<TabList aria-label="List of tabs" activation="manual">
<Tab>Script Editor</Tab>
<Tab>Unit Tests</Tab>
</TabList>
<TabPanels>
<TabPanel>{scriptEditor()}</TabPanel>
<TabPanel>{scriptUnitTestEditorElement()}</TabPanel>
</TabPanels>
</Tabs>
</Modal> </Modal>
); );
}; };
@ -878,7 +934,7 @@ export default function ProcessModelEditDiagram() {
{saveFileMessage()} {saveFileMessage()}
{appropriateEditor()} {appropriateEditor()}
{newFileNameBox()} {newFileNameBox()}
{scriptEditor()} {scriptEditorAndTests()}
{markdownEditor()} {markdownEditor()}
{processModelSelector()} {processModelSelector()}
<div id="diagram-container" /> <div id="diagram-container" />