test: 集成 Vitest 测试框架和开发规范

- 安装 vitest, @vue/test-utils, jsdom 等测试依赖
- 配置 vitest.config.js 测试环境
- 添加 schema.test.ts (7个数据结构验证测试)
- 添加 useStore.test.ts (7个状态管理测试)
- 创建测试指南文档 (docs/testing.md)
- 创建测试规范文档 (docs/testing-rules.md)
- 创建开发规范文档 (docs/development-rules.md)
- 创建开发工作流程文档 (docs/1management/workflow.md)
- 添加测试相关 npm scripts (test, test:watch, test:ui, test:coverage)
- 所有测试通过 (14/14)
This commit is contained in:
2026-02-12 23:25:13 +08:00
parent c4d701b443
commit 92aa4094f5
13 changed files with 4245 additions and 17 deletions

View File

@@ -0,0 +1,98 @@
import { describe, it, expect } from 'vitest'
import {
CURRENT_SCHEMA_VERSION,
DefaultNodeStyle,
type GraphNode,
type GraphEdge,
type NodeProperties,
type RootDocument
} from '../ts/schema'
describe('Schema 数据结构验证', () => {
it('当前 schema 版本应该是 1.0.0', () => {
expect(CURRENT_SCHEMA_VERSION).toBe('1.0.0')
})
it('DefaultNodeStyle 应该包含正确的默认值', () => {
expect(DefaultNodeStyle).toMatchObject({
width: 180,
height: 120,
rotate: 0,
fill: '#ffffff',
stroke: '#dcdfe6'
})
})
it('创建 GraphNode 应该符合类型定义', () => {
const node: GraphNode = {
id: 'node-1',
type: 'rect',
x: 100,
y: 200,
properties: {
style: {
width: 200,
height: 150,
fill: '#ff0000'
}
}
}
expect(node.id).toBe('node-1')
expect(node.type).toBe('rect')
expect(node.properties.style.width).toBe(200)
})
it('创建 GraphEdge 应该包含必需字段', () => {
const edge: GraphEdge = {
id: 'edge-1',
sourceNodeId: 'node-1',
targetNodeId: 'node-2'
}
expect(edge.id).toBe('edge-1')
expect(edge.sourceNodeId).toBe('node-1')
expect(edge.targetNodeId).toBe('node-2')
})
it('NodeProperties 应该支持式神数据', () => {
const properties: NodeProperties = {
style: DefaultNodeStyle,
shikigami: {
name: '茨木童子',
avatar: '/assets/Shikigami/ibaraki.png',
rarity: 'SSR'
}
}
expect(properties.shikigami?.name).toBe('茨木童子')
expect(properties.shikigami?.rarity).toBe('SSR')
})
it('NodeProperties 应该支持御魂数据', () => {
const properties: NodeProperties = {
style: DefaultNodeStyle,
yuhun: {
name: '破势',
type: '攻击',
avatar: '/assets/Yuhun/poshi.png'
}
}
expect(properties.yuhun?.name).toBe('破势')
expect(properties.yuhun?.type).toBe('攻击')
})
it('RootDocument 应该包含文件列表和活动文件', () => {
const doc: RootDocument = {
schemaVersion: '1.0.0',
fileList: [],
activeFile: 'File 1',
activeFileId: 'f_123'
}
expect(doc.schemaVersion).toBe('1.0.0')
expect(doc.activeFile).toBe('File 1')
expect(doc.activeFileId).toBe('f_123')
})
})