import { expect, test } from '@playwright/test'; import { contextForUser } from './helpers'; const BASE_URL = process.env.E2E_BASE_URL ?? 'http://localhost:5173'; /** * The general admin settings card saves THROUGH THE FORM (issue #322). * * This must drive the UI, not the api: the bug it fences was invisible to * every api-level test — react-hook-form nested the dotted field names on * input, the strict PATCH schema rejected the body, and the form looked * fine while never saving. Verified end to end: success message, the value * survives a full reload, the api returns it, and the TopBar picks it up * without a reload (branding query invalidation). */ test('instance name changed in the general settings form persists', async ({ browser }) => { const admin = await contextForUser(browser, BASE_URL, 'fixture-admin'); const before = ( (await (await admin.request.get('/api/v1/admin/settings')).json()) as Record )['instance.name'] as string; const newName = `Renamed ${Date.now()}`; const nameLabel = /^(Instance name|Name der Instanz)$/; const page = await admin.newPage(); try { await page.goto('/admin'); const generalCard = page .locator('section.settings-section') .filter({ has: page.getByLabel(nameLabel) }); await page.getByLabel(nameLabel).fill(newName); await generalCard.getByRole('button', { name: /^(Save|Speichern)$/ }).click(); // Scoped to the card: the page has several forms with status regions. await expect(generalCard.getByRole('status')).toHaveText(/^(Saved\.|Gespeichert\.)$/); // The TopBar and the document title show the new name without a reload — // the save invalidates the branding query both read from (issue #323). await expect(page.locator('.topbar__brand')).toHaveText(newName); await expect(page).toHaveTitle(new RegExp(`${newName}$`)); // The proof the form really persisted: the value survives a reload and // the api returns it. await page.reload(); await expect(page.getByLabel(nameLabel)).toHaveValue(newName); const stored = ( (await (await admin.request.get('/api/v1/admin/settings')).json()) as Record )['instance.name']; expect(stored).toBe(newName); } finally { await admin.request.patch('/api/v1/admin/settings', { data: { 'instance.name': before }, }); await admin.close(); } });