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(); }); it("submits a bounded evidence-backed practice target", async () => { const user = userEvent.setup(); const onGenerate = vi.fn(); render( , ); await user.selectOptions( screen.getByLabelText("Practice technique"), "x-wing", ); const attempts = screen.getByLabelText("Mining attempts"); await user.clear(attempts); await user.type(attempts, "7"); await user.clear(screen.getByLabelText("Seed")); await user.type(screen.getByLabelText("Seed"), "x-wing-training"); await user.click(screen.getByRole("button", { name: "Generate Classic" })); expect(onGenerate).toHaveBeenCalledWith( expect.objectContaining({ requiredTechnique: "x-wing", maxTechniqueAttempts: 7, seed: "x-wing-training", }), ); await user.selectOptions(screen.getByLabelText("Variant"), "killer"); expect( within(screen.getByLabelText("Practice technique")).getByRole("option", { name: "Killer Cage", }), ).toBeInTheDocument(); }); });