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>
87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
// @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();
|
|
});
|
|
});
|