const assert = require('node:assert/strict'); const { chromium } = require(process.env.PLAYWRIGHT_PACKAGE || 'playwright'); const base = process.env.REVIEW_BASE || 'http://localhost:3114'; (async () => { const browser = await chromium.launch(); try { const context = await browser.newContext(); await context.addCookies([{ name: 'magent_logged_in', value: '1', url: base }]); let allowed = true; const writes = [], errors = []; await context.route('**/api/**', async route => { const request = route.request(), path = new URL(request.url()).pathname; const reply = json => route.fulfill({ json }); if (path === '/api/auth/me') return reply({ username: 'Viewer', role: 'user', features: { requests: true, ignore_profile_limits: allowed } }); if (path.endsWith('/snapshot')) return reply({ request_id: '42', title: 'Trying', request_type: 'tv', state: 'ADDED_TO_ARR', timeline: [], actions: [{ id: 'search_releases', label: 'Search and choose a download', requires_confirmation: false }], presentation: { status: { label: 'Waiting', meaning: 'Two missing episodes.' }, nextStep: { title: 'Search', description: 'Find missing episodes.', actionIds: ['search_releases'] }, pipeline: [] } }); if (path.endsWith('/language')) return reply({ language: null }); if (path.includes('/operations/')) return reply({ id: path.split('/').pop(), status: 'complete', events: [] }); if (path.endsWith('/actions/search')) return reply({ status: 'ok', outcome: 'attention', canIgnoreProfileLimits: allowed, nextOffset: 20, message: '2 releases found; none meet the assigned profile.', releases: [ { guid: 'out', indexerId: 1, title: 'Trying.S05E03.2160p', quality: 'WEBDL-2160p', requiresOverride: true, selectable: true, selectionToken: allowed ? 'signed-fixture' : undefined, rejections: ['WEBDL-2160p is not wanted in profile'] }, { guid: 'wrong', indexerId: 1, title: 'Wrong.Show.S05E03', selectable: false, rejections: ['Unknown series'] }, ] }); if (path.endsWith('/actions/grab')) { writes.push(request.postDataJSON()); return reply({ status: 'ok', message: 'Selected release sent to Sonarr.' }); } if (path.includes('/events/stream')) return route.fulfill({ contentType: 'text/event-stream', body: ': fixture\n\n' }); return reply({}); }); const page = await context.newPage(); page.on('pageerror', e => errors.push(e.message)); for (const width of [1440, 390]) { for (const permission of [true, false]) { allowed = permission; await page.setViewportSize({ width, height: 950 }); await page.goto(base + '/requests/42'); await page.getByRole('button', { name: 'Search and choose a download', exact: true }).first().click(); await page.getByRole('button', { name: allowed ? 'Choose a version' : 'View search results', exact: true }).click(); const picker = page.getByRole('dialog', { name: 'Choose an available download' }); await picker.waitFor(); await picker.getByText('WEBDL-2160p is not wanted in profile', { exact: true }).waitFor(); assert.equal(await picker.getByText('Best pick', { exact: true }).count(), 0); assert(await picker.getByRole('button', { name: 'Download outside profile' }).isDisabled()); assert(await picker.getByRole('button', { name: 'Download this release' }).isDisabled()); const toggle = picker.getByRole('checkbox', { name: /^Ignore profile limits/ }); assert.equal(await toggle.count(), allowed ? 1 : 0); assert(await picker.evaluate(el => el.scrollWidth <= el.clientWidth)); if (allowed) { await toggle.check(); assert(await picker.getByRole('button', { name: 'Download outside profile' }).isEnabled()); assert(await picker.getByRole('button', { name: 'Download this release' }).isDisabled()); page.once('dialog', dialog => dialog.dismiss()); const before = writes.length; await picker.getByRole('button', { name: 'Download outside profile' }).click(); assert.equal(writes.length, before); page.once('dialog', dialog => dialog.accept()); await picker.getByRole('button', { name: 'Download outside profile' }).click(); await page.getByRole('dialog', { name: 'Waiting to start', exact: true }).getByText('Your download has been sent.', { exact: true }).waitFor(); assert.equal(await page.locator('.activity-dialog-events').count(), 0); assert.equal(await page.getByRole('dialog', { name: 'Waiting to start', exact: true }).getByRole('progressbar').getAttribute('aria-valuenow'), '100'); assert.equal(writes.at(-1).ignoreProfileLimits, true); assert.equal(writes.at(-1).selectionToken, 'signed-fixture'); } } } assert.deepEqual(errors, []); console.log('Passed: desktop/mobile rejected-release reasons, per-user override visibility, explicit confirmation/cancel, blocked operational failures, signed selection payload, and no overflow. All APIs intercepted.'); } finally { await browser.close(); } })().catch(e => { console.error(e); process.exitCode = 1; });