Files
initiative/apps/web/src/components/__tests__/roll-mode-menu.test.tsx
Lukas a77db0eeee Add quick-win tests for components and hooks
Adds tests for DifficultyIndicator, Toast, RollModeMenu, OverflowMenu,
useTheme, and useRulesEdition. Covers rendering, user interactions,
auto-dismiss timers, external store sync, and localStorage persistence.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 19:32:15 +01:00

56 lines
1.4 KiB
TypeScript

// @vitest-environment jsdom
import { cleanup, render, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { afterEach, describe, expect, it, vi } from "vitest";
import { RollModeMenu } from "../roll-mode-menu.js";
afterEach(cleanup);
describe("RollModeMenu", () => {
it("renders advantage and disadvantage buttons", () => {
render(
<RollModeMenu
position={{ x: 100, y: 100 }}
onSelect={() => {}}
onClose={() => {}}
/>,
);
expect(screen.getByText("Advantage")).toBeDefined();
expect(screen.getByText("Disadvantage")).toBeDefined();
});
it("calls onSelect with 'advantage' and onClose when clicked", async () => {
const onSelect = vi.fn();
const onClose = vi.fn();
render(
<RollModeMenu
position={{ x: 100, y: 100 }}
onSelect={onSelect}
onClose={onClose}
/>,
);
await userEvent.click(screen.getByText("Advantage"));
expect(onSelect).toHaveBeenCalledWith("advantage");
expect(onClose).toHaveBeenCalled();
});
it("calls onSelect with 'disadvantage' and onClose when clicked", async () => {
const onSelect = vi.fn();
const onClose = vi.fn();
render(
<RollModeMenu
position={{ x: 100, y: 100 }}
onSelect={onSelect}
onClose={onClose}
/>,
);
await userEvent.click(screen.getByText("Disadvantage"));
expect(onSelect).toHaveBeenCalledWith("disadvantage");
expect(onClose).toHaveBeenCalled();
});
});