feat(test-case+bug): 测试用例模块 + Bug 模块完整实现
需求验收体系: - 测试用例:五态状态机(待执行/执行中/通过/失败/阻塞) - Bug:六态状态机(待修复/修复中/已修复/验证中/已关闭/已拒绝) - Bug 通过测试用例间接关联需求(不冗余存版本) - Bug 默认修复人 = 关联需求的开发任务负责人 - 测试进度 = 已执行用例/总用例, 通过率 = 通过/已执行 UI: - 版本详情页新增"测试用例" Tab + "BUG" Tab - 测试用例:统计栏+筛选+按需求分组列表+详情抽屉+提BUG入口 - Bug:统计栏+筛选+列表+详情抽屉(链式跳转用例→需求) - 概览胶囊"测试"阶段进度联动 - "与我相关"新增测试用例/Bug分组 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
92
apps/web/stores/useBugStore.ts
Normal file
92
apps/web/stores/useBugStore.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
'use client';
|
||||
import { create } from 'zustand';
|
||||
import type { Bug, BugStatus } from '@/lib/bug';
|
||||
import { canBugTransition, generateBugNo } from '@/lib/bug';
|
||||
|
||||
const STORAGE_KEY = 'ftb_bugs_v1';
|
||||
|
||||
function saveLocal(items: Bug[]) {
|
||||
try { localStorage.setItem(STORAGE_KEY, JSON.stringify(items)); } catch {}
|
||||
}
|
||||
|
||||
function loadLocal(): Bug[] | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (raw) return JSON.parse(raw);
|
||||
} catch {}
|
||||
return null;
|
||||
}
|
||||
|
||||
interface BugState {
|
||||
bugs: Bug[];
|
||||
fetchBugs: () => void;
|
||||
createBug: (data: Omit<Bug, 'id' | 'bugNo' | 'createdAt' | 'updatedAt' | 'status'>) => Bug;
|
||||
updateBug: (id: string, data: Partial<Bug>) => void;
|
||||
deleteBug: (id: string) => void;
|
||||
changeStatus: (id: string, to: BugStatus, extra?: { resolution?: string }) => { ok: boolean; message?: string };
|
||||
getByTestCase: (caseId: string) => Bug[];
|
||||
getByAssignee: (assigneeId: string) => Bug[];
|
||||
}
|
||||
|
||||
export const useBugStore = create<BugState>((set, get) => ({
|
||||
bugs: [],
|
||||
|
||||
fetchBugs: () => {
|
||||
const cached = loadLocal();
|
||||
if (cached) set({ bugs: cached });
|
||||
},
|
||||
|
||||
createBug: (data) => {
|
||||
const list = get().bugs;
|
||||
const now = new Date().toISOString();
|
||||
const bug: Bug = {
|
||||
...data,
|
||||
id: `bug-${Date.now()}`,
|
||||
bugNo: generateBugNo(list),
|
||||
status: 'open',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
const updated = [...list, bug];
|
||||
set({ bugs: updated });
|
||||
saveLocal(updated);
|
||||
return bug;
|
||||
},
|
||||
|
||||
updateBug: (id, data) => {
|
||||
const updated = get().bugs.map((b) =>
|
||||
b.id === id ? { ...b, ...data, updatedAt: new Date().toISOString() } : b,
|
||||
);
|
||||
set({ bugs: updated });
|
||||
saveLocal(updated);
|
||||
},
|
||||
|
||||
deleteBug: (id) => {
|
||||
const updated = get().bugs.filter((b) => b.id !== id);
|
||||
set({ bugs: updated });
|
||||
saveLocal(updated);
|
||||
},
|
||||
|
||||
changeStatus: (id, to, extra) => {
|
||||
const bug = get().bugs.find((b) => b.id === id);
|
||||
if (!bug) return { ok: false, message: 'Bug不存在' };
|
||||
if (!canBugTransition(bug.status, to)) {
|
||||
return { ok: false, message: `不允许从「${bug.status}」流转到「${to}」` };
|
||||
}
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const patch: Partial<Bug> = { status: to };
|
||||
if (to === 'fixed') patch.resolvedAt = today;
|
||||
if (to === 'closed') patch.closedAt = today;
|
||||
if (extra?.resolution) patch.resolution = extra.resolution;
|
||||
get().updateBug(id, patch);
|
||||
return { ok: true };
|
||||
},
|
||||
|
||||
getByTestCase: (caseId) => {
|
||||
return get().bugs.filter((b) => b.testCaseId === caseId);
|
||||
},
|
||||
|
||||
getByAssignee: (assigneeId) => {
|
||||
return get().bugs.filter((b) => b.assigneeId === assigneeId);
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user