test(e2e): fix J4 — add page reload assertion, unique title, afterAll cleanup, precise selector

Four concerns addressed:
- Persistence: reloads the detail page after save and re-asserts the tag link,
  making the report's "after page reload" claim accurate
- Unique title: adds stamp to document title to prevent accumulation across runs
- Cleanup: afterAll deletes the test document
- Selector: replaces getByText(newTagName) with a[href*="?tag="] scoped to the tag link

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-05 19:03:27 +02:00
parent fcd91c2e81
commit 3f25f1fd73

View File

@@ -633,24 +633,30 @@ test.describe('Document editing — tags (J3)', () => {
// ── J4: Create a brand-new tag via TagInput ────────────────────────────────
//
// Types a tag name that does not exist yet, confirms creation with Enter, and
// verifies the tag chip persists after save.
// verifies the tag chip persists after save AND after a full page reload.
test.describe('Document editing — new tag creation (J4)', () => {
const baseURL = process.env.E2E_BASE_URL ?? 'http://localhost:3000';
let newTagDocHref: string;
const newTagName = `E2E-Tag-${Date.now().toString(36)}`;
let newTagDocId: string;
const stamp = Date.now().toString(36);
const newTagName = `E2E-Tag-${stamp}`;
test.beforeAll(async ({ request }) => {
const createRes = await request.post('/api/documents', {
multipart: { title: 'E2E New Tag Test' }
multipart: { title: `E2E New Tag Test ${stamp}` }
});
if (!createRes.ok()) throw new Error(`Create document failed: ${createRes.status()}`);
const doc = await createRes.json();
newTagDocHref = `${baseURL}/documents/${doc.id}`;
newTagDocId = doc.id;
});
test('user types a new tag name, presses Enter, saves, and sees the chip', async ({ page }) => {
await page.goto(`${newTagDocHref}/edit`);
test.afterAll(async ({ request }) => {
if (newTagDocId) await request.delete(`/api/documents/${newTagDocId}`);
});
test('user types a new tag name, presses Enter, saves, and tag persists after reload', async ({
page
}) => {
await page.goto(`/documents/${newTagDocId}/edit`);
await page.waitForSelector('[data-hydrated]');
const tagInput = page.getByPlaceholder('Schlagworte hinzufügen...');
@@ -665,8 +671,19 @@ test.describe('Document editing — new tag creation (J4)', () => {
await page.getByRole('button', { name: 'Speichern', exact: true }).click();
// Detail page after redirect — tag link must be visible.
await expect(page).toHaveURL(/\/documents\/[^/]+$/);
await expect(page.getByText(newTagName)).toBeVisible({ timeout: 5_000 });
await expect(page.locator('a[href*="?tag="]', { hasText: newTagName })).toBeVisible({
timeout: 5_000
});
// Reload to verify the tag survived the round-trip (not just client-side state).
await page.reload();
await page.waitForSelector('[data-hydrated]');
await expect(page.locator('a[href*="?tag="]', { hasText: newTagName })).toBeVisible({
timeout: 5_000
});
await page.screenshot({ path: 'test-results/e2e/document-new-tag-created.png' });
});
});