diff --git a/apps/app/e2e/shell/responsive.spec.ts b/apps/app/e2e/shell/responsive.spec.ts new file mode 100644 index 00000000..d7f95d83 --- /dev/null +++ b/apps/app/e2e/shell/responsive.spec.ts @@ -0,0 +1,162 @@ +import { en } from '@/i18n/en' +import { fr } from '@/i18n/fr' +import type { Dict } from '@/i18n/types' +import type { Page, TestInfo } from '@playwright/test' +import { + expect, + expectNoHorizontalOverflow, + focusOwner, + test, +} from '../support/browser' +import { + createAccount, + dropLateReplays, + routeToSandbox, +} from '../support/sandbox' +import { seedAnimal, seedClient, seedRelation } from '../support/records' +import { signIn } from '../support/shell' + +// RESP-01 (V1-1 DEV acceptance): no page of the shell scrolls sideways, from +// 320 to 430 px on the phone project and at the desktop width, with long +// realistic values in both languages; the dashboard shows the whole e-mail of +// the account (a long one used to widen the cards past the screen). + +const LANGUAGES = [ + ['fr', fr], + ['en', en], +] as const + +const PHONE_WIDTHS = [320, 360, 375, 390, 430] + +const LONG = { + localPart: 'prenom.nom-compose.praticienne-fictive', + client: 'Recette Client Au Nom Particulièrement Long Pour Les Petits Écrans', + clientEmail: 'prenom.nom-compose.recette@cabinet-veterinaire-exemple.example.org', + address: 'Chemin de la Recette Responsive, Lieu-dit Les Petits Écrans', + city: 'Saint-Rémy-de-Provence-sur-Recette', + structure: 'Écurie Recette Structure Responsive Organisation', + animal: 'Recette Animal Au Nom Très Long Pour Les Écrans Étroits', +} + +const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' + +/** Opens a page and waits for its heading and its reads. */ +async function open(page: Page, path: string) { + await page.goto(path) + await expect(page.locator('main h1').first()).toBeVisible() + await page.waitForLoadState('networkidle') +} + +/** The account e-mail of the dashboard is shown whole: not clipped, not cut. */ +async function expectWholeEmail(page: Page, email: string, state: string) { + const value = page.locator('main dd', { hasText: email }) + await expect(value).toHaveText(email) + const clipped = await value.evaluate((dd) => dd.scrollWidth > dd.clientWidth) + expect(clipped, `e-mail clipped on ${state}`).toBe(false) +} + +/** A confirmation opened with Enter keeps the focus, fits, and Escape gives it back. */ +async function checkConfirmation( + page: Page, + action: string, + title: string, + state: string, +) { + const button = page.getByRole('button', { name: action, exact: true }) + await button.focus() + await page.keyboard.press('Enter') + const dialog = page.getByRole('dialog', { name: title }) + await expect(dialog).toBeVisible() + expect(await focusOwner(page)).toBe('dialog') + await expectNoHorizontalOverflow(page, state) + await page.keyboard.press('Escape') + await expect(dialog).toBeHidden() + await expect(button).toBeFocused() +} + +async function checkDrawer(page: Page, dict: Dict, state: string) { + const menu = page.getByRole('button', { name: dict['shell.open_menu'] }) + await menu.focus() + await page.keyboard.press('Enter') + const drawer = page.getByRole('dialog', { name: dict['shell.nav_label'] }) + await expect(drawer).toBeVisible() + await expectNoHorizontalOverflow(page, state) + await page.keyboard.press('Escape') + await expect(drawer).toBeHidden() + await expect(menu).toBeFocused() +} + +for (const [locale, dict] of LANGUAGES) { + test.describe(`responsive (${locale})`, () => { + test.use({ locale: locale === 'fr' ? 'fr-FR' : 'en-GB' }) + test.beforeEach(async ({ context }) => { + await routeToSandbox(context) + }) + test.afterEach(async ({ context }) => { + await dropLateReplays(context) + }) + + test('no sideways scroll on the shell pages, dialogs and drawer, long values', async ({ + page, + requests, + }, info) => { + test.setTimeout(240_000) + const account = await createAccount(locale, true, LONG.localPart) + requests.forbid(account.email, account.password, account.displayName) + const client = await seedClient(account, LONG.client, { + email: LONG.clientEmail, + addressLine1: LONG.address, + city: LONG.city, + phone: '+33639980001', + }) + const structure = await seedClient(account, LONG.structure, { + kind: 'organization', + city: LONG.city, + }) + const animal = await seedAnimal(account, LONG.animal) + await seedRelation(account, animal, client, 'owner', '2024-01-01') + await seedRelation(account, animal, structure, 'keeper', '2024-02-01') + await signIn(page, account, dict) + + const pages = [ + '/app', + '/app/clients', + '/app/clients/new', + `/app/clients/${client}`, + `/app/clients/${client}/edit`, + '/app/animals', + '/app/animals/new', + `/app/animals/${animal}`, + `/app/animals/${animal}/edit`, + ] + const widths = isPhone(info) ? PHONE_WIDTHS : [page.viewportSize()!.width] + for (const width of widths) { + await page.setViewportSize({ width, height: 667 }) + for (const path of pages) { + await open(page, path) + const state = `${path.replace(/[0-9a-f-]{36}/, ':id')} at ${width} px` + await expectNoHorizontalOverflow(page, state) + if (path === '/app') await expectWholeEmail(page, account.email, state) + if (path === `/app/clients/${client}`) + await checkConfirmation( + page, + dict['clients.detail.archive'], + dict['clients.archive.title'], + `the client archive confirmation at ${width} px`, + ) + if (path === `/app/animals/${animal}`) + await checkConfirmation( + page, + dict['animals.detail.archive'], + dict['animals.archive.title'], + `the animal archive confirmation at ${width} px`, + ) + } + if (isPhone(info)) { + await open(page, '/app/clients') + await checkDrawer(page, dict, `the open drawer at ${width} px`) + } + } + }) + }) +} diff --git a/apps/app/e2e/support/records.ts b/apps/app/e2e/support/records.ts index f078ccd5..4770b0e1 100644 --- a/apps/app/e2e/support/records.ts +++ b/apps/app/e2e/support/records.ts @@ -15,6 +15,8 @@ export interface ClientSeed { kind?: 'person' | 'organization' city?: string | null phone?: string | null + email?: string | null + addressLine1?: string | null } export async function seedClient( @@ -23,9 +25,11 @@ export async function seedClient( seed: ClientSeed = {}, ): Promise { const ws = await workspaceOf(account) - return sql(`insert into public.clients (workspace_id, kind, display_name, city, phone, create_request_id, create_request_digest) + return sql(`insert into public.clients (workspace_id, kind, display_name, city, phone, email, address_line1, + create_request_id, create_request_digest) values (${literal(ws)}, ${literal(seed.kind ?? 'person')}, ${literal(displayName)}, ${literal(seed.city ?? null)}, - ${literal(seed.phone ?? null)}, gen_random_uuid(), '\\x00') returning id`) + ${literal(seed.phone ?? null)}, ${literal(seed.email ?? null)}, ${literal(seed.addressLine1 ?? null)}, + gen_random_uuid(), '\\x00') returning id`) } export async function seedAnimal( diff --git a/apps/app/e2e/support/sandbox.ts b/apps/app/e2e/support/sandbox.ts index 8bfb6c94..4f34dda7 100644 --- a/apps/app/e2e/support/sandbox.ts +++ b/apps/app/e2e/support/sandbox.ts @@ -96,14 +96,18 @@ async function seedAvatar(ownerId: string): Promise { 'image/webp', ${AVATAR_WEBP.length}, ${AVATAR_WEBP.length}, '${sha256}')`) } -/** A confirmed fictitious account, its profile in `locale`, with or without a photo. */ +/** + * A confirmed fictitious account, its profile in `locale`, with or without a + * photo; `localPart` starts the address (a long one tests narrow screens). + */ export async function createAccount( locale: 'fr' | 'en', withAvatar: boolean, + localPart = 'e2e-shell', ): Promise { const tag = randomUUID().slice(0, 8) const account = { - email: `e2e-shell-${tag}@sandbox.local`, + email: `${localPart}-${tag}@sandbox.local`, password: randomBytes(18).toString('base64url'), displayName: `Praticienne Fictive ${tag}`, } diff --git a/apps/app/src/app/routes/app/DashboardRoute.tsx b/apps/app/src/app/routes/app/DashboardRoute.tsx index 45e3ca63..b1a94665 100644 --- a/apps/app/src/app/routes/app/DashboardRoute.tsx +++ b/apps/app/src/app/routes/app/DashboardRoute.tsx @@ -87,8 +87,9 @@ function AccountCard() {

{t('dashboard.account.title')}

-
{t('dashboard.account.email')}
-
{user?.email}
+
{t('dashboard.account.email')}
+ {/* An address longer than the card wraps: never cut, never wider than the screen. */} +
{user?.email}
@@ -126,7 +127,8 @@ export default function DashboardRoute() { {t('dashboard.intro')}

-
+ {/* One explicit column below md: an implicit track would grow to the cards' content. */} +