feat(版本详情): 优化任务统计与测试轮次

This commit is contained in:
Script Generator
2026-06-26 15:12:24 +08:00
parent 914e6180c1
commit 2d802318fa
16 changed files with 631 additions and 65 deletions

View File

@@ -1,6 +1,6 @@
'use client';
import { create } from 'zustand';
import type { TestCase, TestCaseStatus } from '@/lib/test-case';
import type { CreateTestCaseInput, TestCase, TestCaseStatus } from '@/lib/test-case';
import { generateCaseNo, normalizeTestCases } from '@/lib/test-case';
import { applyTestCaseTransition, normalizeTestCaseOnCreate } from '@/lib/test-case-workflow';
import { createEntityId, dedupeEntityIds } from '@/lib/entity-id';
@@ -20,7 +20,8 @@ async function loadStored(): Promise<TestCase[] | null> {
interface TestCaseState {
testCases: TestCase[];
fetchTestCases: () => Promise<void>;
createTestCase: (data: Omit<TestCase, 'id' | 'caseNo' | 'createdAt' | 'updatedAt' | 'status'>) => TestCase;
createTestCase: (data: CreateTestCaseInput) => TestCase;
createTestCases: (items: CreateTestCaseInput[]) => TestCase[];
updateTestCase: (id: string, data: Partial<TestCase>) => void;
deleteTestCase: (id: string) => void;
changeStatus: (id: string, to: TestCaseStatus, extra?: { failReason?: string; blockReason?: string }) => { ok: boolean; message?: string };
@@ -58,6 +59,28 @@ export const useTestCaseStore = create<TestCaseState>((set, get) => ({
return tc;
},
createTestCases: (items) => {
if (items.length === 0) return [];
let list = get().testCases;
const now = new Date().toISOString();
const created: TestCase[] = [];
for (const data of items) {
const tc: TestCase = normalizeTestCaseOnCreate({
...data,
id: createEntityId('tc'),
caseNo: generateCaseNo(list),
status: 'pending',
createdAt: now,
updatedAt: now,
} as TestCase);
created.push(tc);
list = [...list, tc];
}
set({ testCases: list });
saveStored(list);
return created;
},
updateTestCase: (id, data) => {
const updated = get().testCases.map((c) =>
c.id === id ? { ...c, ...data, aiDraft: false, updatedAt: new Date().toISOString() } : c,