const { test, expect } = require('@playwright/test'); test('report triage filters age and resolves a song batch with confirmation', async ({ page }) => { const requests = []; await page.route('**/api/**', async route => { const request = route.request(); const url = new URL(request.url()); requests.push({ path: url.pathname, search: url.search, method: request.method() }); let body = { ok: true }; if (url.pathname === '/api/admin/me') body = { ok: true, enabled: true, admin: true }; if (url.pathname === '/api/admin/flags' && request.method() === 'GET') body = { ok: true, open: 2, flags: [ { id: 1, videoId: 'dQw4w9WgXcQ', title: 'Sample song', channel: 'Choir', text: 'Flagged line', reporter: 'Listener', reason: 'words', status: 'open', createdAt: 1791300000, note: 'Wrong lyric' }, { id: 2, videoId: 'dQw4w9WgXcQ', title: 'Sample song', channel: 'Choir', text: 'Flagged line', reporter: 'Second listener', reason: 'typo', status: 'open', createdAt: 1791300000, note: '' }, ] }; if (url.pathname.endsWith('/resolve') && request.method() === 'POST') body = { ok: true, resolved: 2, open: 0 }; if (url.pathname === '/api/notes/dQw4w9WgXcQ') body = { ok: true, lyrics: null, chapters: null }; if (url.pathname === '/api/admin/notes/recent') body = { ok: true, notes: [] }; await route.fulfill({ contentType: 'application/json', body: JSON.stringify(body) }); }); page.on('dialog', dialog => dialog.accept()); await page.goto('/admin.html#reports'); await expect(page.locator('#repList')).toContainText('Second listener'); await page.locator('#reportAge').selectOption('30'); await expect.poll(() => requests.some(r => r.path === '/api/admin/flags' && r.search.includes('olderThanDays=30'))).toBe(true); await page.locator('[data-resolve-song="dQw4w9WgXcQ"]').click(); await expect.poll(() => requests.some(r => r.path === '/api/admin/flags/song/dQw4w9WgXcQ/resolve' && r.method === 'POST')).toBe(true); });