Skip to content
18 changes: 18 additions & 0 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,21 @@ _Avoid_:项目负责人、项目管理员
**项目成员**:
可以进入一个项目,但不能管理它的项目角色。
_Avoid_:member、参与者

## 用例与测试任务

**用例状态**:
一条用例在用例库中的生命周期状态:草稿、生效或废弃。
_Avoid_:用例阶段、发布状态

**测试任务**:
一次评审和执行一组用例的工作。测试任务不修改用例库。
_Avoid_:测试计划、评审单、轮次

**测试任务状态**:
一个测试任务的进度:待评审、待测试、测试中、已完成或已提交。
_Avoid_:任务阶段、运行状态

**执行结果**:
一条用例在一个测试任务中的结果:未测、通过、失败、阻塞或跳过。
_Avoid_:测试结果、用例结果、verdict
4 changes: 2 additions & 2 deletions apps/web/src/components/auth-settings/auth-url-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Label } from "@automationstack/ui/components/label";
import { type ChangeEvent, useCallback } from "react";

import { CopyButton } from "@/components/auth-settings/copy-button";
import { JiraFieldError } from "@/components/settings/jira-field-error";
import { FieldError } from "@/components/interaction/field-error";

export interface AuthUrlFieldProps {
copyLabel: string;
Expand Down Expand Up @@ -50,7 +50,7 @@ export function AuthUrlField(props: AuthUrlFieldProps) {
/>
<CopyButton label={props.copyLabel} value={props.value} />
</div>
<JiraFieldError id={`${props.id}-error`} message={error} />
<FieldError id={`${props.id}-error`} message={error} />
<p className="text-muted-foreground text-xs" id={hintId}>
{props.hint}
</p>
Expand Down
66 changes: 12 additions & 54 deletions apps/web/src/components/cases/case-delete-button.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,30 @@
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@automationstack/ui/components/alert-dialog";
import { Button } from "@automationstack/ui/components/button";
import { Trash2Icon } from "lucide-react";
import { useCallback, useState } from "react";
import { useCallback } from "react";

import { useRemoveCase } from "@/components/cases/use-case-mutations";
import { useCloseOnDismiss } from "@/components/use-close-on-dismiss";
import { InlineConfirm } from "@/components/interaction/inline-confirm";

interface CaseDeleteButtonProps {
caseId: string;
caseName: string;
onDeleted: () => void;
}

export function CaseDeleteButton({
caseId,
caseName,
onDeleted,
}: CaseDeleteButtonProps) {
const [open, setOpen] = useState(false);
const close = useCallback(() => setOpen(false), []);
const handleOpenChange = useCloseOnDismiss(close);
const askConfirm = useCallback(() => setOpen(true), []);
export function CaseDeleteButton({ caseId, onDeleted }: CaseDeleteButtonProps) {
const remove = useRemoveCase(onDeleted);
const handleConfirm = useCallback(
() => remove.mutate({ id: caseId }),
[caseId, remove]
);

return (
<>
<Button
aria-label="删除用例"
onClick={askConfirm}
size="sm"
variant="ghost"
>
<Trash2Icon data-icon="inline-start" />
删除
</Button>
<AlertDialog onOpenChange={handleOpenChange} open={open}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>删除用例「{caseName}」?</AlertDialogTitle>
<AlertDialogDescription>
该用例及其版本历史将一并删除,且不可恢复。
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>取消</AlertDialogCancel>
<AlertDialogAction
disabled={remove.isPending}
onClick={handleConfirm}
variant="destructive"
>
删除
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
<InlineConfirm
confirmLabel="确认删除"
onConfirm={handleConfirm}
pending={remove.isPending}
prompt="删除后用例和版本历史不可恢复。"
triggerAriaLabel="删除用例"
triggerIcon={<Trash2Icon data-icon="inline-start" />}
triggerLabel="删除"
/>
);
}
6 changes: 1 addition & 5 deletions apps/web/src/components/cases/case-detail-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ export function CaseDetailHeader({
保存时会基于 v{testCase.currentVersion} 做乐观锁校验。
</SheetDescription>
<div className="flex flex-wrap items-center justify-between gap-2 pt-2">
<CaseDeleteButton
caseId={testCase.id}
caseName={testCase.name}
onDeleted={onClose}
/>
<CaseDeleteButton caseId={testCase.id} onDeleted={onClose} />
<CaseDetailActions editor={editor} onStopEditing={onStopEditing} />
</div>
</SheetHeader>
Expand Down
14 changes: 4 additions & 10 deletions apps/web/src/components/cases/case-detail-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ import {
import type { ReactNode } from "react";

import { useCaseAttachmentUrls } from "@/components/cases/case-attachment-context";
import {
CASE_TYPE_LABELS,
formatDateTime,
PRIORITY_BADGE_VARIANTS,
} from "@/components/cases/case-meta";
import { CaseStatusBadge } from "@/components/cases/case-status-badge";
import { CASE_TYPE_LABELS, formatDateTime } from "@/components/cases/case-meta";
import type { MarkdownImageUrls } from "@/components/cases/markdown-inline-render";
import { MarkdownRender } from "@/components/cases/markdown-render";
import { StatusBadge } from "@/components/status/status-badge";

function DetailRow({
children,
Expand Down Expand Up @@ -77,10 +73,8 @@ export function CaseDetailView({ testCase }: { testCase: TestCase }) {
return (
<div className="flex flex-col gap-4">
<div className="flex flex-wrap items-center gap-2">
<Badge variant={PRIORITY_BADGE_VARIANTS[testCase.priority]}>
{testCase.priority}
</Badge>
<CaseStatusBadge status={testCase.status} />
<StatusBadge kind="priority" value={testCase.priority} />
<StatusBadge kind="caseStatus" value={testCase.status} />
<Badge variant="outline">{CASE_TYPE_LABELS[testCase.caseType]}</Badge>
{testCase.tags.map((tag) => (
<Badge key={tag} variant="secondary">
Expand Down
27 changes: 0 additions & 27 deletions apps/web/src/components/cases/case-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,12 @@ export interface CaseOption {
value: string;
}

export type BadgeVariant =
| "default"
| "destructive"
| "destructive-solid"
| "ghost"
| "outline"
| "secondary";

export const PRIORITY_BADGE_VARIANTS: Record<CasePriority, BadgeVariant> = {
P0: "destructive-solid",
P1: "destructive",
P2: "secondary",
P3: "ghost",
};

export const STATUS_LABELS: Record<CaseStatus, string> = {
active: "生效",
deprecated: "废弃",
draft: "草稿",
};

export const STATUS_BADGE_VARIANTS: Record<CaseStatus, BadgeVariant> = {
active: "outline",
deprecated: "outline",
draft: "outline",
};

export const STATUS_DOT_CLASSES: Record<CaseStatus, string> = {
active: "bg-success",
deprecated: "bg-muted-foreground/50",
draft: "border border-muted-foreground",
};

export const CASE_TYPE_LABELS: Record<CaseType, string> = {
compatibility: "兼容性",
functional: "功能",
Expand Down
24 changes: 0 additions & 24 deletions apps/web/src/components/cases/case-status-badge.tsx

This file was deleted.

14 changes: 4 additions & 10 deletions apps/web/src/components/cases/case-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ import {
import { cn } from "@automationstack/ui/lib/utils";

import { CaseCollaboratorsCell } from "@/components/cases/case-collaborators-cell";
import {
CASE_TYPE_LABELS,
formatDateTime,
PRIORITY_BADGE_VARIANTS,
} from "@/components/cases/case-meta";
import { CASE_TYPE_LABELS, formatDateTime } from "@/components/cases/case-meta";
import { CaseNameCell } from "@/components/cases/case-name-cell";
import { CaseStatusBadge } from "@/components/cases/case-status-badge";
import { CaseTableEmpty } from "@/components/cases/case-table-empty";
import { StatusBadge } from "@/components/status/status-badge";
import {
type CaseCollaborators,
useCollaboratorsByCaseId,
Expand Down Expand Up @@ -71,13 +67,11 @@ function CaseRow({ collaborators, selected, testCase }: CaseRowProps) {
>
<CaseNameCell testCase={testCase} />
<TableCell>
<Badge variant={PRIORITY_BADGE_VARIANTS[testCase.priority]}>
{testCase.priority}
</Badge>
<StatusBadge kind="priority" value={testCase.priority} />
</TableCell>
<TableCell>{CASE_TYPE_LABELS[testCase.caseType]}</TableCell>
<TableCell>
<CaseStatusBadge status={testCase.status} />
<StatusBadge kind="caseStatus" value={testCase.status} />
</TableCell>
<TableCell>
<CaseTags tags={testCase.tags} />
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/cases/use-case-mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function useRemoveCase(onRemoved: () => void) {

return useMutation(
orpc.cases.remove.mutationOptions({
meta: { failureAction: "删除用例" },
onSuccess: () => {
toast.success("用例已删除");
invalidateCases();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export function JiraFieldError({
/**
* 字段旁边的错误提示。字段用 aria-describedby 指向 id,
* 并在有错误时设 aria-invalid。没有错误时不渲染。
*/
export function FieldError({
id,
message,
}: {
Expand Down
Loading
Loading