mirror of
https://github.com/willchen96/mike.git
synced 2026-07-24 23:41:04 +02:00
Ported from the amal66 fork (index: Open-Legal-Products/mike#205), adapted to this repo's frontend/ layout and current component behavior. Adds the jsdom + testing-library harness on top of the existing vitest setup: vitest.config.mts (jsdom environment, @/ alias mirroring tsconfig paths, dummy Supabase env for modules that build a client at import time) and vitest.setup.ts (jest-dom matchers). New devDependencies: jsdom, @testing-library/react, @testing-library/jest-dom, @testing-library/user-event, @vitejs/plugin-react. Ported suites (30 new tests): - FileTypeIcon.test.tsx (11) — fileTypeKind mapping + icon rendering - TRTable.test.tsx (1) — header/row render smoke test; the fork's ARIA role assertions (table/columnheader, "Tabular review" label) target fork-only markup — this repo's grid is div-based, so the test asserts rendered content instead - button.test.tsx (4), pill-button.test.tsx (8), cite-button.test.tsx (3) - useSmoothedReveal.test.ts (3) — passes against this repo's early-return snap behavior unchanged Dropped (subjects don't exist here): - HistoryDropdown.test.tsx — no tr-chat-panel/HistoryDropdown component - applyAssistantStreamEvent.test.ts — no such module - useProjectsQuery/useTabularReviewsQuery/useWorkflowsQuery tests — react-query is fork-only - lib/toast.test.ts — no frontend/src/lib/toast.ts - useAssistantChat.parsers.test.ts — the parser helpers exist inside useAssistantChat.ts but are not exported, and the fork's extracted module doesn't exist here Verified: frontend npm test 38/38 passing (30 new + 8 pre-existing cn() utils tests); npx tsc --noEmit clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { Button } from "./button";
|
|
|
|
describe("Button", () => {
|
|
it("renders its children", () => {
|
|
render(<Button>Click me</Button>);
|
|
expect(
|
|
screen.getByRole("button", { name: "Click me" }),
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it("fires onClick when activated", async () => {
|
|
const onClick = vi.fn();
|
|
const user = userEvent.setup();
|
|
render(<Button onClick={onClick}>Submit</Button>);
|
|
|
|
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
|
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("applies the variant class for destructive buttons", () => {
|
|
render(<Button variant="destructive">Delete</Button>);
|
|
expect(screen.getByRole("button", { name: "Delete" })).toHaveClass(
|
|
"bg-destructive",
|
|
);
|
|
});
|
|
|
|
it("does not fire onClick while disabled", async () => {
|
|
const onClick = vi.fn();
|
|
const user = userEvent.setup();
|
|
render(
|
|
<Button disabled onClick={onClick}>
|
|
Disabled
|
|
</Button>,
|
|
);
|
|
|
|
await user.click(screen.getByRole("button", { name: "Disabled" }));
|
|
|
|
expect(onClick).not.toHaveBeenCalled();
|
|
});
|
|
});
|