Skip to content

Commit 924cf47

Browse files
committed
chore: demo with simple mocks
1 parent 794e030 commit 924cf47

File tree

5 files changed

+99
-18
lines changed

5 files changed

+99
-18
lines changed

demo/App.jsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
import { useState, useRef, useEffect } from 'react';
2+
3+
import BpmnModeler from 'bpmn-js/lib/Modeler';
4+
15
import 'bpmn-js/dist/assets/diagram-js.css';
26
import 'bpmn-js/dist/assets/bpmn-js.css';
37
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css';
48

5-
import { useState, useRef, useEffect } from 'react';
6-
import BpmnModeler from 'bpmn-js/lib/Modeler';
9+
import TaskTesting from '../lib';
710

8-
// import TaskTesting from '../lib';
11+
import {
12+
saveFile,
13+
deploymentConfig,
14+
deployResources,
15+
createProcessInstance,
16+
getProcessInstance
17+
} from '../test/mock';
918

1019
import diagram from './diagram.bpmn?raw';
1120

@@ -43,11 +52,22 @@ function App() {
4352
}
4453
}, [ modeler ]);
4554

55+
const injector = modeler?.get('injector');
56+
57+
const props = {
58+
injector,
59+
saveFile,
60+
deploymentConfig,
61+
deployResources,
62+
createProcessInstance,
63+
getProcessInstance
64+
};
65+
4666
return (
4767
<>
4868
<div className="modeler" ref={ modelerRef }></div>
4969
<div className="bottom-panel">
50-
{/* <TaskTesting /> */}
70+
{injector && <TaskTesting { ...props } />}
5171
</div>
5272
</>
5373
);

demo/main.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import React from 'react';
22
import ReactDOM from 'react-dom/client';
33
import App from './App.jsx';
44

5-
// import './index.scss';
6-
75
ReactDOM.createRoot(document.getElementById('root')).render(
86
<React.StrictMode>
97
<App />

lib/components/TabContent.jsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { useState, useEffect } from 'react';
1+
import { useState, useEffect, useRef } from 'react';
2+
23
import classNames from 'classnames';
34

45
import { is } from 'bpmn-js/lib/util/ModelUtil';
@@ -19,13 +20,24 @@ export default function TabContent(props) {
1920
const [ input, setInput ] = useState('{\n\n}');
2021
const [ loading, setLoading ] = useState(false);
2122
const [ selectedElement, setSelectedElement ] = useState(null);
22-
const [ test, setTest ] = useState(null);
2323
const [ testResults, setTestResults ] = useState({});
2424

25-
useEffect(() => {
26-
const _test = new Test(...props);
25+
const utilRef = useRef(null);
2726

28-
setTest(_test);
27+
useEffect(() => {
28+
const {
29+
deploymentConfig,
30+
deployResources,
31+
createProcessInstance,
32+
getProcessInstance
33+
} = props;
34+
35+
utilRef.current = new Test(
36+
deployResources,
37+
deploymentConfig,
38+
createProcessInstance,
39+
getProcessInstance
40+
);
2941
}, []);
3042

3143
useEffect(() => {
@@ -64,10 +76,6 @@ export default function TabContent(props) {
6476
}, [ input ]);
6577

6678
const onTest = async () => {
67-
if (!test) {
68-
return;
69-
}
70-
7179
setLoading(true);
7280

7381
saveFile();
@@ -77,7 +85,7 @@ export default function TabContent(props) {
7785
[ selectedElement.id ]: null
7886
});
7987

80-
const results = await test.run(selectedElement.id, input, (getProcessInstanceResult) => {
88+
const results = await utilRef.current.run(selectedElement.id, input, (getProcessInstanceResult) => {
8189
if (getProcessInstanceResult.success) {
8290
setTestResults({
8391
...testResults,

lib/utils/Test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class Test {
1717
* @param {getProcessInstance} getProcessInstance
1818
* @param {DeploymentConfig} deploymentConfig
1919
*/
20-
construtor(deployResources, deploymentConfig, createProcessInstance, getProcessInstance) {
20+
constructor(deployResources, deploymentConfig, createProcessInstance, getProcessInstance) {
2121

2222
this._deployResources = deployResources;
2323
this._deploymentConfig = deploymentConfig;
@@ -41,7 +41,7 @@ export default class Test {
4141
// return deploymentResponse;
4242
// }
4343

44-
const { deployments } = deploymentResponse.response;
44+
const { deployments } = deploymentResponse;
4545

4646
// Naive approach
4747
const processId = deployments?.[0]?.processDefinition?.processId;

test/mock/index.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
export const injector = {
2+
get() {
3+
return {
4+
on: () => {},
5+
off: () => {},
6+
};
7+
}
8+
};
9+
10+
export function saveFile() {}
11+
12+
export const deploymentConfig = {
13+
tenantId: 'mock-tenant-id',
14+
deploymentKey: 'mock-deployment-key',
15+
resources: [
16+
{
17+
content: 'mock-content',
18+
name: 'mock-process.bpmn'
19+
}
20+
]
21+
};
22+
23+
export function deployResources(resources, tenantId) {
24+
return {
25+
deploymentKey: 'mock-deployment-key',
26+
tenantId: tenantId,
27+
deployments: [
28+
{
29+
processDefinition: {
30+
processId: 'mock-process-id'
31+
}
32+
}
33+
]
34+
};
35+
}
36+
37+
export function createProcessInstance(processId, config) {
38+
return {
39+
processInstanceKey: 'mock-process-instance-key'
40+
};
41+
}
42+
43+
export function getProcessInstance(processId, config) {
44+
return {
45+
success: true,
46+
type: 'instanceFound',
47+
response: {
48+
processId: 'mock-process-id',
49+
variables: {
50+
input: 'mock-input',
51+
output: 'mock-output'
52+
}
53+
}
54+
};
55+
}

0 commit comments

Comments
 (0)