Skip to content

Commit b4b3e1c

Browse files
authored
Merge pull request #59 from codingapi/dev
Dev
2 parents daf819d + 938e4be commit b4b3e1c

56 files changed

Lines changed: 1608 additions & 346 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

flow-engine-framework/src/main/java/com/codingapi/flow/manager/FlowNodeState.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.Getter;
66

77
import java.util.ArrayList;
8+
import java.util.Comparator;
89
import java.util.List;
910
import java.util.stream.Stream;
1011

@@ -31,7 +32,7 @@ public FlowNodeState(IFlowNode node) {
3132
this.branchNodeTypes.add(NodeType.PARALLEL_BRANCH.name());
3233
}
3334

34-
public boolean isEndNode(){
35+
public boolean isEndNode() {
3536
return this.node.getType().equals(NodeType.END.name());
3637
}
3738

@@ -65,8 +66,8 @@ public String getName() {
6566
}
6667

6768
public List<IFlowNode> getFirstBlocks() {
68-
List<IFlowNode> blocks = this.node.blocks();
69-
if (blocks != null && !blocks.isEmpty()) {
69+
List<IFlowNode> blocks = this.node.blocks().stream().sorted(Comparator.comparingInt(IFlowNode::getOrder)).toList();
70+
if (!blocks.isEmpty()) {
7071
return Stream.of(blocks.get(0)).toList();
7172
}
7273
return new ArrayList<>();

flow-engine-framework/src/main/java/com/codingapi/flow/node/nodes/ConditionNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void addDefaultBranch(int count){
3737
List<IFlowNode> branches = new ArrayList<>();
3838
for (int i=0;i<count;i++){
3939
ConditionBranchNode branchNode = new ConditionBranchNode();
40+
branchNode.setOrder(i+1);
4041
branches.add(branchNode);
4142
}
4243
this.setBlocks(branches);

flow-engine-framework/src/main/java/com/codingapi/flow/node/nodes/InclusiveNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void addDefaultBranch(int count){
4040
List<IFlowNode> branches = new ArrayList<>();
4141
for (int i=0;i<count;i++){
4242
InclusiveBranchNode branchNode = new InclusiveBranchNode();
43+
branchNode.setOrder(i+1);
4344
branches.add(branchNode);
4445
}
4546
this.setBlocks(branches);

flow-engine-framework/src/main/java/com/codingapi/flow/node/nodes/ParallelNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void addDefaultBranch(int count){
3838
List<IFlowNode> branches = new ArrayList<>();
3939
for (int i=0;i<count;i++){
4040
ParallelBranchNode branchNode = new ParallelBranchNode();
41+
branchNode.setOrder(i+1);
4142
branches.add(branchNode);
4243
}
4344
this.setBlocks(branches);

frontend/packages/flow-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
],
1515
"scripts": {
1616
"build": "rslib build",
17-
"dev": "rslib build --watch"
17+
"dev": "rslib build --watch",
18+
"test": "rstest"
1819
},
1920
"peerDependencies": {
2021
"react": ">=18",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {pluginReact} from '@rsbuild/plugin-react';
2+
import {defineConfig} from '@rstest/core';
3+
import {pluginSass} from "@rsbuild/plugin-sass";
4+
import * as path from "path";
5+
6+
export default defineConfig({
7+
testEnvironment: 'jsdom',
8+
setupFiles: ['./rstest.setup.ts'],
9+
plugins: [pluginReact(), pluginSass()],
10+
resolve: {
11+
alias: {
12+
"@/": path.resolve(__dirname, "src"),
13+
}
14+
}
15+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { expect } from '@rstest/core';
2+
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';
3+
4+
expect.extend(jestDomMatchers);

frontend/packages/flow-core/src/groovy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class GroovyScriptConvertorUtil {
415415
*/
416416
public static updateScriptMeta(script: string, meta: string): string {
417417
const metaComment = `// ${SCRIPT_META} ${meta}`;
418-
if (GroovyScriptConvertorUtil.getScriptTitle(script)) {
418+
if (GroovyScriptConvertorUtil.getScriptMeta(script)) {
419419
return script.replace(new RegExp(`//\\s*${SCRIPT_META}\\s*.+`), metaComment);
420420
} else {
421421
return `${metaComment}\n${script}`;

frontend/packages/flow-pc/flow-pc-design/tests/script/utils/convertor-utils.test.ts renamed to frontend/packages/flow-core/tests/groovy.test.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {describe, expect, it} from '@rstest/core';
2-
import {GroovyScriptConvertorUtil} from "@/components/script/utils/convertor";
2+
import {GroovyScriptConvertorUtil} from "@/groovy";
33

44
describe('GroovyScriptUtil', () => {
55

@@ -54,7 +54,7 @@ def run(request){
5454
});
5555

5656

57-
describe('getScriptMeta', () => {
57+
describe('getScriptMeta1', () => {
5858
it('get groovy script meta', () => {
5959
const script = `
6060
// @SCRIPT_TITLE 这是一个实例的标题
@@ -67,8 +67,21 @@ def run(request){
6767
});
6868
});
6969

70+
describe('getScriptMeta2', () => {
71+
it('get groovy script meta', () => {
72+
const script = `
73+
// @CUSTOM_SCRIPT 自定义脚本,返回的数据为动作类型
74+
// @SCRIPT_META {"trigger":"PASS"}
75+
def run(request){
76+
return 'SAVE';
77+
}`
78+
const result = GroovyScriptConvertorUtil.getScriptMeta(script)
79+
expect(result).toEqual(`{"trigger":"PASS"}`);
80+
});
81+
});
7082

71-
describe('updateScriptMeta', () => {
83+
84+
describe('updateScriptMeta1', () => {
7285
it('update groovy script meta', () => {
7386
const script = `
7487
// @SCRIPT_TITLE 这是一个实例的标题
@@ -82,4 +95,19 @@ def run(request){
8295
expect(title).toEqual(`{name:"test"}`);
8396
});
8497
});
98+
99+
describe('updateScriptMeta2', () => {
100+
it('update groovy script meta', () => {
101+
const script = `
102+
// @CUSTOM_SCRIPT 自定义脚本,返回的数据为动作类型
103+
// @SCRIPT_META {"trigger":"PASS"}
104+
def run(request){
105+
return 'SAVE';
106+
}`
107+
const result = GroovyScriptConvertorUtil.updateScriptMeta(script,'{trigger:"SAVE"}');
108+
console.log(result);
109+
const title = GroovyScriptConvertorUtil.getScriptMeta(result)
110+
expect(title).toEqual(`{trigger:"SAVE"}`);
111+
});
112+
});
85113
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@testing-library/jest-dom" />

0 commit comments

Comments
 (0)