import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import { GeneratorWorkspace } from "../../src/components/GeneratorWorkspace";
describe("Sudoku generator workspace", () => {
it("offers only reliable sizes and submits an explicit local recipe", async () => {
const user = userEvent.setup();
const onGenerate = vi.fn();
render(
,
);
await user.selectOptions(screen.getByLabelText("Variant"), "anti-king");
const grid = screen.getByLabelText("Grid");
expect(
within(grid)
.getAllByRole("option")
.map((option) => option.textContent),
).toEqual(["6 × 6", "9 × 9"]);
expect(
screen.queryByLabelText("Requested markings"),
).not.toBeInTheDocument();
await user.selectOptions(screen.getByLabelText("Variant"), "thermo");
expect(screen.getByLabelText("Requested markings")).toBeInTheDocument();
await user.selectOptions(screen.getByLabelText("Grid"), "4");
await user.selectOptions(
screen.getByLabelText("Requested profile"),
"easy",
);
await user.clear(screen.getByLabelText("Seed"));
await user.type(screen.getByLabelText("Seed"), "repeatable-demo");
await user.click(screen.getByRole("button", { name: "Generate Thermo" }));
expect(onGenerate).toHaveBeenCalledWith({
variant: "thermo",
size: 4,
targetDifficulty: "easy",
symmetry: "rotational",
constraintCount: 8,
seed: "repeatable-demo",
});
});
it("exposes independent rating for the current puzzle", async () => {
const user = userEvent.setup();
const onRate = vi.fn();
render(
,
);
await user.click(
screen.getByRole("button", { name: "Rate current puzzle" }),
);
expect(onRate).toHaveBeenCalledOnce();
});
});