Chore/slice workflow utils (#17730)

This commit is contained in:
zxhlyh
2025-04-10 10:03:19 +08:00
committed by GitHub
parent 9d5a0fdd8a
commit 30f7118c7a
19 changed files with 1215 additions and 1081 deletions

View File

@@ -0,0 +1,69 @@
import { preprocessNodesAndEdges } from './workflow-init'
import { BlockEnum } from '@/app/components/workflow/types'
import type {
Node,
} from '@/app/components/workflow/types'
import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants'
describe('preprocessNodesAndEdges', () => {
it('process nodes without iteration node or loop node should return origin nodes and edges.', () => {
const nodes = [
{
data: {
type: BlockEnum.Code,
},
},
]
const result = preprocessNodesAndEdges(nodes as Node[], [])
expect(result).toEqual({
nodes,
edges: [],
})
})
it('process nodes with iteration node should return nodes with iteration start node', () => {
const nodes = [
{
id: 'iteration',
data: {
type: BlockEnum.Iteration,
},
},
]
const result = preprocessNodesAndEdges(nodes as Node[], [])
expect(result.nodes).toEqual(
expect.arrayContaining([
expect.objectContaining({
data: expect.objectContaining({
type: BlockEnum.IterationStart,
}),
}),
]),
)
})
it('process nodes with iteration node start should return origin', () => {
const nodes = [
{
data: {
type: BlockEnum.Iteration,
start_node_id: 'iterationStart',
},
},
{
id: 'iterationStart',
type: CUSTOM_ITERATION_START_NODE,
data: {
type: BlockEnum.IterationStart,
},
},
]
const result = preprocessNodesAndEdges(nodes as Node[], [])
expect(result).toEqual({
nodes,
edges: [],
})
})
})