feat: expand sudoku analysis and interoperability
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { Workbench } from "../../src/components/Workbench";
|
||||
|
||||
class WorkerStub {
|
||||
addEventListener() {}
|
||||
postMessage() {}
|
||||
terminate() {}
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
vi.stubGlobal("Worker", WorkerStub);
|
||||
});
|
||||
|
||||
function digitButton(name: string) {
|
||||
return within(screen.getByRole("group", { name: "Digits" })).getByRole(
|
||||
"button",
|
||||
{ name },
|
||||
);
|
||||
}
|
||||
|
||||
describe("gameplay history integration", () => {
|
||||
it("restores savepoints and preserves discarded hypotheses for replay", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Workbench />);
|
||||
|
||||
fireEvent.pointerDown(
|
||||
screen.getByRole("gridcell", {
|
||||
name: "Row 1, column 3, empty",
|
||||
}),
|
||||
{ buttons: 1 },
|
||||
);
|
||||
await user.click(digitButton("2"));
|
||||
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "History & branches" }),
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("heading", {
|
||||
name: "Branches, savepoints and replay",
|
||||
}),
|
||||
).toBeInTheDocument();
|
||||
await user.type(screen.getByLabelText("Savepoint name"), "After two");
|
||||
await user.click(screen.getByRole("button", { name: "Save current grid" }));
|
||||
expect(screen.getByText("After two")).toBeInTheDocument();
|
||||
await user.click(screen.getByRole("button", { name: "Close" }));
|
||||
|
||||
await user.click(digitButton("3"));
|
||||
expect(
|
||||
screen.getByRole("gridcell", { name: "Row 1, column 3, 3" }),
|
||||
).toBeInTheDocument();
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "History & branches" }),
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "Restore" }));
|
||||
expect(
|
||||
screen.getByRole("gridcell", { name: "Row 1, column 3, 2" }),
|
||||
).toBeInTheDocument();
|
||||
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "History & branches" }),
|
||||
);
|
||||
await user.type(screen.getByLabelText("Hypothesis name"), "Try three");
|
||||
await user.click(screen.getByRole("button", { name: "Start hypothesis" }));
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Hypothesis: Try three" }),
|
||||
).toBeInTheDocument();
|
||||
await user.click(digitButton("3"));
|
||||
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "Hypothesis: Try three" }),
|
||||
);
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "Discard and return" }),
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("gridcell", { name: "Row 1, column 3, 2" }),
|
||||
).toBeInTheDocument();
|
||||
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "History & branches" }),
|
||||
);
|
||||
expect(screen.getByText("discarded")).toBeInTheDocument();
|
||||
await user.click(
|
||||
within(screen.getByRole("list", { name: "Solve history" })).getAllByRole(
|
||||
"button",
|
||||
{ name: /Set r1c3 to 3/u },
|
||||
)[0]!,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("heading", { name: "Set r1c3 to 3" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("gridcell", { name: "Row 1, column 3, 3" }),
|
||||
).toBeInTheDocument();
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "Return to live grid" }),
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("gridcell", { name: "Row 1, column 3, 2" }),
|
||||
).toBeInTheDocument();
|
||||
}, 15_000);
|
||||
});
|
||||
Reference in New Issue
Block a user