import { test, expect } from '@playwright/test' import { readStackManifest } from './stack-manifest.mjs' async function loginAsBootstrapAdmin(page, stack) { await page.goto(new URL('/login', stack.frontendUrl).href) await page.getByLabel('Adresse email').fill(stack.bootstrapAdmin.email) await page.getByLabel('Mot de passe').fill(stack.bootstrapAdmin.password) await page.getByRole('button', { name: 'Se connecter' }).click() await expect(page).toHaveURL(new URL('/', stack.frontendUrl).href) } test('admin source controls stay accessible and fit at 320, 375 and 390 px', async ({ page }) => { const stack = readStackManifest() await page.context().route('**/*', async route => { const host = new URL(route.request().url()).hostname if (host !== '127.0.0.1' && host !== '[::1]') return route.abort('blockedbyclient') return route.continue() }) await loginAsBootstrapAdmin(page, stack) await page.goto(new URL('/admin/sources', stack.frontendUrl).href) await expect(page.getByRole('heading', { name: 'Sources et plafonds' })).toBeVisible() const activationControls = page.locator('button[aria-label^="Activer "], button[aria-label^="Désactiver "]') await expect(activationControls).toHaveCount(3) const activationNames = (await activationControls.evaluateAll(nodes => nodes.map(node => node.getAttribute('aria-label').replace(/^(Activer|Désactiver) /, '')).sort())) expect(activationNames).toEqual(['Bloomberg', 'CNBC Business', 'Yahoo Finance']) await expect(page.locator('form[aria-label^="Réglages de "]')).toHaveCount(3) const historical = page.getByRole('region', { name: 'Anciennes sources exclues' }) await expect(historical).toBeVisible() await historical.getByText(/^Consulter les anciennes sources/).click() const historicalRows = historical.locator('li') expect(await historicalRows.count()).toBeGreaterThan(0) await expect(historicalRows.locator('button, input, form, a')).toHaveCount(0) for (const width of [320, 375, 390]) { await page.setViewportSize({ width, height: 844 }) const dimensions = await page.evaluate(() => ({ viewport: window.innerWidth, document: document.documentElement.scrollWidth, })) expect(dimensions.document, `horizontal overflow at ${width}px: ${JSON.stringify(dimensions)}`).toBeLessThanOrEqual(dimensions.viewport) await expect(page.getByRole('spinbutton', { name: 'Articles max par résumé' })).toBeVisible() for (const name of ['Yahoo Finance', 'Bloomberg', 'CNBC Business']) { const toggle = page.getByRole('button', { name: new RegExp(`^(?:Activer|Désactiver) ${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`) }) const cap = page.getByRole('spinbutton', { name: `Plafond ${name}` }) await expect(toggle).toBeVisible() await expect(toggle).toBeEnabled() await expect(cap).toBeVisible() await expect(cap).toHaveAttribute('min', '1') await expect(cap).toHaveAttribute('max', '200') await expect(page.getByRole('button', { name: `Enregistrer le plafond ${name}` })).toBeVisible() } await expect(historical).toBeVisible() await expect(historicalRows.locator('button, input, form, a')).toHaveCount(0) } })