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(); });