get-vertices.test.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { describe, expect, it } from 'vitest';
  6. import { calcEllipseY, getHorizontalVertices, getVertices } from '../../src/components/utils';
  7. import {
  8. mockDivergeLine1,
  9. mockDivergeLine2,
  10. mockDivergeLine3,
  11. mockMergeLine3,
  12. mockMergeLine4,
  13. mockMergeLine5,
  14. noRadiusLine,
  15. noTypeLine,
  16. } from '../../__mocks__/mock-lines';
  17. describe('test Vertices', () => {
  18. it('calcEllipseY', () => {
  19. expect(calcEllipseY(1, 1, 3)).toEqual(0);
  20. });
  21. // 垂直布局
  22. it('getVertices diverge_line', () => {
  23. expect(() => getVertices(undefined as any)).toThrowError();
  24. // 正常线条
  25. const res1 = getVertices(mockDivergeLine1);
  26. expect(res1).toEqual([
  27. { x: 140, y: 215, radiusY: 3 },
  28. { x: 0, y: 215 },
  29. ]);
  30. // radiusYCount = 1
  31. const res2 = getVertices(mockDivergeLine2);
  32. expect(res2).toEqual([{ x: 156, y: 212, radiusY: 20 }]);
  33. // radiusYCount > 1 & radiusXCount < 1
  34. const res3 = getVertices(mockDivergeLine3);
  35. expect(res3).toEqual([
  36. { x: 140, y: 232, moveX: 0.5 },
  37. { x: 141, y: 232, moveX: 0.5 },
  38. ]);
  39. });
  40. it('getVertices merge_line', () => {
  41. // merge_line radiusYCount < 2
  42. const res3 = getVertices(mockMergeLine3);
  43. expect(res3).toEqual([{ x: 140, y: 235 }]);
  44. // merge_line radiusYCount > 2 & radiusXCount < 2
  45. const res4 = getVertices(mockMergeLine4);
  46. expect(res4).toEqual([
  47. { x: 140, y: 315, moveX: 0.5 },
  48. { x: 141, y: 315, moveX: 0.5 },
  49. ]);
  50. // merge_line radiusYCount > 2 & radiusXCount > 2
  51. const res5 = getVertices(mockMergeLine5);
  52. expect(res5).toEqual([
  53. { x: 140, y: 315, moveX: 5 },
  54. { x: 150, y: 315, moveX: 5 },
  55. ]);
  56. });
  57. it('getVertices no radius line', () => {
  58. const noRadiusRes = getVertices(noRadiusLine);
  59. expect(noRadiusRes).toEqual([]);
  60. const noTypeRes = getVertices(noTypeLine as any);
  61. expect(noTypeRes).toEqual([]);
  62. });
  63. // 水平布局
  64. it('getHorizontalVertices diverge_line', () => {
  65. expect(() => getHorizontalVertices(undefined as any)).toThrowError();
  66. // 正常线条
  67. const res1 = getHorizontalVertices(mockDivergeLine1);
  68. expect(res1).toEqual([
  69. { x: 160, y: 212, moveY: 11.5 },
  70. { x: 160, y: 235, moveY: 11.5 },
  71. ]);
  72. // radiusYCount = 1
  73. const res2 = getHorizontalVertices(mockDivergeLine2);
  74. expect(res2).toEqual([{ x: 156, y: 212, radiusX: 16 }]);
  75. // radiusYCount > 1 & radiusXCount < 2
  76. const res3 = getHorizontalVertices(mockDivergeLine3, 0.9);
  77. expect(res3).toEqual([
  78. { x: 121, y: 212, radiusX: -19 },
  79. { x: 121, y: 332 },
  80. ]);
  81. });
  82. it('getHorizontalVertices merge_line', () => {
  83. // merge_line radiusYCount < 2
  84. const res3 = getHorizontalVertices(mockMergeLine3);
  85. expect(res3).toEqual([
  86. { x: -20, y: 212, moveY: 11.5 },
  87. { x: -20, y: 235, moveY: 11.5 },
  88. ]);
  89. // merge_line radiusYCount > 2 & radiusXCount < 2
  90. const res4 = getHorizontalVertices(mockMergeLine4, 0.9);
  91. expect(res4).toEqual([{ x: 141, y: 212 }]);
  92. // merge_line radiusYCount > 2 & radiusXCount > 2
  93. const res5 = getHorizontalVertices(mockMergeLine5);
  94. expect(res5).toEqual([]);
  95. });
  96. it('getHorizontalVertices no radius line', () => {
  97. const noRadiusRes = getHorizontalVertices(noRadiusLine);
  98. expect(noRadiusRes).toEqual([]);
  99. const noTypeRes = getHorizontalVertices(noTypeLine as any);
  100. expect(noTypeRes).toEqual([]);
  101. });
  102. });