import { test, expect, type Page } from '@playwright/test'; // E2E for the admin Analysis section: scoped re-enqueue (all / manga / // chapter) with the include-already-analyzed toggle. Fully mocked. const DESKTOP = { width: 1280, height: 720 } as const; const adminUser = { id: 'u11111111-1111-1111-1111-111111111111', username: 'admin', created_at: '2026-01-01T00:00:00Z', is_admin: true }; const systemStats = { disk: null, memory: { total_bytes: 1, used_bytes: 0, percent_used: 0 }, cpu: { percent_used: 0 }, alerts: [] }; type Captured = { body: Record | null }; async function mockAdmin(page: Page, captured: Captured) { await page.route('**/api/v1/auth/config', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ self_register_enabled: true, private_mode: false }) }) ); await page.route('**/api/v1/auth/me', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) }) ); await page.route('**/api/v1/auth/me/preferences', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ reader_mode: 'single', reader_page_gap: 'small' }) }) ); await page.route('**/api/v1/me/bookmarks*', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ items: [], page: { limit: 50, offset: 0, total: 0 } }) }) ); await page.route('**/api/v1/admin/system', (route) => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(systemStats) }) ); await page.route('**/api/v1/admin/analysis/reenqueue', (route) => { captured.body = JSON.parse(route.request().postData() ?? '{}'); return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ enqueued: 12 }) }); }); } test.describe('/admin/analysis', () => { test('default whole-library re-enqueue posts only_unanalyzed=true', async ({ page }) => { const captured: Captured = { body: null }; await mockAdmin(page, captured); await page.setViewportSize(DESKTOP); await page.goto('/admin/analysis'); await expect(page.getByTestId('admin-analysis-form')).toBeVisible(); await page.getByTestId('admin-analysis-submit').click(); await expect(page.getByTestId('admin-analysis-notice')).toContainText( 'Enqueued 12 pages' ); expect(captured.body).toEqual({ only_unanalyzed: true }); }); test('manga scope + include-analyzed posts manga_id and only_unanalyzed=false', async ({ page }) => { const captured: Captured = { body: null }; await mockAdmin(page, captured); await page.setViewportSize(DESKTOP); await page.goto('/admin/analysis'); await page.getByTestId('admin-analysis-scope-manga').check(); await page .getByTestId('admin-analysis-manga-id') .fill('a9999999-9999-9999-9999-999999999999'); await page.getByTestId('admin-analysis-include-analyzed').check(); await page.getByTestId('admin-analysis-submit').click(); await expect(page.getByTestId('admin-analysis-notice')).toBeVisible(); expect(captured.body).toEqual({ only_unanalyzed: false, manga_id: 'a9999999-9999-9999-9999-999999999999' }); }); test('chapter scope requires an id before posting', async ({ page }) => { const captured: Captured = { body: null }; await mockAdmin(page, captured); await page.setViewportSize(DESKTOP); await page.goto('/admin/analysis'); await page.getByTestId('admin-analysis-scope-chapter').check(); await page.getByTestId('admin-analysis-submit').click(); await expect(page.getByTestId('admin-analysis-error')).toContainText( 'Enter a chapter id' ); expect(captured.body).toBeNull(); }); });