import { expect, test } from '@playwright/test'; import { contextForUser } from './helpers'; /** * Label UI pack (issue #44). Runs against the local dev stack (api + web). * Selectors are language-independent (CSS classes + label names) because the * UI language follows the signed-in user's profile locale, not the browser — * so text-based selectors would be locale-dependent. Creates uniquely-named * labels/pages per test and removes the labels via the api afterwards so the * shared fixture pond does not accumulate them. */ const BASE_URL = process.env.E2E_BASE_URL ?? 'http://localhost:5173'; type Ctx = Awaited>; async function personalPond(context: Ctx): Promise<{ id: string; slug: string }> { const ponds = await context.request.get('/api/v1/ponds'); const pond = (await ponds.json()).find((p: { type: string }) => p.type === 'personal'); return { id: pond.id, slug: pond.slug }; } async function createPage( context: Ctx, pondId: string, title: string, ): Promise<{ id: string; slug: string }> { const created = await context.request.post(`/api/v1/ponds/${pondId}/pages`, { data: { title } }); return created.json(); } async function createLabel( context: Ctx, pondId: string, name: string, parentId?: string, ): Promise<{ id: string }> { const created = await context.request.post(`/api/v1/ponds/${pondId}/labels`, { data: { name, ...(parentId ? { parentId } : {}) }, }); return created.json(); } test('label lifecycle works from the pond settings UI', async ({ browser }) => { const context = await contextForUser(browser, BASE_URL, 'fixture-user'); const pond = await personalPond(context); const ts = Date.now(); const root = `Alpha ${ts}`; const renamed = `Alpha2 ${ts}`; const child = `Sub ${ts}`; const page = await context.newPage(); // Delete confirmations are window.confirm dialogs — accept them. page.on('dialog', (dialog) => void dialog.accept()); await page.goto(`/p/${pond.slug}/settings`); // Create a root label using only the keyboard (type + Enter submits the form). const newInput = page.locator('.label-manager__new-root input'); await newInput.fill(root); await newInput.press('Enter'); await expect(page.locator('.label-node__name', { hasText: root })).toBeVisible(); // Locate a row by its name span — NOT getByText, which would also match the // move-dropdown