Files
scrabble-game/ui/e2e/gamelimit.spec.ts
T
Ilia Denisov 3306a016a0
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 12s
CI / integration (pull_request) Successful in 28s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m46s
feat(ui): per-kind active-game limit lock on the New Game screen
Carry the caller's per-tier active-game caps and each game's kind on the
wire (Profile.game_limits + GameView.kind, additive FBS + gateway transcode
+ client codec, committed regen). The New Game screen counts the player's
active games per kind from the lobby and locks a capped start: an outline
button with a lock that opens a funnel modal instead of a game -- a sign-in
prompt for a guest, a "finish a current game first" notice for a signed-in
account (native Telegram popup, in-app modal elsewhere). The lock lifts via
the existing profile refetch after a guest->durable upgrade.

Remove the lobby's old at_game_limit New-Game tab disable + notice: the flag
(now the random-kind cap) conflicted with the per-kind lock -- it hid the
screen where the lock lives and wrongly blocked an unfulfilled kind. The New
Game tab is always enabled; the per-kind start lock is the only gate. The
at_game_limit wire field stays (unused by the client) for a later cleanup.

Tests: client lock logic + codec kind/game_limits roundtrip + gateway
transcode encode + native popup builders (unit); a mock e2e for the lock
badge and the modal.
2026-07-10 10:09:45 +02:00

41 lines
2.0 KiB
TypeScript

import { expect, test } from './fixtures';
// The active-game limit lock on the New Game screen. When a start's kind is at the caller's per-kind
// cap (Profile.game_limits), the start button shows a 🔒 and opens a funnel modal instead of a game;
// when the cap lifts (the profile refetch a guest→durable upgrade would trigger), the lock clears and
// the button starts a game again. Driven by the mock's __mock.setGameLimits seam (no backend). The
// native Telegram popup path is verified on the contour; here the cross-platform in-app modal shows
// (the mock profile is a durable account, so it is the "finish a current game first" notice).
type Limits = { vsAi: number; random: number; friends: number };
function setLimits(l: Limits) {
(window as unknown as { __mock: { setGameLimits(l: Limits): void } }).__mock.setGameLimits(l);
}
test('new game: a start locks at its per-kind cap and the funnel modal opens', async ({ page }) => {
await page.goto('/');
await page.getByRole('button', { name: /guest/i }).click();
// The New Game button always opens the screen now — the per-kind lock lives on the start button.
await page.getByRole('button', { name: /🎲/ }).click();
const start = page.getByRole('button', { name: /start game/i });
await expect(start).not.toContainText('🔒');
// Cap every kind: the AI start (the default opponent) locks.
await page.evaluate(setLimits, { vsAi: 0, random: 0, friends: 0 });
await expect(start).toContainText('🔒');
// Tapping the locked start opens the modal instead of a game, and does not navigate away.
await start.click();
const notice = page.getByText(/reached the limit of simultaneous games/i);
await expect(notice).toBeVisible();
await expect(page).toHaveURL(/\/new$/);
await page.getByRole('button', { name: /^ok$/i }).click();
await expect(notice).toHaveCount(0);
// Lift the cap (the same profile-refetch path a registration takes): the lock clears.
await page.evaluate(setLimits, { vsAi: 10, random: 10, friends: 10 });
await expect(start).not.toContainText('🔒');
});