fix(home): Back keeps the question, and the focus finds its card by name
Opening a card left Home, and Back came back to "Doesn't matter" with a different hero, whose card then dropped out of the Continue rail and moved the keyboard onto its neighbour. The budget, reroll seed and seen list live on the history entry now, and a returning list focuses the item by its name before its place.
This commit is contained in:
@@ -163,6 +163,8 @@ function mountWithClient() {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
// Home keeps its question on the history entry (Back restores it): each test starts a fresh one.
|
||||
window.history.replaceState(null, "");
|
||||
discover.mockReset();
|
||||
discoverPick.mockReset();
|
||||
setPage.mockReset();
|
||||
@@ -553,11 +555,35 @@ describe("Home", () => {
|
||||
|
||||
first.unmount();
|
||||
discoverPick.mockClear();
|
||||
// A later visit is a new history entry (setPage pushes a fresh one); the same entry would bring
|
||||
// the rerolled question back on purpose (see the Back test below).
|
||||
window.history.pushState(null, "");
|
||||
mount();
|
||||
await screen.findByText("Hero v1");
|
||||
expect(discoverPick).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Prod UAT 2026-09-19: a card opened from Home leaves the page, and Back came back to "Doesn't
|
||||
// matter" and a different hero. The question is kept on the entry, so Back asks it again.
|
||||
it("Back to the same entry brings back the budget and the rerolled hero", async () => {
|
||||
discoverPick.mockResolvedValue({
|
||||
budget: "short",
|
||||
hero: { tier: "surprise", card: ytCard("v9", "Rerolled") },
|
||||
});
|
||||
const first = mount();
|
||||
await screen.findByText("Hero v1");
|
||||
fireEvent.click(screen.getByText("home.budget.short"));
|
||||
fireEvent.click(screen.getByText("home.hero.reroll"));
|
||||
expect(await screen.findByText("Rerolled")).toBeTruthy();
|
||||
first.unmount();
|
||||
|
||||
discover.mockClear();
|
||||
mount();
|
||||
|
||||
expect(await screen.findByText("Rerolled")).toBeTruthy();
|
||||
expect(discover).toHaveBeenLastCalledWith("short", 0);
|
||||
});
|
||||
|
||||
// Measured in the browser (2026-09-07), before the fix: the palette's "Meglepetés" arrived at Home
|
||||
// as `start=2` — two picks deep before the page had painted once — because StrictMode invokes a
|
||||
// mount effect twice with the same render snapshot, and a reroll is not idempotent. The token is
|
||||
|
||||
Reference in New Issue
Block a user