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>
This commit is contained in:
Lukas
2026-03-28 19:28:58 +01:00
parent d8c8a0c44d
commit a77db0eeee
7 changed files with 385 additions and 6 deletions

View File

@@ -0,0 +1,55 @@
// @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();
});
});