import {test,expect} from '@playwright/test'; import fs from 'node:fs'; const source=JSON.parse(fs.readFileSync('data/external-usage.json','utf8')); test.describe('lecture documentaire sans JavaScript',()=>{ test.use({javaScriptEnabled:false}); test('accueil et noscript : vrais liens, archive publique et contact lisibles',async({page})=>{ const r=await page.goto('/');expect(r.status()).toBe(200);await expect(page.locator('#app')).toContainText('empreinte de ses usages');await expect(page.locator('body')).not.toContainText('Chargement du journal'); await expect(page.locator('noscript a[href="/methode.html"]')).toBeVisible();await expect(page.locator('noscript a[href="/audit.html"]')).toBeVisible();await expect(page.locator('a[href="mailto:contact@gtbia.com"]')).toBeVisible(); await page.locator('#app a[href="/methode.html"]').click();await expect(page.getByRole('heading',{name:'Méthode, facteurs et limites',exact:true})).toBeVisible(); }); test('méthode HTML complète : sources, formules, licence et aucun script',async({page})=>{ const r=await page.goto('/methode.html');expect(r.status()).toBe(200);expect(r.headers()['content-type']).toContain('text/html');const html=await r.text();expect(html).not.toMatch(/document.documentElement.scrollWidth<=innerWidth)).toBe(true); }); test('journal HTML : un agrégat Claude, 33 requêtes et quatre comptes bruts',async({page})=>{ const r=await page.goto('/journal.html');expect(r.status()).toBe(200);expect(await r.text()).not.toMatch(/document.documentElement.scrollWidth<=innerWidth)).toBe(true); }); }); test('mêmes totaux statiques/interactifs ; doublon Claude importé sans ajout',async({page})=>{ const stat=await page.request.get('/journal.html');const html=await stat.text(),encoded=html.match(/data-total-wh="([^"]+)"/)[1];const expected=JSON.parse(encoded.replaceAll('"','"').replaceAll('&','&')); await page.goto('/#fabrication');await expect(page.locator('.external-details')).toContainText('33 requêtes agrégées'); const metrics=page.locator('#fabrication .white-metrics .metric').first(),unit=await metrics.getAttribute('data-unit'),values=JSON.parse(await metrics.getAttribute('data-values'));values.forEach((v,i)=>expect(unit==='kWh'?v*1000:v).toBeCloseTo(expected[i],8)); const before=await metrics.getAttribute('data-values');await page.locator('#import-local').setInputFiles({name:'claude.json',mimeType:'application/json',buffer:Buffer.from(JSON.stringify([source,source]))}); await expect(page.locator('#contribution-status')).toContainText('pas ajoutées une deuxième fois');await expect(metrics).toHaveAttribute('data-values',before);await expect(page.locator('.external-details')).toHaveCount(1);await expect(page.locator('.local-label')).toHaveCount(0); await page.locator('#import-local').setInputFiles({name:'cumul-nouveau.json',mimeType:'application/json',buffer:Buffer.from(JSON.stringify({...source,cutoff:'2026-11-14T14:53+01:00'}))});await expect(page.locator('#contribution-status')).toContainText('Import refusé');await expect(metrics).toHaveAttribute('data-values',before); });