test(coverage): bootstrap vitest unit infra and add tests at 90%+ per file (#1245) (#1269)

* 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:
Cliff Hall 2026-05-01 15:15:32 -04:00 • committed by GitHub
commit 75f74d64c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,146 @@
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 { PromptArgumentsForm } from "./PromptArgumentsForm";
const promptNoArgs: Prompt = {
name: "summarize",
description: "Summarize the given text into key points",
};
const promptWithArgs: Prompt = {
name: "translate",
title: "Translate Text",
description: "Translate text from one language to another",
arguments: [
{ name: "text", required: true, description: "The text to translate" },
{
name: "targetLanguage",
required: false,
description: "The language to translate into",
},
],
};
const promptNoDescription: Prompt = {
name: "code-review",
arguments: [
{ name: "code", required: true, description: "The code to review" },
],
};
describe("PromptArgumentsForm", () => {
it("renders the prompt name when title is missing", () => {
renderWithMantine(
<PromptArgumentsForm
prompt={promptNoArgs}
argumentValues={{}}
onArgumentChange={vi.fn()}
onGetPrompt={vi.fn()}
/>,
);
expect(screen.getByText("summarize")).toBeInTheDocument();
expect(
screen.getByText("Summarize the given text into key points"),
).toBeInTheDocument();
});
it("prefers the prompt title over the name", () => {
renderWithMantine(
<PromptArgumentsForm
prompt={promptWithArgs}
argumentValues={{}}
onArgumentChange={vi.fn()}
onGetPrompt={vi.fn()}
/>,
);
expect(screen.getByText("Translate Text")).toBeInTheDocument();
});
it("does not render Arguments section when prompt has no arguments", () => {
renderWithMantine(
<PromptArgumentsForm
prompt={promptNoArgs}
argumentValues={{}}
onArgumentChange={vi.fn()}
onGetPrompt={vi.fn()}
/>,
);
expect(screen.queryByText("Arguments")).not.toBeInTheDocument();
});
it("renders argument inputs and the Arguments title when arguments are present", () => {
renderWithMantine(
<PromptArgumentsForm
prompt={promptWithArgs}
argumentValues={{}}
onArgumentChange={vi.fn()}
onGetPrompt={vi.fn()}
/>,
);
expect(screen.getByText("Arguments")).toBeInTheDocument();
expect(screen.getByLabelText(/text/)).toBeInTheDocument();
expect(screen.getByLabelText(/targetLanguage/)).toBeInTheDocument();
expect(screen.getByPlaceholderText("Enter text...")).toBeInTheDocument();
expect(
screen.getByPlaceholderText("Enter targetLanguage..."),
).toBeInTheDocument();
});
it("renders pre-filled argument values", () => {
renderWithMantine(
<PromptArgumentsForm
prompt={promptWithArgs}
argumentValues={{ text: "Hello", targetLanguage: "Spanish" }}
onArgumentChange={vi.fn()}
onGetPrompt={vi.fn()}
/>,
);
expect(screen.getByDisplayValue("Hello")).toBeInTheDocument();
expect(screen.getByDisplayValue("Spanish")).toBeInTheDocument();
});
it("invokes onArgumentChange when typing in an argument input", async () => {
const user = userEvent.setup();
const onArgumentChange = vi.fn();
renderWithMantine(
<PromptArgumentsForm
prompt={promptWithArgs}
argumentValues={{}}
onArgumentChange={onArgumentChange}
onGetPrompt={vi.fn()}
/>,
);
await user.type(screen.getByPlaceholderText("Enter text..."), "h");
expect(onArgumentChange).toHaveBeenCalledWith("text", "h");
});
it("invokes onGetPrompt when Get Prompt is clicked", async () => {
const user = userEvent.setup();
const onGetPrompt = vi.fn();
renderWithMantine(
<PromptArgumentsForm
prompt={promptWithArgs}
argumentValues={{}}
onArgumentChange={vi.fn()}
onGetPrompt={onGetPrompt}
/>,
);
await user.click(screen.getByRole("button", { name: "Get Prompt" }));
expect(onGetPrompt).toHaveBeenCalledTimes(1);
});
it("renders without description when none is provided", () => {
renderWithMantine(
<PromptArgumentsForm
prompt={promptNoDescription}
argumentValues={{}}
onArgumentChange={vi.fn()}
onGetPrompt={vi.fn()}
/>,
);
expect(screen.getByText("code-review")).toBeInTheDocument();
expect(screen.getByText("Arguments")).toBeInTheDocument();
});
});