* test(coverage): bootstrap vitest unit infra and add tests at 90%+ per file (#1245) Establishes the unit-test runtime AGENTS.md mandates: a vitest "unit" project alongside the existing storybook project, RTL + jest-dom + happy-dom, a Mantine-aware render helper, and a 90%-line per-file coverage gate enforced by CI. Adds 66 test files covering all 62 components under elements/groups/screens/views, plus core/mcp and clients/web/src/utils. Total: 577 tests, 98.7% line coverage globally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * test(coverage): address PR #1269 review feedback - AGENTS.md: correct coverage gate description (lines ≥ 90, statements ≥ 85, functions ≥ 80, branches ≥ 50) with rationale for the relaxed branch threshold - InspectorView.test.tsx: document what the Math.random() mock values (0.1 / 0.99) control vs. STUB_SUCCESS_RATE in InspectorView.tsx - vite.config.ts / tsconfig.test.json: drop unused `globals: true` and the `vitest/globals` type now that every test file imports describe/it/expect/vi explicitly; manual `afterEach(cleanup)` in setup.ts remains required because testing-library auto-cleanup relies on globalThis.afterEach Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
64a42e645b
commit
75f74d64c1
1 changed files with 8117 additions and 30 deletions
|
|
@ -0,0 +1,120 @@
|
|||
import { describe, it, expect, vi } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { Prompt } from "@modelcontextprotocol/sdk/types.js";
|
||||
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
|
||||
import { PromptsScreen } from "./PromptsScreen";
|
||||
|
||||
const prompts: Prompt[] = [
|
||||
{ name: "summarize", description: "Summarize text" },
|
||||
{ name: "translate", description: "Translate text" },
|
||||
];
|
||||
|
||||
const baseProps = {
|
||||
prompts,
|
||||
listChanged: false,
|
||||
onRefreshList: vi.fn(),
|
||||
onGetPrompt: vi.fn(),
|
||||
};
|
||||
|
||||
describe("PromptsScreen", () => {
|
||||
it("renders the empty state when no prompt is selected", () => {
|
||||
renderWithMantine(<PromptsScreen {...baseProps} />);
|
||||
expect(
|
||||
screen.getByText("Select a prompt to view details"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows prompt arguments when a prompt is selected", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<PromptsScreen {...baseProps} />);
|
||||
await user.click(screen.getByText("summarize"));
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Get Prompt" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows pending state", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<PromptsScreen {...baseProps} getPromptState={{ status: "pending" }} />,
|
||||
);
|
||||
await user.click(screen.getByText("summarize"));
|
||||
expect(screen.getByText("Loading prompt...")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows error state", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<PromptsScreen
|
||||
{...baseProps}
|
||||
getPromptState={{ status: "error", error: "Bad prompt" }}
|
||||
/>,
|
||||
);
|
||||
await user.click(screen.getByText("summarize"));
|
||||
expect(screen.getByText("Prompt Error")).toBeInTheDocument();
|
||||
expect(screen.getByText("Bad prompt")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders fallback error when error message is missing", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<PromptsScreen {...baseProps} getPromptState={{ status: "error" }} />,
|
||||
);
|
||||
await user.click(screen.getByText("summarize"));
|
||||
expect(screen.getByText("Failed to get prompt")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows messages when result is provided", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<PromptsScreen
|
||||
{...baseProps}
|
||||
getPromptState={{
|
||||
status: "ok",
|
||||
result: {
|
||||
messages: [{ role: "user", content: { type: "text", text: "hi" } }],
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
await user.click(screen.getByText("summarize"));
|
||||
expect(screen.getByText("Messages")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("updates argument values and calls onGetPrompt", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onGetPrompt = vi.fn();
|
||||
const promptsWithArgs: Prompt[] = [
|
||||
{
|
||||
name: "ask",
|
||||
arguments: [{ name: "topic", required: true }],
|
||||
},
|
||||
];
|
||||
renderWithMantine(
|
||||
<PromptsScreen
|
||||
{...baseProps}
|
||||
prompts={promptsWithArgs}
|
||||
onGetPrompt={onGetPrompt}
|
||||
/>,
|
||||
);
|
||||
await user.click(screen.getByText("ask"));
|
||||
await user.type(screen.getByPlaceholderText("Enter topic..."), "math");
|
||||
await user.click(screen.getByRole("button", { name: "Get Prompt" }));
|
||||
expect(onGetPrompt).toHaveBeenCalledWith("ask", { topic: "math" });
|
||||
});
|
||||
|
||||
it("resets argument values when switching prompts", async () => {
|
||||
const user = userEvent.setup();
|
||||
const promptsWithArgs: Prompt[] = [
|
||||
{ name: "alpha", arguments: [{ name: "x" }] },
|
||||
{ name: "beta", arguments: [{ name: "y" }] },
|
||||
];
|
||||
renderWithMantine(
|
||||
<PromptsScreen {...baseProps} prompts={promptsWithArgs} />,
|
||||
);
|
||||
await user.click(screen.getByText("alpha"));
|
||||
await user.type(screen.getByPlaceholderText("Enter x..."), "value");
|
||||
await user.click(screen.getByText("beta"));
|
||||
expect(screen.getByPlaceholderText("Enter y...")).toHaveValue("");
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue