update at 2026-01-21 21:48:08

This commit is contained in:
douboer@gmail.com
2026-01-21 21:48:08 +08:00
parent 54f3fd93f2
commit 78d8801a07
8 changed files with 184 additions and 271 deletions

View File

@@ -25,7 +25,6 @@ describe('useLuopan', () => {
expect(result).toHaveProperty('rings');
expect(result).toHaveProperty('outerMost');
expect(result).toHaveProperty('sectors');
expect(result).toHaveProperty('getLabelTransform');
expect(result).toHaveProperty('toXY');
});
@@ -92,7 +91,6 @@ describe('useLuopan', () => {
expect(sector).toHaveProperty('path');
expect(sector).toHaveProperty('textPath');
expect(sector).toHaveProperty('textPathId');
expect(sector).toHaveProperty('needReverse');
expect(sector).toHaveProperty('isVertical');
expect(sector).toHaveProperty('fontSize');
});
@@ -161,8 +159,8 @@ describe('useLuopan', () => {
const { sectors } = useLuopan(example, textRadialPosition);
sectors.value.forEach((sector) => {
expect(sector.fill).toMatch(/^(hsl\(.*\)|#[0-9a-fA-F]{6}|#ffffff)$/);
expect(sector.textColor).toMatch(/^(#[0-9a-fA-F]{6}|#ffffff)$/);
expect(sector.fill).toMatch(/^#[0-9a-fA-F]{6}$/);
expect(sector.textColor).toMatch(/^#[0-9a-fA-F]{6}$/);
});
});
@@ -248,38 +246,6 @@ describe('useLuopan', () => {
});
});
describe('文字方向', () => {
it('应该为左半圆的扇区设置 needReverse', () => {
const example = ref(createMockExample());
const textRadialPosition = ref<TextRadialPosition>('middle');
const { sectors } = useLuopan(example, textRadialPosition);
// 中间角度在 (90, 270) 范围内的扇区应该需要反向
const leftSectors = sectors.value.filter(
(s) => s.aMidDeg > 90 && s.aMidDeg < 270
);
leftSectors.forEach((sector) => {
expect(sector.needReverse).toBe(true);
});
});
it('应该为右半圆的扇区不设置 needReverse', () => {
const example = ref(createMockExample());
const textRadialPosition = ref<TextRadialPosition>('middle');
const { sectors } = useLuopan(example, textRadialPosition);
// 中间角度在 [0, 90] 或 [270, 360] 范围内的扇区不需要反向
const rightSectors = sectors.value.filter(
(s) => s.aMidDeg <= 90 || s.aMidDeg >= 270
);
rightSectors.forEach((sector) => {
expect(sector.needReverse).toBe(false);
});
});
});
describe('竖排文字判断', () => {
it('应该为窄扇区设置 isVertical', () => {
const example = ref({
@@ -384,21 +350,6 @@ describe('useLuopan', () => {
});
});
describe('getLabelTransform', () => {
it('应该返回有效的 SVG transform 字符串', () => {
const example = ref(createMockExample());
const textRadialPosition = ref<TextRadialPosition>('middle');
const { sectors, getLabelTransform } = useLuopan(example, textRadialPosition);
const sector = sectors.value[0];
const transform = getLabelTransform(sector);
expect(transform).toContain('translate');
expect(transform).toContain('rotate');
});
});
describe('toXY', () => {
it('应该正确转换极坐标', () => {
const example = ref(createMockExample());