* 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,129 @@
|
|||
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 { PromptControls } from "./PromptControls";
|
||||
|
||||
const samplePrompts: Prompt[] = [
|
||||
{
|
||||
name: "summarize",
|
||||
description: "Summarize the given text into key points",
|
||||
},
|
||||
{
|
||||
name: "translate",
|
||||
description: "Translate text from one language to another",
|
||||
},
|
||||
{ name: "analyze", description: "Analyze sentiment and tone of the text" },
|
||||
{ name: "code-review", description: "Review code for issues" },
|
||||
{ name: "refactor" },
|
||||
];
|
||||
|
||||
const baseProps = {
|
||||
prompts: samplePrompts,
|
||||
listChanged: false,
|
||||
onRefreshList: vi.fn(),
|
||||
onSelectPrompt: vi.fn(),
|
||||
};
|
||||
|
||||
describe("PromptControls", () => {
|
||||
it("renders the title and search input", () => {
|
||||
renderWithMantine(<PromptControls {...baseProps} />);
|
||||
expect(screen.getByText("Prompts")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByPlaceholderText("Search prompts..."),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders all prompts by default", () => {
|
||||
renderWithMantine(<PromptControls {...baseProps} />);
|
||||
expect(screen.getByText("summarize")).toBeInTheDocument();
|
||||
expect(screen.getByText("translate")).toBeInTheDocument();
|
||||
expect(screen.getByText("analyze")).toBeInTheDocument();
|
||||
expect(screen.getByText("code-review")).toBeInTheDocument();
|
||||
expect(screen.getByText("refactor")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("filters prompts by name when typing in the search input", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<PromptControls {...baseProps} />);
|
||||
await user.type(screen.getByPlaceholderText("Search prompts..."), "trans");
|
||||
expect(screen.getByText("translate")).toBeInTheDocument();
|
||||
expect(screen.queryByText("summarize")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("refactor")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("filters prompts by description when typing in the search input", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(<PromptControls {...baseProps} />);
|
||||
await user.type(
|
||||
screen.getByPlaceholderText("Search prompts..."),
|
||||
"sentiment",
|
||||
);
|
||||
expect(screen.getByText("analyze")).toBeInTheDocument();
|
||||
expect(screen.queryByText("summarize")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("filters prompts by title when present", async () => {
|
||||
const user = userEvent.setup();
|
||||
const promptsWithTitle: Prompt[] = [
|
||||
{ name: "p1", title: "Alpha Title" },
|
||||
{ name: "p2", title: "Beta Title" },
|
||||
];
|
||||
renderWithMantine(
|
||||
<PromptControls {...baseProps} prompts={promptsWithTitle} />,
|
||||
);
|
||||
await user.type(screen.getByPlaceholderText("Search prompts..."), "alpha");
|
||||
expect(screen.getByText("Alpha Title")).toBeInTheDocument();
|
||||
expect(screen.queryByText("Beta Title")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("invokes onSelectPrompt when an unselected prompt is clicked", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onSelectPrompt = vi.fn();
|
||||
renderWithMantine(
|
||||
<PromptControls {...baseProps} onSelectPrompt={onSelectPrompt} />,
|
||||
);
|
||||
await user.click(screen.getByText("translate"));
|
||||
expect(onSelectPrompt).toHaveBeenCalledWith("translate");
|
||||
});
|
||||
|
||||
it("does not invoke onSelectPrompt when the already-selected prompt is clicked", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onSelectPrompt = vi.fn();
|
||||
renderWithMantine(
|
||||
<PromptControls
|
||||
{...baseProps}
|
||||
selectedName="translate"
|
||||
onSelectPrompt={onSelectPrompt}
|
||||
/>,
|
||||
);
|
||||
await user.click(screen.getByText("translate"));
|
||||
expect(onSelectPrompt).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not show the list-changed indicator when listChanged is false", () => {
|
||||
renderWithMantine(<PromptControls {...baseProps} />);
|
||||
expect(screen.queryByText("List updated")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the list-changed indicator when listChanged is true and invokes onRefreshList", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onRefreshList = vi.fn();
|
||||
renderWithMantine(
|
||||
<PromptControls
|
||||
{...baseProps}
|
||||
listChanged
|
||||
onRefreshList={onRefreshList}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText("List updated")).toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Refresh" }));
|
||||
expect(onRefreshList).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("renders empty list when no prompts", () => {
|
||||
renderWithMantine(<PromptControls {...baseProps} prompts={[]} />);
|
||||
expect(screen.getByText("Prompts")).toBeInTheDocument();
|
||||
expect(screen.queryByText("translate")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue