test: add the end-to-end suite, on desktop and on a phone
Twenty-six tests across two viewports, covering what the spec asks for: changing today's hours reaches the panel, a message survives the translation service being unavailable, a closure period closes the days it covers — plus the authorisation paths and the sign-out regression. They run against the standalone build served the way the container serves it, not `next start`, which refuses to work with standalone output anyway. The suite therefore exercises the artifact that ships rather than a second arrangement that could drift from it. Sign-in mints the session cookie Auth.js would have issued rather than driving Authentik. What is under test is the application's behaviour for a given role; the handshake itself is verified against the live provider separately, and standing up an identity provider per run would trade a lot of machinery for coverage of somebody else's code. The secret lives in one module imported by both the config and the fixtures — when it differed, every signed-in test failed at once while looking like an authorisation bug. Database access goes through plain SQL rather than the Prisma client, whose generated module format Playwright's loader and Next's bundler disagree about. That traded one problem for a subtler one: node-postgres parses a DATE column into a local-midnight Date, so reading it back shifted the day at UTC+2. Dates are read as text now. The mobile profile runs on Chromium: WebKit needs system packages only root can install, and a suite nobody can run locally is a suite nobody runs. The config says how to switch to the real engine. Two real defects surfaced, both found by the tests rather than by reading. The seven "Ouvert" checkboxes on the hours page were indistinguishable to a screen reader; each now names its day. And on a phone the signed-in address appeared nowhere at all — the header hides it to save room — so nobody could tell which account was about to sign an audit entry on a device the shop shares. It is on the dashboard now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { expect, query, resetDatabase, signIn, test } from './fixtures';
|
||||
|
||||
test.beforeEach(async () => {
|
||||
await resetDatabase();
|
||||
});
|
||||
|
||||
test('a message is saved even when the translation service is unavailable', async ({ page }) => {
|
||||
// The E2E server has no translation credentials on purpose: losing the
|
||||
// message because the service is down would be the worst failure here.
|
||||
await signIn(page, 'admin');
|
||||
await page.goto('/admin/messages');
|
||||
|
||||
// Deliberately not the field's own placeholder text: matching that would
|
||||
// make the assertion pass before anything had been saved.
|
||||
const text = 'Nouvelle collection de printemps';
|
||||
|
||||
await page.getByLabel(/Texte en français/).fill(text);
|
||||
await page.getByRole('button', { name: 'Ajouter' }).click();
|
||||
|
||||
// Wait for the server's own verdict rather than for the text to appear: it
|
||||
// is the only signal that the write has actually completed.
|
||||
await expect(page.getByRole('status')).toContainText(/Message enregistré/);
|
||||
await expect(page.getByText(text).first()).toBeVisible();
|
||||
|
||||
const [stored] = await query<{ textFr: string; translationStatus: string }>(
|
||||
'SELECT "textFr", "translationStatus" FROM messages',
|
||||
);
|
||||
expect(stored?.textFr).toBe(text);
|
||||
// The E2E server has no translation credentials on purpose: the message
|
||||
// must survive the service being unavailable.
|
||||
expect(stored?.translationStatus).toBe('ERROR');
|
||||
});
|
||||
|
||||
test('a translation typed by hand is kept and shown', async ({ page }) => {
|
||||
await signIn(page, 'admin');
|
||||
await page.goto('/admin/messages');
|
||||
|
||||
await page.getByLabel(/Texte en français/).fill('Fermeture exceptionnelle');
|
||||
await page.getByRole('button', { name: 'Ajouter' }).click();
|
||||
await expect(page.getByRole('status')).toContainText(/Message enregistré/);
|
||||
|
||||
await page.getByLabel('Traduction anglaise').fill('Exceptionally closed');
|
||||
await page.getByRole('button', { name: 'Enregistrer' }).click();
|
||||
|
||||
await expect(page.getByText(/ne sera plus écrasée/)).toBeVisible();
|
||||
|
||||
const [stored] = await query<{ textEn: string; translationStatus: string }>(
|
||||
'SELECT "textEn", "translationStatus" FROM messages',
|
||||
);
|
||||
expect(stored?.textEn).toBe('Exceptionally closed');
|
||||
expect(stored?.translationStatus).toBe('MANUAL');
|
||||
});
|
||||
|
||||
test('the counter warns before a message stops fitting', async ({ page }) => {
|
||||
await signIn(page, 'admin');
|
||||
await page.goto('/admin/messages');
|
||||
|
||||
await page.getByLabel(/Texte en français/).fill('a'.repeat(130));
|
||||
await expect(page.getByText(/caractères de trop/)).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Ajouter' })).toBeDisabled();
|
||||
});
|
||||
Reference in New Issue
Block a user