Files
ita-ito-horaires/e2e/messages.spec.ts
T
vliaudatandClaude Opus 5 5f7aa951d3 feat: explain a schedule change on the panel, and preview it in advance
Two things the shop asked for, and one it will notice.

**A message on an exception.** A closure or a late opening can now carry
a reason, and it reaches the panel. It shows while the door is shut and
disappears the moment the shop opens — a notice explaining a late
opening is worse than useless once the door is open.

It outranks a free message on purpose: "closed this afternoon, back
tomorrow" is what someone standing outside needs, and "new collection in
store" can wait. Say so if you would rather it were the other way.

The first version keyed this off the day's `isOpen`, which means "this
day has opening hours" — so a day opening at 14:00 counted as open all
morning, exactly when the reason is needed. A test caught it; the rule
now reads the state at this minute.

**Reusable phrases.** The same handful of notices get written over and
over. /admin/modeles keeps them, translated once, and offers them
wherever a message is composed — exceptions, closure periods, the
banner. Picking one costs no translation at all: the saved English is
reused directly, where the service takes the better part of ten seconds.

Exception notes and holiday labels are translated too, which they were
not before. After the save rather than during it, so a slow service
never costs the shop its dates.

**Previewing the future.** The dashboard can render the panel at any
moment within about a year: "what will the window say while I'm away?"
is worth answering before someone is standing in front of a locked door.
The whole pipeline was already a function of "now", so this costs
passing a different instant. An unparseable or absurd value falls back
to the present rather than confidently rendering nonsense.

Checked against a three-week holiday, which surfaced something worth
knowing: the automatic "opens on…" line stays empty, because the
resolver's search is bounded to fourteen days. During a long closure the
message is the only thing that tells customers when the shop is back —
which is a good reason for this feature to exist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cSY9pVhZmJUKNN7wf1Myd
2026-09-23 09:34:14 +02:00

78 lines
3.3 KiB
TypeScript

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('a saved phrase can be reused wherever a message is composed', async ({ page }) => {
await signIn(page, 'admin');
await page.goto('/admin/modeles');
await page.getByLabel(/Texte en français/).fill('Fermeture exceptionnelle, retour demain');
await page.getByRole('button', { name: 'Ajouter' }).click();
await expect(page.getByRole('status')).toContainText(/Modèle enregistré/);
// The point of a template is that it turns up elsewhere without retyping.
await page.goto('/admin/exceptions');
await page.getByLabel('Modèle de message').first().selectOption({ label: 'Fermeture exceptionnelle, retour demain' });
await expect(page.getByLabel(/Message affiché/).first()).toHaveValue(
'Fermeture exceptionnelle, retour demain',
);
});
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();
});