SPB Git

Repository Public

pages.spec.ts 5.6 KB 124 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : agentilab-web8 * File             : tests/e2e/pages.spec.ts9 * Module           : Tests10 * Repository       : https://git.spboucher.ai/agentilab-web11 * Project Website  : Not specified12 * Created          : 2026-12-0513 * Last Modified    : 2026-12-0514 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : Proprietary34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import AxeBuilder from '@axe-core/playwright';44import { expect, test } from '@playwright/test';45import { href, pages } from './helpers';4647const titles = new Map<string, string>();4849for (const { id, locale, path } of pages) {50  test.describe(`${path}`, () => {51    test('répond 200, structure, métadonnées, console propre', async ({ page }) => {52      const problems: string[] = [];53      page.on('console', (message) => {54        if (message.type() === 'error') problems.push(message.text());55      });56      page.on('pageerror', (error) => problems.push(error.message));57      page.on('requestfailed', (request) => problems.push(`échec ${request.url()}`));58      page.on('response', (response) => {59        if (response.status() >= 400) problems.push(`${response.status()} ${response.url()}`);60        // Aucune ressource ne doit venir d’une autre origine.61        if (!response.url().startsWith('http://localhost')) problems.push(`tiers ${response.url()}`);62      });6364      const response = await page.goto(path);65      expect(response?.status()).toBe(200);66      await expect(page.locator('html')).toHaveAttribute('lang', locale === 'fr' ? 'fr-CA' : 'en-CA');67      await expect(page.locator('h1')).toHaveCount(1);68      await expect(page.locator('main')).toHaveCount(1);6970      // Titre et description uniques sur tout le site.71      const title = await page.title();72      expect(title.length).toBeGreaterThan(10);73      expect([...titles.entries()].filter(([p, t]) => t === title && p !== path)).toEqual([]);74      titles.set(path, title);75      const description = await page.locator('meta[name="description"]').getAttribute('content');76      expect(description?.length ?? 0).toBeGreaterThan(50);7778      // Canonical auto-référent et hreflang réciproques.79      const canonical = `https://www.agentilab.ai${path === '/' ? '' : path}`;80      await expect(page.locator('link[rel="canonical"]')).toHaveAttribute('href', canonical);81      for (const [tag, target] of [['fr-CA', href(id, 'fr')], ['en-CA', href(id, 'en')], ['x-default', href(id, 'fr')]] as const) {82        await expect(page.locator(`link[rel="alternate"][hreflang="${tag}"]`)).toHaveAttribute('href', `https://www.agentilab.ai${target === '/' ? '' : target}`);83      }84      await expect(page.locator('meta[property="og:image"]')).toHaveAttribute('content', /\/og\.png$/);85      await expect(page.locator('meta[property="og:image:alt"]')).toHaveAttribute('content', /AgentiLab/);86      await expect(page.locator('meta[name="robots"]')).toHaveCount(0);8788      // Données structurées valides.89      for (const raw of await page.locator('script[type="application/ld+json"]').allTextContents()) {90        expect(() => JSON.parse(raw)).not.toThrow();91      }9293      // Images : texte alternatif et dimensions explicites.94      for (const img of await page.locator('img').all()) {95        expect(await img.getAttribute('alt')).not.toBeNull();96        expect(await img.getAttribute('width')).not.toBeNull();97        expect(await img.getAttribute('height')).not.toBeNull();98      }99100      // Liens : jamais vides ; les liens sortants sont en HTTPS et protégés.101      for (const link of await page.locator('a').all()) {102        const target = await link.getAttribute('href');103        expect(target, 'lien sans destination').toBeTruthy();104        expect(target).not.toBe('#');105        if (target?.startsWith('http')) {106          expect(target).toMatch(/^https:\/\//);107          expect(await link.getAttribute('rel')).toContain('noopener');108        }109      }110111      await page.waitForLoadState('networkidle');112      expect(problems).toEqual([]);113    });114115    test('accessibilité (axe, WCAG 2.1 AA)', async ({ page }) => {116      // Sans animation : axe mesure les contrastes sur l’état final, non sur un fondu en cours.117      await page.emulateMedia({ reducedMotion: 'reduce' });118      await page.goto(path);119      const results = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'best-practice']).analyze();120      expect(results.violations.map((v) => `${v.id}: ${v.nodes.map((n) => n.target).join(' | ')}`)).toEqual([]);121    });122  });123}124
Files main
Menu

Theme