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 scenario = 'empty'; 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 scenario === 'error' ? route.fulfill({ status: 502, json: { detail: 'Service unavailable' } }) : reply({ status: 'ok', outcome: 'attention', releases: [], nextOffset: null }); 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 test of ['empty', 'error']) { scenario = test; 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(); const dialog = page.getByRole('dialog', {name: test === 'empty' ? 'Nothing available yet' : 'Search could not finish', exact:true}); await dialog.waitFor(); assert.equal(await dialog.getByRole('button', {name:'Choose a version'}).count(), 0); await dialog.getByText(test === 'empty' ? 'You can try again later.' : 'Try again shortly. If it keeps happening, contact an admin.', {exact:true}).waitFor(); assert(await dialog.evaluate(el => el.scrollWidth <= el.clientWidth)); } } assert.deepEqual(errors, []); console.log('Passed: empty search and unavailable service outcomes on desktop/mobile; no unavailable selection action or overflow. APIs intercepted.'); } finally { await browser.close(); } })().catch(e => { console.error(e); process.exitCode = 1; });