* 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,100 @@
|
|||
import { describe, it, expect, vi } from "vitest";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { renderWithMantine, screen } from "../../../test/renderWithMantine";
|
||||
import { LoggingScreen } from "./LoggingScreen";
|
||||
|
||||
const baseProps = {
|
||||
entries: [],
|
||||
currentLevel: "info" as const,
|
||||
onSetLevel: vi.fn(),
|
||||
onClear: vi.fn(),
|
||||
onExport: vi.fn(),
|
||||
autoScroll: true,
|
||||
onToggleAutoScroll: vi.fn(),
|
||||
onCopyAll: vi.fn(),
|
||||
};
|
||||
|
||||
describe("LoggingScreen", () => {
|
||||
it("renders the log stream panel", () => {
|
||||
renderWithMantine(<LoggingScreen {...baseProps} />);
|
||||
expect(screen.getByText("Log Stream")).toBeInTheDocument();
|
||||
expect(screen.getByText("No log entries")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders log entries", () => {
|
||||
const entries = [
|
||||
{
|
||||
receivedAt: new Date(),
|
||||
params: { level: "info" as const, data: "hello" },
|
||||
},
|
||||
];
|
||||
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
|
||||
expect(screen.getByText("hello")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("invokes onClear when clear is clicked", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClear = vi.fn();
|
||||
renderWithMantine(<LoggingScreen {...baseProps} onClear={onClear} />);
|
||||
await user.click(screen.getByRole("button", { name: "Clear" }));
|
||||
expect(onClear).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("invokes onCopyAll when Copy All is clicked", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onCopyAll = vi.fn();
|
||||
renderWithMantine(<LoggingScreen {...baseProps} onCopyAll={onCopyAll} />);
|
||||
await user.click(screen.getByRole("button", { name: "Copy All" }));
|
||||
expect(onCopyAll).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("toggles a single level on level button click", async () => {
|
||||
const user = userEvent.setup();
|
||||
const entries = [
|
||||
{ receivedAt: new Date(), params: { level: "info" as const, data: "x" } },
|
||||
];
|
||||
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
|
||||
expect(screen.getByText("x")).toBeInTheDocument();
|
||||
const debugButton = screen.getByRole("button", { name: "info" });
|
||||
await user.click(debugButton);
|
||||
expect(screen.queryByText("x")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("Deselect All hides all entries; Select All restores them", async () => {
|
||||
const user = userEvent.setup();
|
||||
const entries = [
|
||||
{ receivedAt: new Date(), params: { level: "info" as const, data: "x" } },
|
||||
];
|
||||
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
|
||||
await user.click(screen.getByRole("button", { name: "Deselect All" }));
|
||||
expect(screen.queryByText("x")).not.toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Select All" }));
|
||||
expect(screen.getByText("x")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("filters log text via the search input", async () => {
|
||||
const user = userEvent.setup();
|
||||
const entries = [
|
||||
{
|
||||
receivedAt: new Date(),
|
||||
params: { level: "info" as const, data: "alpha" },
|
||||
},
|
||||
{
|
||||
receivedAt: new Date(),
|
||||
params: { level: "info" as const, data: "beta" },
|
||||
},
|
||||
];
|
||||
renderWithMantine(<LoggingScreen {...baseProps} entries={entries} />);
|
||||
await user.type(screen.getByPlaceholderText("Search..."), "alpha");
|
||||
expect(screen.getByText("alpha")).toBeInTheDocument();
|
||||
expect(screen.queryByText("beta")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("invokes onSetLevel via the Set button", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onSetLevel = vi.fn();
|
||||
renderWithMantine(<LoggingScreen {...baseProps} onSetLevel={onSetLevel} />);
|
||||
await user.click(screen.getByRole("button", { name: "Set" }));
|
||||
expect(onSetLevel).toHaveBeenCalledWith("info");
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue