需求验收体系: - 测试用例:五态状态机(待执行/执行中/通过/失败/阻塞) - Bug:六态状态机(待修复/修复中/已修复/验证中/已关闭/已拒绝) - Bug 通过测试用例间接关联需求(不冗余存版本) - Bug 默认修复人 = 关联需求的开发任务负责人 - 测试进度 = 已执行用例/总用例, 通过率 = 通过/已执行 UI: - 版本详情页新增"测试用例" Tab + "BUG" Tab - 测试用例:统计栏+筛选+按需求分组列表+详情抽屉+提BUG入口 - Bug:统计栏+筛选+列表+详情抽屉(链式跳转用例→需求) - 概览胶囊"测试"阶段进度联动 - "与我相关"新增测试用例/Bug分组 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
94 lines
5.2 KiB
TypeScript
94 lines
5.2 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useMemo } from 'react';
|
|
import { X } from 'lucide-react';
|
|
import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
|
import { useRequirementStore } from '@/stores/useRequirementStore';
|
|
import { useMemberStore } from '@/stores/useMemberStore';
|
|
import { useAuthStore } from '@/stores/useAuthStore';
|
|
import type { Priority } from '@/lib/derive';
|
|
|
|
interface Props {
|
|
requirementIds: string[];
|
|
onClose: () => void;
|
|
}
|
|
|
|
export function TestCaseCreateModal({ requirementIds, onClose }: Props) {
|
|
const { createTestCase } = useTestCaseStore();
|
|
const { requirements } = useRequirementStore();
|
|
const { members } = useMemberStore();
|
|
const user = useAuthStore((s) => s.user);
|
|
|
|
const versionReqs = useMemo(
|
|
() => requirements.filter((r) => requirementIds.includes(r.id)),
|
|
[requirements, requirementIds],
|
|
);
|
|
|
|
const [title, setTitle] = useState('');
|
|
const [requirementId, setRequirementId] = useState(versionReqs[0]?.id || '');
|
|
const [priority, setPriority] = useState<Priority>(versionReqs[0]?.priority || 'P2');
|
|
const [assigneeId, setAssigneeId] = useState(user?.name || '');
|
|
const [description, setDescription] = useState('');
|
|
|
|
const canSubmit = title.trim() && requirementId;
|
|
|
|
const handleSubmit = () => {
|
|
if (!canSubmit) return;
|
|
createTestCase({
|
|
requirementId,
|
|
title: title.trim(),
|
|
description: description.trim() || undefined,
|
|
priority,
|
|
assigneeId: assigneeId || undefined,
|
|
createdBy: user?.name || '系统',
|
|
});
|
|
onClose();
|
|
};
|
|
|
|
return (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40" onClick={onClose}>
|
|
<div className="w-full max-w-md rounded-2xl bg-[var(--bg-card)] border border-[var(--line)] p-6 shadow-[var(--shadow-md)]" onClick={(e) => e.stopPropagation()}>
|
|
<div className="flex items-center justify-between mb-4">
|
|
<h3 className="text-[14px] font-semibold text-[var(--ink)]">新建测试用例</h3>
|
|
<button onClick={onClose} className="rounded-md p-1 hover:bg-[var(--bg-subtle)]"><X className="h-4 w-4 text-[var(--ink-muted)]" /></button>
|
|
</div>
|
|
<div className="space-y-3">
|
|
<div>
|
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">用例标题 *</label>
|
|
<input value={title} onChange={(e) => setTitle(e.target.value)} className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none" placeholder="例如:正常排班" />
|
|
</div>
|
|
<div>
|
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">所属需求 *</label>
|
|
<select value={requirementId} onChange={(e) => { setRequirementId(e.target.value); const r = versionReqs.find((x) => x.id === e.target.value); if (r) setPriority(r.priority); }} className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none">
|
|
{versionReqs.map((r) => <option key={r.id} value={r.id}>{r.code} {r.title}</option>)}
|
|
</select>
|
|
</div>
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">优先级</label>
|
|
<select value={priority} onChange={(e) => setPriority(e.target.value as Priority)} className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none">
|
|
{(['P0','P1','P2','P3'] as Priority[]).map((p) => <option key={p} value={p}>{p}</option>)}
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">测试负责人</label>
|
|
<select value={assigneeId} onChange={(e) => setAssigneeId(e.target.value)} className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none">
|
|
<option value="">选择负责人</option>
|
|
{members.map((m) => <option key={m.id} value={m.name}>{m.name}</option>)}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">测试步骤 & 预期结果</label>
|
|
<textarea rows={4} value={description} onChange={(e) => setDescription(e.target.value)} className="w-full rounded-lg border border-[var(--line)] bg-[var(--bg)] px-3 py-2 text-[13px] focus:border-[var(--accent)] focus:outline-none resize-none" placeholder="1. 操作步骤... 2. 预期结果..." />
|
|
</div>
|
|
</div>
|
|
<div className="flex justify-end gap-2 pt-4 border-t border-[var(--line)] mt-4">
|
|
<button onClick={onClose} className="h-8 px-3 rounded-lg text-[12px] font-medium border border-[var(--line)] text-[var(--ink-soft)] hover:bg-[var(--bg-subtle)]">取消</button>
|
|
<button onClick={handleSubmit} disabled={!canSubmit} className="h-8 px-4 rounded-lg text-[12px] font-medium bg-[var(--accent)] text-white hover:bg-[var(--accent-hover)] disabled:opacity-50">创建</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|