2
0

flow-render-tree.spec.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { beforeEach, describe, expect, it } from 'vitest';
  6. // import { FlowDocumentConfigEnum } from '../src/typings';
  7. // import { FlowDocumentConfigDefaultData } from '../src/flow-document-config';
  8. import { FlowDocument } from '../src/flow-document';
  9. import { baseMockNodeEnd2 } from './flow.mock';
  10. import { createDocumentContainer } from './flow-document-container.mock';
  11. describe('flow-render-tree', () => {
  12. let container = createDocumentContainer();
  13. let document: FlowDocument;
  14. beforeEach(() => {
  15. container = createDocumentContainer();
  16. document = container.get<FlowDocument>(FlowDocument);
  17. });
  18. /**
  19. * 节点折叠
  20. */
  21. it('node collapsed', () => {
  22. container.get(FlowDocument).fromJSON(baseMockNodeEnd2);
  23. document = container.get<FlowDocument>(FlowDocument);
  24. const { renderTree } = document;
  25. const inlineBlocks1 = document.getNode('$inlineBlocks$dynamicSplitcxIBv')!;
  26. const inlineBlocks2 = document.getNode('$inlineBlocks$split')!;
  27. inlineBlocks1.collapsed = true;
  28. renderTree.updateRenderStruct();
  29. expect(inlineBlocks1.children.length).toEqual(0);
  30. expect(inlineBlocks1.allCollapsedChildren.length).toEqual(5);
  31. expect(document.renderTree.toString()).toEqual(`root
  32. |-- start_0
  33. |-- split
  34. |---- $blockIcon$split
  35. |---- $inlineBlocks$split
  36. |------ branch_0
  37. |-------- $blockOrderIcon$branch_0
  38. |-------- endbL5T2
  39. |------ branch_1
  40. |-------- $blockOrderIcon$branch_1
  41. |-------- dynamicSplitcxIBv
  42. |---------- $blockIcon$dynamicSplitcxIBv
  43. |---------- $inlineBlocks$dynamicSplitcxIBv
  44. |-------- endT3VLX
  45. |------ _sJEq
  46. |-------- $blockOrderIcon$_sJEq
  47. |-- staticSplitHLvrh
  48. |---- $blockIcon$staticSplitHLvrh
  49. |---- $inlineBlocks$staticSplitHLvrh
  50. |------ fPE-N
  51. |-------- $blockOrderIcon$fPE-N
  52. |------ ulpHV
  53. |-------- $blockOrderIcon$ulpHV
  54. |-- end_0`);
  55. inlineBlocks2.collapsed = true;
  56. renderTree.updateRenderStruct();
  57. expect(inlineBlocks2.children.length).toEqual(0);
  58. expect(inlineBlocks2.allCollapsedChildren.length).toEqual(16);
  59. expect(document.renderTree.toString()).toEqual(`root
  60. |-- start_0
  61. |-- split
  62. |---- $blockIcon$split
  63. |---- $inlineBlocks$split
  64. |-- staticSplitHLvrh
  65. |---- $blockIcon$staticSplitHLvrh
  66. |---- $inlineBlocks$staticSplitHLvrh
  67. |------ fPE-N
  68. |-------- $blockOrderIcon$fPE-N
  69. |------ ulpHV
  70. |-------- $blockOrderIcon$ulpHV
  71. |-- end_0`);
  72. });
  73. it('render tree stop modified tree', () => {
  74. const { renderTree } = document;
  75. expect(() => renderTree.remove()).toThrowError(/cannot use/);
  76. expect(() => renderTree.addChild()).toThrowError(/cannot use/);
  77. expect(() => renderTree.insertAfter()).toThrowError(/cannot use/);
  78. expect(() => renderTree.removeParent()).toThrowError(/cannot use/);
  79. });
  80. // /**
  81. // * 处理结束节点偏移
  82. // * 结束节点产品改方案
  83. // */
  84. // it.skip('refine end branch', () => {
  85. // container.bind(FlowDocumentConfigDefaultData).toConstantValue({
  86. // [FlowDocumentConfigEnum.END_NODES_REFINE_BRANCH]: true,
  87. // });
  88. // container.get(FlowDocument).fromJSON(dataList.end);
  89. // document = container.get<FlowDocument>(FlowDocument);
  90. //
  91. // const inlineBlocks1 = document.getNode('$inlineBlocks$dynamicSplitcxIBv')!;
  92. // const inlineBlocks2 = document.getNode('$inlineBlocks$split')!;
  93. // inlineBlocks1.collapsed = false;
  94. // inlineBlocks2.collapsed = false;
  95. //
  96. // const { renderTree } = document;
  97. // renderTree.updateRenderStruct();
  98. //
  99. // expect(document.renderTree.toString()).toMatchSnapshot();
  100. //
  101. // inlineBlocks2.collapsed = true;
  102. // renderTree.updateRenderStruct();
  103. //
  104. // // 结束节点拽进去的节点都需要收起
  105. // expect(document.renderTree.toString()).toMatchSnapshot();
  106. // });
  107. });