import {test, expect} from '@playwright/test'; async function expectLinkedMentions(page) { // Le titre du navigateur et les fichiers bruts ne sont pas des liens HTML. const unlinked = await page.locator('body').evaluate(body => { const walker = document.createTreeWalker(body, NodeFilter.SHOW_TEXT); const failures = []; while (walker.nextNode()) { const node = walker.currentNode; const parent = node.parentElement; if (!parent || parent.closest('script, style, noscript') || !parent.checkVisibility()) continue; if (/\bgtb\b/i.test(node.textContent) && parent.closest('a')?.href !== 'https://gtbia.com/') { failures.push(node.textContent); } } return failures; }); expect(unlinked).toEqual([]); expect(await page.locator('a').evaluateAll(links => links.every(a => !a.querySelector('a')))).toBe(true); await expect(page.getByRole('link', {name: 'GTB', exact: true}).first()).toHaveAttribute('href', 'https://gtbia.com'); } async function expectAttribution(page) { const section = page.getByRole('region', {name: 'L’agent derrière Traces'}); await expect(section).toBeVisible(); await expect(section).toContainText('une personnalisation basée sur le projet open source'); await expect(section.getByRole('link', {name: 'pi-mom-slack', exact: true})) .toHaveAttribute('href', 'https://github.com/tsua0002/pi-mom-slack'); await expect(section).toContainText('Le projet d’origine est l’œuvre de ses auteurs'); await expect(section).toContainText('ni partenariat ni approbation'); } for (const viewport of [{width: 1280, height: 900}, {width: 390, height: 844}]) { test(`liens GTB, attribution et navigation (${viewport.width}px)`, async ({page}) => { await page.setViewportSize(viewport); for (const route of ['comprendre', 'simulateur', 'fabrication', 'methode']) { await page.goto(`/#${route}`); await expect(page.locator(`#${route}`)).toBeVisible(); await expectLinkedMentions(page); if (route === 'fabrication') await expectAttribution(page); } const gtb = page.locator('header').getByRole('link', {name: 'GTB', exact: true}); await gtb.focus(); await expect(gtb).toBeFocused(); await page.locator('.brand-home').click(); await expect(page).toHaveURL(/#comprendre$/); await expect(page.locator('#comprendre')).toBeVisible(); expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true); }); } test.describe('sans JavaScript', () => { test.use({javaScriptEnabled: false}); for (const path of ['/', '/methode.html', '/journal.html']) { test(`mentions cliquables ${path}`, async ({page}) => { await page.goto(path); await expectLinkedMentions(page); if (path === '/journal.html') await expectAttribution(page); }); } });