Files
scrabble-game/ui/e2e/social.spec.ts
T
Ilia Denisov acbb2d8254
Tests · Go / test (push) Successful in 7s
Tests · Integration / integration (push) Successful in 11s
Tests · UI / test (push) Successful in 17s
Stage 8 polish: profile validation, finished-game UI, badge + Safari fixes
Owner-review follow-up on the Stage 8 branch:
- Friend code is copyable (📋 + toast). The lobby notification badge is fixed —
  it had inherited the hamburger-bar style — into a proper round count dot.
- Safari: min-width:0 on flex text inputs (friend code, profile, chat) so they
  shrink instead of pushing the adjacent button off-screen.
- Profile editing is validated on both the UI and the backend: display-name format
  (letters joined by single space/./_ separators, no leading/trailing/adjacent
  separators, <=32 runes), a UTC-offset timezone picker (account.ResolveZone parses
  ±HH:MM or a legacy IANA name), a 10-minute away grid capped at 12h (wrap-aware),
  and email format; Save is disabled and invalid fields red-bordered until valid.
  Language stays in Settings.
- In a game, an "add to friends" menu item flips to a disabled "request sent"; chat
  send/nudge became ⬆️/🛎️ icon buttons.
- A finished game drops its last-word highlight, hides Check word / Drop game,
  disables zoom, and draws an inert (greyed) footer instead of hiding it.

Tests: account validators (name/away/zone), UI profileValidation, e2e for the
finished-game footer/menu and the copy control. Docs (PLAN, ARCHITECTURE,
FUNCTIONAL +ru, UI_DESIGN) updated for the display-name rule, UTC-offset timezone
and the 12h away window.
2026-06-03 22:12:59 +02:00

89 lines
4.0 KiB
TypeScript

import { expect, test, type Page } from '@playwright/test';
// Stage 8 social / account / history surfaces against the mock transport (no backend).
// The mock profile is a durable account, so friends, invitations, stats and the GCG
// export are reachable from the seeded fixture.
async function loginLobby(page: Page): Promise<void> {
await page.goto('/');
await page.getByRole('button', { name: /guest/i }).click();
await expect(page.getByText('Active games')).toBeVisible();
}
async function openFriends(page: Page): Promise<void> {
await page.locator('.burger').first().click();
await page.getByRole('button', { name: /Friends/ }).click();
}
test('friends: issue a code, accept an incoming request, redeem a code', async ({ page }) => {
await loginLobby(page);
await openFriends(page);
// Issue a one-time code — it is shown to share, with a copy control.
await page.getByRole('button', { name: /Show my code/i }).click();
await expect(page.getByTestId('friend-code')).toContainText('246813');
await expect(page.getByRole('button', { name: 'Copy' })).toBeVisible();
// The seeded incoming request (Rick) can be accepted; the requests section clears.
await expect(page.getByText('Friend requests')).toBeVisible();
await page.getByRole('button', { name: /^Accept$/ }).click();
await expect(page.getByText('Friend requests')).toBeHidden();
// Redeeming a code adds a new friend to the list.
await page.locator('.codein').fill('111111');
await page.getByRole('button', { name: /^Add$/ }).click();
await expect(page.locator('.who', { hasText: 'Friend 111111' })).toBeVisible();
});
test('invitations: the lobby shows an invitation and accepting clears it', async ({ page }) => {
await loginLobby(page);
await expect(page.getByText('Invitations')).toBeVisible();
await expect(page.getByText(/From Kaya/)).toBeVisible();
await page.getByRole('button', { name: /^Accept$/ }).click();
await expect(page.getByText(/From Kaya/)).toBeHidden();
});
test('stats screen shows the metrics', async ({ page }) => {
await loginLobby(page);
await page.getByRole('button', { name: /Stats/ }).click();
await expect(page.getByText('Win rate')).toBeVisible();
await expect(page.getByText('Best move')).toBeVisible();
});
test('profile edit saves a new display name', async ({ page }) => {
await loginLobby(page);
await page.locator('.burger').first().click();
await page.getByRole('button', { name: /Profile/ }).click();
await page.getByRole('button', { name: /Edit profile/ }).click();
await page.locator('.edit input').first().fill('Kaya Test');
await page.getByRole('button', { name: /^Save$/ }).click();
await expect(page.locator('.name')).toHaveText('Kaya Test');
});
test('GCG export appears only for a finished game', async ({ page }) => {
await loginLobby(page);
// The finished game vs Kaya exposes the export; the menu carries the item.
await page.getByRole('button', { name: /Kaya/ }).click();
await page.locator('.burger').first().click();
await expect(page.getByRole('button', { name: /Export GCG/ })).toBeVisible();
});
test('GCG export is hidden for an active game', async ({ page }) => {
await loginLobby(page);
await page.getByRole('button', { name: /Ann/ }).click();
await page.locator('.burger').first().click();
await expect(page.getByRole('button', { name: /Export GCG/ })).toHaveCount(0);
});
test('finished game draws an inert footer and trims the live-only menu', async ({ page }) => {
await loginLobby(page);
await page.getByRole('button', { name: /Kaya/ }).click(); // finished game vs Kaya
await expect(page.locator('[data-cell]').first()).toBeVisible();
// The footer (tab bar) is drawn but its controls are disabled in a finished game.
await expect(page.locator('.tab').first()).toBeDisabled();
// The menu drops Check word and Drop game once the game is over.
await page.locator('.burger').first().click();
await expect(page.getByRole('button', { name: 'Check word' })).toHaveCount(0);
await expect(page.getByRole('button', { name: 'Drop game' })).toHaveCount(0);
});