import {test,expect} from '@playwright/test'; test('parcours réel : profils, paramètres, méthode, journal et mobile',async({page})=>{ const errors=[];page.on('pageerror',e=>errors.push(e.message)); await page.goto('/#simulateur');await expect(page.locator('#sim-metrics')).toBeVisible(); const numbers=[]; for(const profile of ['chat','dev','agent','team']){ await page.locator(`[data-profile="${profile}"]`).click();numbers.push(await page.locator('#sim-metrics').innerText()); } expect(new Set(numbers).size).toBe(4); await page.locator('[data-profile="chat"]').click();const initial=await page.locator('#sim-metrics').innerText(); await page.locator('#requests').fill('16');await expect(page.locator('#sim-metrics')).not.toHaveText(initial); await page.locator('#sim-metrics .metric').first().click();await expect(page.locator('dialog')).toBeVisible();await expect(page.locator('#assumptions-content')).toContainText('Wh / 1 000 tokens');await page.getByRole('button',{name:'Fermer les hypothèses'}).click(); await page.locator('#mix').selectOption('custom');await page.locator('#customLow').fill('100');await expect(page.locator('#scenario-error')).toContainText('bas ≤ central ≤ haut');await page.locator('#customLow').fill('50'); await page.locator('nav a[href="#methode"]').click();await expect(page.locator('#methode')).toBeVisible();await expect(page.locator('#methode')).toContainText('Quatre constats du Shift');await expect(page.locator('#methode')).toContainText('CC BY-NC'); await page.locator('nav a[href="#fabrication"]').click();await expect(page.locator('#fabrication')).toBeVisible();await expect(page.locator('#fabrication')).toContainText('messages assistant réellement journalisés');await expect(page.locator('svg.graph')).toBeVisible(); const data=await (await page.request.get('/data/usage.jsonl')).text();expect(JSON.parse(data.trim().split('\n')[0]).message_id).toBe('f9ee8358'); await page.setViewportSize({width:390,height:844}); for(const id of ['simulateur','fabrication','methode']){ await page.locator(`nav a[href="#${id}"]`).click();expect(await page.evaluate(()=>document.documentElement.scrollWidth<=window.innerWidth)).toBe(true); } expect(errors).toEqual([]); }); test('contribution externe : ajout local, persistance et export',async({page})=>{ await page.goto('/#fabrication');await expect(page.locator('#contribution-form')).toBeVisible(); const form=page.locator('#contribution-form'); for(const [key,value]of Object.entries({low:'10',central:'20',high:'30',provenance:'Relevé fourni par un testeur',justification:'Fourchette manuelle de test'}))await form.locator(`[name="${key}"]`).fill(value); await form.getByRole('button',{name:'Ajouter à mon aperçu local'}).click();await expect(page.locator('#contribution-status')).toContainText('ajoutée'); await expect(page.locator('.local-label')).toBeVisible();await page.reload();await expect(page.locator('.local-label')).toBeVisible(); const download=page.waitForEvent('download');await page.locator('#export-local').click();expect((await download).suggestedFilename()).toBe('contributions-locales.json'); await page.locator('#include-local').uncheck();await expect(page.locator('.local-label')).toHaveCount(0); }); test('import invalide refusé sans injection, accès clavier et aucune API distante',async({page})=>{ const external=[];page.on('request',r=>{if(!r.url().startsWith('http://127.0.0.1')&&!process.env.TEST_BASE_URL?.startsWith(new URL(r.url()).origin))external.push(r.url());}); await page.goto('/#fabrication');await expect(page.locator('#import-local')).toBeVisible(); await page.locator('#import-local').setInputFiles({name:'bad.json',mimeType:'application/json',buffer:Buffer.from(JSON.stringify([{id:'bad',mode:'wh',wh:[3,2,1]}]))}); await expect(page.locator('#contribution-status')).toContainText('Import refusé'); await page.locator('[data-assumptions]').filter({visible:true}).first().focus();await page.keyboard.press('Enter');await expect(page.locator('dialog')).toBeVisible();await page.keyboard.press('Escape');await expect(page.locator('dialog')).not.toBeVisible(); expect(external).toEqual([]); });