You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 6 месеца
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. describe('preprocessNodesAndEdges', () => {
  8. it('process nodes without iteration node or loop node should return origin nodes and edges.', () => {
  9. const nodes = [
  10. {
  11. data: {
  12. type: BlockEnum.Code,
  13. },
  14. },
  15. ]
  16. const result = preprocessNodesAndEdges(nodes as Node[], [])
  17. expect(result).toEqual({
  18. nodes,
  19. edges: [],
  20. })
  21. })
  22. it('process nodes with iteration node should return nodes with iteration start node', () => {
  23. const nodes = [
  24. {
  25. id: 'iteration',
  26. data: {
  27. type: BlockEnum.Iteration,
  28. },
  29. },
  30. ]
  31. const result = preprocessNodesAndEdges(nodes as Node[], [])
  32. expect(result.nodes).toEqual(
  33. expect.arrayContaining([
  34. expect.objectContaining({
  35. data: expect.objectContaining({
  36. type: BlockEnum.IterationStart,
  37. }),
  38. }),
  39. ]),
  40. )
  41. })
  42. it('process nodes with iteration node start should return origin', () => {
  43. const nodes = [
  44. {
  45. data: {
  46. type: BlockEnum.Iteration,
  47. start_node_id: 'iterationStart',
  48. },
  49. },
  50. {
  51. id: 'iterationStart',
  52. type: CUSTOM_ITERATION_START_NODE,
  53. data: {
  54. type: BlockEnum.IterationStart,
  55. },
  56. },
  57. ]
  58. const result = preprocessNodesAndEdges(nodes as Node[], [])
  59. expect(result).toEqual({
  60. nodes,
  61. edges: [],
  62. })
  63. })
  64. })