* 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,140 @@
|
|||
import { describe, it, expect, vi } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import type { ResourceTemplate } from "@modelcontextprotocol/sdk/types.js";
|
||||
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
|
||||
import { ResourceTemplatePanel } from "./ResourceTemplatePanel";
|
||||
|
||||
const singleVarTemplate: ResourceTemplate = {
|
||||
name: "User Profile",
|
||||
uriTemplate: "file:///users/{userId}/profile",
|
||||
description: "Fetch a user profile.",
|
||||
};
|
||||
|
||||
const titledTemplate: ResourceTemplate = {
|
||||
name: "Table Row",
|
||||
title: "Database Row",
|
||||
uriTemplate: "db://tables/{tableName}/rows/{rowId}",
|
||||
};
|
||||
|
||||
const annotatedTemplate: ResourceTemplate = {
|
||||
name: "Dynamic",
|
||||
uriTemplate: "resource://dynamic/{id}",
|
||||
annotations: { audience: ["user"], priority: 0.8 },
|
||||
};
|
||||
|
||||
const noVarTemplate: ResourceTemplate = {
|
||||
name: "Static",
|
||||
uriTemplate: "file:///static.txt",
|
||||
};
|
||||
|
||||
describe("ResourceTemplatePanel", () => {
|
||||
it("renders the template title (or name) and description", () => {
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={singleVarTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText("User Profile Template")).toBeInTheDocument();
|
||||
expect(screen.getByText("Fetch a user profile.")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("prefers the title over the name when present", () => {
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={titledTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText("Database Row Template")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders an input per template variable", () => {
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={titledTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByLabelText("tableName")).toBeInTheDocument();
|
||||
expect(screen.getByLabelText("rowId")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("disables Read Resource until all variables are filled", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={titledTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
const button = screen.getByRole("button", { name: "Read Resource" });
|
||||
expect(button).toBeDisabled();
|
||||
await user.type(screen.getByLabelText("tableName"), "users");
|
||||
expect(button).toBeDisabled();
|
||||
await user.type(screen.getByLabelText("rowId"), "42");
|
||||
expect(button).not.toBeDisabled();
|
||||
});
|
||||
|
||||
it("invokes onReadResource with the resolved URI when submitted", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onReadResource = vi.fn();
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={singleVarTemplate}
|
||||
onReadResource={onReadResource}
|
||||
/>,
|
||||
);
|
||||
await user.type(screen.getByLabelText("userId"), "alice");
|
||||
await user.click(screen.getByRole("button", { name: "Read Resource" }));
|
||||
expect(onReadResource).toHaveBeenCalledWith("file:///users/alice/profile");
|
||||
});
|
||||
|
||||
it("updates the URI preview as variables change", async () => {
|
||||
const user = userEvent.setup();
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={singleVarTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
screen.getByText("file:///users/{userId}/profile"),
|
||||
).toBeInTheDocument();
|
||||
await user.type(screen.getByLabelText("userId"), "bob");
|
||||
expect(screen.getByText("file:///users/bob/profile")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders annotation badges when present", () => {
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={annotatedTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText("audience: user")).toBeInTheDocument();
|
||||
expect(screen.getByText("priority: high")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders without description when not provided", () => {
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={titledTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.queryByText("Fetch a user profile.")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("enables submission immediately when there are no variables", () => {
|
||||
renderWithMantine(
|
||||
<ResourceTemplatePanel
|
||||
template={noVarTemplate}
|
||||
onReadResource={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Read Resource" }),
|
||||
).not.toBeDisabled();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue