import { useTestActions } from "./useTestActions"; import type { TestRun } from "../../core/index"; import { useEffect, useState } from "react"; import { useWorkspace } from "../../workspaceStore"; import { cx } from "../../components/common"; import { Icon } from "../../components/icons"; import { Button } from "../../components/primitives"; import { AiCaseDialog } from "../../components/dialogs/AiCaseDialog"; import { ScheduleDialog } from "../../components/dialogs/ScheduleDialog"; import { CaseDetail } from "./CaseDetail"; import { installHttp8Regression } from "./regression"; import { WorkspaceSidebar } from "../../components/WorkspaceSidebar"; export function TestingView() { const testCases = useWorkspace((s) => s.testCases); const testRuns = useWorkspace((s) => s.testRuns); const schedules = useWorkspace((s) => s.schedules); const addTestCase = useWorkspace((s) => s.addTestCase); const [selected, setSelected] = useState(testCases[0]?.id ?? null); const [showAi, setShowAi] = useState(false); const [showSchedule, setShowSchedule] = useState(false); const { busy: runAllBusy, runAll } = useTestActions(); const tc = testCases.find((c) => c.id === selected) ?? null; const lastRunOf = (caseId: string): TestRun | undefined => testRuns.find((r) => r.caseId === caseId); useEffect(() => { if (!testCases.some((c) => c.id === selected)) setSelected(testCases[0]?.id ?? null); }, [testCases, selected]); return (
{/* 左栏:用例列表 */}
场景用例 {testCases.length}
示例与学习
{testCases.length === 0 && (
还没有用例
点「新建」手动编排,或用「AI 生成」
)} {testCases.map((c) => { const last = lastRunOf(c.id); const sched = schedules.find((s) => s.caseId === c.id && s.enabled); return ( ); })}
{/* 右侧:用例详情 */} {tc ? ( setShowSchedule(true)} /> ) : (
自动化测试
手动编排 · AI 生成 · 定时调度,三种方式共用同一套场景用例
左侧新建用例;侧栏底部「自动化测试」随时进出本视图
)} {showAi && setShowAi(false)} onSaved={(id) => setSelected(id)} />} {showSchedule && setShowSchedule(false)} />}
); }