fix(ui): no-op when re-selecting the turn already on screen
Tests · UI / test (push) Waiting to run
Tests · UI / test (pull_request) Successful in 3m35s

Clicking the current-turn row in the header turn navigator while
already viewing it routed through returnToCurrent() →
viewTurn(currentTurn), which re-fetches the live report and flips the
view through `loading`. At turn 0 the only row is the live turn, so
the dropdown always fired a pointless backend round-trip and redraw.

Guard goToTurn() against re-selecting the on-screen turn
(turn === viewedTurn): just close the popover and stop. Leaving
history is unaffected — there the viewed turn differs from the target.

Closes #45

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Ilia Denisov
2026-05-26 00:18:30 +02:00
parent b957d17022
commit e82c9f8bbd
3 changed files with 53 additions and 3 deletions
+36
View File
@@ -165,4 +165,40 @@ describe("TurnNavigator", () => {
expect(returnToCurrent).toHaveBeenCalledTimes(1);
expect(viewTurn).not.toHaveBeenCalled();
});
test("selecting the live row at turn 0 is a no-op (no fetch, no redraw)", async () => {
const store = buildStore({ currentTurn: 0, viewedTurn: 0 });
const viewTurn = vi
.spyOn(store, "viewTurn")
.mockResolvedValue(undefined);
const returnToCurrent = vi
.spyOn(store, "returnToCurrent")
.mockResolvedValue(undefined);
const ui = render(TurnNavigator, {
context: new Map([[GAME_STATE_CONTEXT_KEY, store]]),
});
await fireEvent.click(ui.getByTestId("turn-navigator-trigger"));
await fireEvent.click(ui.getByTestId("turn-navigator-item-0"));
expect(viewTurn).not.toHaveBeenCalled();
expect(returnToCurrent).not.toHaveBeenCalled();
// The click still dismisses the popover.
expect(ui.queryByTestId("turn-navigator-list")).not.toBeInTheDocument();
});
test("re-selecting the row already viewed in history is a no-op", async () => {
const store = buildStore({ currentTurn: 3, viewedTurn: 2 });
const viewTurn = vi
.spyOn(store, "viewTurn")
.mockResolvedValue(undefined);
const returnToCurrent = vi
.spyOn(store, "returnToCurrent")
.mockResolvedValue(undefined);
const ui = render(TurnNavigator, {
context: new Map([[GAME_STATE_CONTEXT_KEY, store]]),
});
await fireEvent.click(ui.getByTestId("turn-navigator-trigger"));
await fireEvent.click(ui.getByTestId("turn-navigator-item-2"));
expect(viewTurn).not.toHaveBeenCalled();
expect(returnToCurrent).not.toHaveBeenCalled();
});
});