feat(test-case): 测试耗时自动计算(逻辑同开发任务)
- TestCase 新增 startedAt / completedAt 字段 - 流转到"执行中"时记录 startedAt - 流转到"通过/失败/阻塞"时记录 completedAt - 回退到执行中时清除 completedAt - 测试耗时 = startedAt → completedAt 工作日 × 8h - 列表行显示耗时,详情抽屉显示开始/完成/耗时 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
||||
import { useBugStore } from '@/stores/useBugStore';
|
||||
import { useRequirementStore } from '@/stores/useRequirementStore';
|
||||
import { TC_ALLOWED_TRANSITIONS, TEST_CASE_STATUS_LABEL } from '@/lib/test-case';
|
||||
import { calcActualHoursByDates } from '@/lib/dev-task';
|
||||
import { BUG_SEVERITY_LABEL, BUG_SEVERITY_COLOR } from '@/lib/bug';
|
||||
import type { TestCaseStatus } from '@/lib/test-case';
|
||||
|
||||
@@ -126,6 +127,9 @@ export function TestCaseDetailDrawer({ testCaseId, onClose, onCreateBug }: Props
|
||||
<div><span className="text-[var(--ink-muted)]">负责人:</span><span className="text-[var(--ink)] font-medium">{tc.assigneeId || '-'}</span></div>
|
||||
<div><span className="text-[var(--ink-muted)]">创建人:</span><span className="text-[var(--ink)]">{tc.createdBy}</span></div>
|
||||
<div><span className="text-[var(--ink-muted)]">创建日期:</span><span className="text-[var(--ink)]">{tc.createdAt.slice(0, 10)}</span></div>
|
||||
{tc.startedAt && <div><span className="text-[var(--ink-muted)]">开始执行:</span><span className="text-[var(--ink)]">{tc.startedAt}</span></div>}
|
||||
{tc.completedAt && <div><span className="text-[var(--ink-muted)]">执行完成:</span><span className="text-[var(--ink)]">{tc.completedAt}</span></div>}
|
||||
{tc.startedAt && <div><span className="text-[var(--ink-muted)]">测试耗时:</span><span className="text-[var(--ink)] font-medium">{calcActualHoursByDates(tc.startedAt, tc.completedAt)}h</span></div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { TestCaseStatusBadge } from './TestCaseStatusBadge';
|
||||
import { calcActualHoursByDates } from '@/lib/dev-task';
|
||||
import type { TestCase } from '@/lib/test-case';
|
||||
import type { Bug } from '@/lib/bug';
|
||||
|
||||
interface Props {
|
||||
testCase: TestCase;
|
||||
@@ -24,6 +24,9 @@ export function TestCaseRow({ testCase, bugCount, onClick }: Props) {
|
||||
<span className="text-[11px] font-mono text-[var(--ink-muted)] w-14 shrink-0">{testCase.caseNo}</span>
|
||||
<span className="text-[13px] text-[var(--ink)] flex-1 truncate">{testCase.title}</span>
|
||||
<TestCaseStatusBadge status={testCase.status} />
|
||||
{testCase.startedAt && (
|
||||
<span className="text-[11px] text-[var(--ink-muted)] tabular-nums w-10 text-right">{calcActualHoursByDates(testCase.startedAt, testCase.completedAt)}h</span>
|
||||
)}
|
||||
{bugCount > 0 && (
|
||||
<span className="text-[10px] text-red-500 bg-red-50 px-1.5 py-0.5 rounded">{bugCount} Bug</span>
|
||||
)}
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface TestCase {
|
||||
priority: Priority;
|
||||
assigneeId?: string;
|
||||
status: TestCaseStatus;
|
||||
startedAt?: string;
|
||||
completedAt?: string;
|
||||
executedAt?: string;
|
||||
executedBy?: string;
|
||||
failReason?: string;
|
||||
|
||||
@@ -76,12 +76,17 @@ export const useTestCaseStore = create<TestCaseState>((set, get) => ({
|
||||
}
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const patch: Partial<TestCase> = { status: to };
|
||||
// 开始执行时间
|
||||
if (to === 'running' && !tc.startedAt) patch.startedAt = today;
|
||||
// 执行完成时间(通过/失败/阻塞都算执行完成)
|
||||
if (to === 'passed' || to === 'failed' || to === 'blocked') patch.completedAt = today;
|
||||
if (to === 'running' || to === 'passed' || to === 'failed' || to === 'blocked') {
|
||||
patch.executedAt = today;
|
||||
}
|
||||
// 回退到执行中时清除完成时间
|
||||
if (to === 'running') { patch.failReason = undefined; patch.blockReason = undefined; patch.completedAt = undefined; }
|
||||
if (to === 'failed' && extra?.failReason) patch.failReason = extra.failReason;
|
||||
if (to === 'blocked' && extra?.blockReason) patch.blockReason = extra.blockReason;
|
||||
if (to === 'running') { patch.failReason = undefined; patch.blockReason = undefined; }
|
||||
get().updateTestCase(id, patch);
|
||||
return { ok: true };
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user