93 lines
3.0 KiB
TypeScript
93 lines
3.0 KiB
TypeScript
/**
|
|
* useLuopan 组合函数单元测试
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { ref } from 'vue';
|
|
import { useLuopan } from '../src/composables/useLuopan';
|
|
import type { LuopanConfig, TextRadialPosition } from '../src/types';
|
|
|
|
const createMockConfig = (): LuopanConfig => ({
|
|
name: '测试配置',
|
|
background: '#000000',
|
|
theme: {
|
|
colorPalettes: {
|
|
A: '#111111',
|
|
},
|
|
},
|
|
layers: [
|
|
{
|
|
divisions: 4,
|
|
rInner: 0,
|
|
rOuter: 80,
|
|
sectors: [{ content: '甲' }, { content: '乙' }, { content: '丙' }, { content: '丁' }],
|
|
},
|
|
],
|
|
});
|
|
|
|
describe('useLuopan', () => {
|
|
it('应该返回所有必需的属性和方法', async () => {
|
|
const textRadialPosition = ref<TextRadialPosition>('middle');
|
|
const result = useLuopan(createMockConfig(), textRadialPosition);
|
|
await result.reload();
|
|
|
|
expect(result).toHaveProperty('anglesDeg');
|
|
expect(result).toHaveProperty('rings');
|
|
expect(result).toHaveProperty('outerMost');
|
|
expect(result).toHaveProperty('sectors');
|
|
expect(result).toHaveProperty('degreeRing');
|
|
expect(result).toHaveProperty('centerIcon');
|
|
expect(result).toHaveProperty('toXY');
|
|
});
|
|
|
|
it('anglesDeg 应该按 divisions 生成角度数组', async () => {
|
|
const textRadialPosition = ref<TextRadialPosition>('middle');
|
|
const { anglesDeg, reload } = useLuopan(createMockConfig(), textRadialPosition);
|
|
await reload();
|
|
|
|
expect(anglesDeg.value).toEqual([0, 90, 180, 270, 360]);
|
|
});
|
|
|
|
it('rings 应该返回 rOuter 列表', async () => {
|
|
const textRadialPosition = ref<TextRadialPosition>('middle');
|
|
const { rings, reload } = useLuopan(createMockConfig(), textRadialPosition);
|
|
await reload();
|
|
|
|
expect(rings.value).toEqual([80]);
|
|
});
|
|
|
|
it('outerMost 应该返回最大半径', async () => {
|
|
const textRadialPosition = ref<TextRadialPosition>('middle');
|
|
const { outerMost, reload } = useLuopan(createMockConfig(), textRadialPosition);
|
|
await reload();
|
|
|
|
expect(outerMost.value).toBe(80);
|
|
});
|
|
|
|
it('应该生成正确数量的扇区', async () => {
|
|
const textRadialPosition = ref<TextRadialPosition>('middle');
|
|
const { sectors, reload } = useLuopan(createMockConfig(), textRadialPosition);
|
|
await reload();
|
|
|
|
expect(sectors.value.length).toBe(4);
|
|
});
|
|
|
|
it('扇区应包含必要字段', async () => {
|
|
const textRadialPosition = ref<TextRadialPosition>('middle');
|
|
const { sectors, reload } = useLuopan(createMockConfig(), textRadialPosition);
|
|
await reload();
|
|
|
|
sectors.value.forEach((sector) => {
|
|
expect(sector).toHaveProperty('key');
|
|
expect(sector).toHaveProperty('layerIndex');
|
|
expect(sector).toHaveProperty('pieIndex');
|
|
expect(sector).toHaveProperty('rInner');
|
|
expect(sector).toHaveProperty('rOuter');
|
|
expect(sector).toHaveProperty('aStart');
|
|
expect(sector).toHaveProperty('aEnd');
|
|
expect(sector).toHaveProperty('path');
|
|
expect(sector).toHaveProperty('textPath');
|
|
});
|
|
});
|
|
});
|