Files
TradarrV2/frontend/e2e/ticket13-sources-responsive.spec.mjs

65 lines
3.4 KiB
JavaScript

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(2)
const activationNames = await activationControls.evaluateAll(nodes => nodes.map(node => node.getAttribute('aria-label').replace(/^(Activer|Désactiver) /, '')).sort())
expect(activationNames).toEqual(['Bloomberg', 'Investing.com'])
await expect(page.locator('form[aria-label^="Réglages de "]')).toHaveCount(2)
const historical = page.getByRole('region', { name: 'Sources retirées' })
await expect(historical).toBeVisible()
await historical.getByText(/^Consulter les sources retirées/).click()
for (const name of ['Yahoo Finance', 'CNBC Business']) {
await expect(historical.getByText(name, { exact: true })).toBeVisible()
await expect(page.getByRole('button', { name: `Activer ${name}`, exact: true })).toHaveCount(0)
await expect(page.getByRole('button', { name: `Désactiver ${name}`, exact: true })).toHaveCount(0)
}
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 ['Bloomberg', 'Investing.com']) {
const toggle = activationControls.filter({ hasText: /Activer|Désactiver/ }).and(page.getByRole('button', { name: new RegExp(name) }))
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)
}
})