rounded-turning-line.test.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import * as React from 'react';
  6. import { describe, test, expect, vi } from 'vitest';
  7. import { Container, interfaces } from 'inversify';
  8. import { render } from '@testing-library/react';
  9. import {
  10. FlowDocumentContainerModule,
  11. FlowTransitionLine,
  12. FlowTransitionLineEnum,
  13. } from '@flowgram.ai/document';
  14. import RoundedTurningLine from '../../src/components/RoundedTurningLine';
  15. function createDocumentContainer(): interfaces.Container {
  16. const container = new Container();
  17. container.load(FlowDocumentContainerModule);
  18. // container.bind(FlowDocumentContribution).to(FlowDocumentMockRegister);
  19. return container;
  20. }
  21. vi.mock('../../src/hooks/use-base-color.ts', () => ({
  22. useBaseColor: () => ({
  23. baseActivatedColor: '#fff',
  24. baseColor: '#fff',
  25. }),
  26. BASE_DEFAULT_COLOR: '#BBBFC4',
  27. BASE_DEFAULT_ACTIVATED_COLOR: '#82A7FC',
  28. }));
  29. describe('RoundedTurningLine', () => {
  30. test('should render RoundedTurningLine correctly', () => {
  31. const line: FlowTransitionLine = {
  32. type: FlowTransitionLineEnum.ROUNDED_LINE,
  33. from: {
  34. x: 0,
  35. y: 0,
  36. },
  37. to: {
  38. x: 100,
  39. y: 100,
  40. },
  41. vertices: [
  42. {
  43. x: 100,
  44. y: 0,
  45. },
  46. ],
  47. };
  48. const { container } = render(<RoundedTurningLine {...line} />);
  49. expect(container.querySelector('path')).toBeDefined();
  50. });
  51. test('should render RoundedTurningLine horizontal & arrow & active', () => {
  52. const line: FlowTransitionLine = {
  53. type: FlowTransitionLineEnum.ROUNDED_LINE,
  54. from: {
  55. x: 0,
  56. y: 0,
  57. },
  58. to: {
  59. x: 100,
  60. y: 100,
  61. },
  62. activated: true,
  63. };
  64. const { container } = render(<RoundedTurningLine arrow={true} isHorizantal={true} {...line} />);
  65. expect(container.querySelector('path')).toBeDefined();
  66. });
  67. test('should render with vertices', () => {
  68. const line: FlowTransitionLine = {
  69. type: FlowTransitionLineEnum.ROUNDED_LINE,
  70. from: {
  71. x: 0,
  72. y: 0,
  73. },
  74. to: {
  75. x: 100,
  76. y: 100,
  77. },
  78. vertices: [
  79. {
  80. x: 0,
  81. y: 30,
  82. },
  83. {
  84. x: 0,
  85. y: 30,
  86. radiusX: 30,
  87. radiusY: 30,
  88. },
  89. {
  90. x: 0,
  91. y: 30,
  92. moveX: 10,
  93. moveY: 10,
  94. },
  95. {
  96. x: 50,
  97. y: 50,
  98. },
  99. ],
  100. activated: true,
  101. };
  102. const { container } = render(<RoundedTurningLine arrow={true} isHorizantal={true} {...line} />);
  103. expect(container.querySelector('path')).toBeDefined();
  104. });
  105. test('should hide RoundedTurningLine', () => {
  106. const line: FlowTransitionLine = {
  107. type: FlowTransitionLineEnum.ROUNDED_LINE,
  108. from: {
  109. x: 0,
  110. y: 0,
  111. },
  112. to: {
  113. x: 100,
  114. y: 100,
  115. },
  116. };
  117. const { container } = render(<RoundedTurningLine hide={true} {...line} />);
  118. expect(container.querySelector('path')).toBeNull();
  119. });
  120. });