Add missing component and hook tests, raise coverage thresholds

13 new test files for untested components (color-palette, player-management,
stat-block, settings-modal, export/import dialogs, bulk-import-prompt,
source-fetch-prompt, player-character-section) and hooks (use-long-press,
use-swipe-to-dismiss, use-bulk-import, use-initiative-rolls). Expand
combatant-row tests with inline editing, HP popover, and condition picker.

Component coverage: 59% → 80% lines, 55% → 71% branches
Hook coverage: 72% → 83% lines, 55% → 66% branches

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-29 23:55:21 +02:00
parent 08b5db81ad
commit b229a0dac7
15 changed files with 1802 additions and 4 deletions

View File

@@ -0,0 +1,86 @@
// @vitest-environment jsdom
import "@testing-library/jest-dom/vitest";
import { cleanup, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { polyfillDialog } from "../../__tests__/polyfill-dialog.js";
import { ExportMethodDialog } from "../export-method-dialog.js";
afterEach(cleanup);
beforeAll(() => {
polyfillDialog();
});
function renderDialog(open = true) {
const onDownload = vi.fn();
const onCopyToClipboard = vi.fn();
const onClose = vi.fn();
const result = render(
<ExportMethodDialog
open={open}
onDownload={onDownload}
onCopyToClipboard={onCopyToClipboard}
onClose={onClose}
/>,
);
return { ...result, onDownload, onCopyToClipboard, onClose };
}
describe("ExportMethodDialog", () => {
it("renders filename input and unchecked history checkbox", () => {
renderDialog();
expect(
screen.getByPlaceholderText("Filename (optional)"),
).toBeInTheDocument();
const checkbox = screen.getByRole("checkbox");
expect(checkbox).not.toBeChecked();
});
it("download button calls onDownload with defaults", async () => {
const user = userEvent.setup();
const { onDownload } = renderDialog();
await user.click(screen.getByText("Download file"));
expect(onDownload).toHaveBeenCalledWith(false, "");
});
it("download with filename and history checked", async () => {
const user = userEvent.setup();
const { onDownload } = renderDialog();
await user.type(
screen.getByPlaceholderText("Filename (optional)"),
"my-encounter",
);
await user.click(screen.getByRole("checkbox"));
await user.click(screen.getByText("Download file"));
expect(onDownload).toHaveBeenCalledWith(true, "my-encounter");
});
it("copy to clipboard calls onCopyToClipboard and shows Copied", async () => {
const user = userEvent.setup();
const { onCopyToClipboard } = renderDialog();
await user.click(screen.getByText("Copy to clipboard"));
expect(onCopyToClipboard).toHaveBeenCalledWith(false);
expect(screen.getByText("Copied!")).toBeInTheDocument();
});
it("Copied! reverts after 2 seconds", async () => {
const user = userEvent.setup();
renderDialog();
await user.click(screen.getByText("Copy to clipboard"));
expect(screen.getByText("Copied!")).toBeInTheDocument();
await waitFor(
() => {
expect(screen.queryByText("Copied!")).not.toBeInTheDocument();
},
{ timeout: 3000 },
);
expect(screen.getByText("Copy to clipboard")).toBeInTheDocument();
});
});