您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

workflow-init.spec.ts 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { preprocessNodesAndEdges } from './workflow-init'
  2. import { BlockEnum } from '@/app/components/workflow/types'
  3. import type {
  4. Node,
  5. } from '@/app/components/workflow/types'
  6. import { CUSTOM_ITERATION_START_NODE } from '@/app/components/workflow/nodes/iteration-start/constants'
  7. jest.mock('ky', () => ({
  8. __esModule: true,
  9. default: {
  10. create: jest.fn(),
  11. },
  12. }))
  13. jest.mock('lodash-es/groupBy', () => ({
  14. __esModule: true,
  15. default: jest.fn(),
  16. }))
  17. describe('preprocessNodesAndEdges', () => {
  18. it('process nodes without iteration node or loop node should return origin nodes and edges.', () => {
  19. const nodes = [
  20. {
  21. data: {
  22. type: BlockEnum.Code,
  23. },
  24. },
  25. ]
  26. const result = preprocessNodesAndEdges(nodes as Node[], [])
  27. expect(result).toEqual({
  28. nodes,
  29. edges: [],
  30. })
  31. })
  32. it('process nodes with iteration node should return nodes with iteration start node', () => {
  33. const nodes = [
  34. {
  35. id: 'iteration',
  36. data: {
  37. type: BlockEnum.Iteration,
  38. },
  39. },
  40. ]
  41. const result = preprocessNodesAndEdges(nodes as Node[], [])
  42. expect(result.nodes).toEqual(
  43. expect.arrayContaining([
  44. expect.objectContaining({
  45. data: expect.objectContaining({
  46. type: BlockEnum.IterationStart,
  47. }),
  48. }),
  49. ]),
  50. )
  51. })
  52. it('process nodes with iteration node start should return origin', () => {
  53. const nodes = [
  54. {
  55. data: {
  56. type: BlockEnum.Iteration,
  57. start_node_id: 'iterationStart',
  58. },
  59. },
  60. {
  61. id: 'iterationStart',
  62. type: CUSTOM_ITERATION_START_NODE,
  63. data: {
  64. type: BlockEnum.IterationStart,
  65. },
  66. },
  67. ]
  68. const result = preprocessNodesAndEdges(nodes as Node[], [])
  69. expect(result).toEqual({
  70. nodes,
  71. edges: [],
  72. })
  73. })
  74. })