inspector/clients/web/src/components/groups/historyUtils.test.ts
Cliff Hall 75f74d64c1
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>
2026-05-01 15:15:32 -04:00

60 lines
1.6 KiB
TypeScript

import { describe, it, expect } from "vitest";
import type { MessageEntry } from "@inspector/core/mcp/types.js";
import { extractMethod } from "./historyUtils";
describe("extractMethod", () => {
it("returns the method name for a request entry", () => {
const entry: MessageEntry = {
id: "1",
timestamp: new Date(),
direction: "request",
message: {
jsonrpc: "2.0",
id: 1,
method: "tools/list",
},
};
expect(extractMethod(entry)).toBe("tools/list");
});
it("returns the method name for a notification entry", () => {
const entry: MessageEntry = {
id: "2",
timestamp: new Date(),
direction: "notification",
message: {
jsonrpc: "2.0",
method: "notifications/initialized",
},
};
expect(extractMethod(entry)).toBe("notifications/initialized");
});
it("returns 'response' for a result-response entry without a method", () => {
const entry: MessageEntry = {
id: "3",
timestamp: new Date(),
direction: "response",
message: {
jsonrpc: "2.0",
id: 1,
result: { tools: [] },
},
};
expect(extractMethod(entry)).toBe("response");
});
it("returns 'response' for an error-response entry without a method", () => {
const entry: MessageEntry = {
id: "4",
timestamp: new Date(),
direction: "response",
message: {
jsonrpc: "2.0",
id: 1,
error: { code: -32600, message: "Invalid Request" },
},
};
expect(extractMethod(entry)).toBe("response");
});
});