wwf
2025-05-20 938c3e5a587ce950a94964ea509b9e7f8834dfae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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: [],
    })
  })
})