import {test,expect} from '@playwright/test'; const disclaimer='Estimation à partir de votre usage et des hypothèses de calcul.'; async function choose(page,ids=['question']){await page.goto('/');await expect(page.locator('#guide-tasks')).toBeVisible();for(const id of ids)await page.locator(`#guide-tasks input[value="${id}"]`).check();await page.getByRole('button',{name:'Décrire mon usage'}).click();} async function finish(page){await page.getByRole('button',{name:'Voir mon résultat'}).click();await expect(page.locator('.result-overview')).toBeVisible();} async function checkFirstScreen(page){ await expect(page.locator('.simple-metric')).toHaveCount(3);await expect(page.locator('.calculation-link p')).toHaveText(disclaimer); await expect(page.locator('.simple-metric[data-kind="wh"]')).toContainText('Électricité des serveurs'); await expect(page.locator('.simple-metric[data-kind="carbon"]')).toContainText('Émissions liées à cette électricité'); const text=await page.locator('#comprendre').innerText();expect(text).not.toMatch(/au central|\d[.,]?\d*[eE][+-]\d|verres de|minutes de four/); expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true); const rect=await page.locator('.change-sentence').boundingBox();expect(rect.y+rect.height).toBeLessThanOrEqual(844); } for(const id of ['chat','dev','agent','team'])test(`profil ${id} : jour/année, mobile/ordinateur, action et annulation`,async({page})=>{ const errors=[];page.on('pageerror',e=>errors.push(e.message));await page.goto('/');await page.locator('.guide-presets summary').click();await page.locator(`[data-guide-profile="${id}"]`).click(); await expect(page.locator('.comparison')).toHaveCount(0);await expect(page.locator('.usage-line')).toContainText(id==='team'?'10 personnes':'1 personne'); const rawBefore=await page.locator('.simple-metric[data-kind="wh"]').getAttribute('data-exact'); await page.locator('#refine-results summary').click();await page.getByRole('button',{name:'Actualiser mon estimation'}).click();await expect(page.locator('.comparison')).toHaveCount(0);await expect(page.locator('[data-kind="wh"]')).toHaveAttribute('data-exact',rawBefore); for(const width of [390,1440]){await page.setViewportSize({width,height:844});for(const p of ['daily','annual']){await page.locator(`[data-guide-period="${p}"]`).click();await page.evaluate(()=>scrollTo(0,0));await checkFirstScreen(page);await expect(page.locator('.metric-period').first()).toHaveText(p==='annual'?'par an':'par jour d’usage');}} const before=await page.locator('.simple-metric[data-kind="wh"] .world-number').innerText(); await page.locator('.primary-change [data-decision]').click();await expect(page.locator('.comparison')).toBeVisible();await expect(page.locator('.simple-metric[data-kind="wh"] .world-number')).not.toHaveText(before); await page.locator('#reset-guide').click();await expect(page.locator('.comparison')).toHaveCount(0);await expect(page.locator('.simple-metric[data-kind="wh"]')).toHaveAttribute('data-exact',rawBefore); await page.getByRole('button',{name:'Voir le calcul',exact:true}).click();await expect(page.locator('dialog')).toContainText('Valeurs complètes avant arrondi');await expect(page.locator('dialog')).toContainText('exclu');await page.keyboard.press('Escape');expect(errors).toEqual([]); }); test('questions + 2 h d’agent : durée déclarée, appels supposés et action directe sur l’incertitude',async({page})=>{ await choose(page,['question','agent']);await page.locator('[name="agent-volume"]').fill('2');await page.locator('[name="disjoint"]').check();await finish(page); await expect(page.locator('.usage-line')).toContainText('Questions');await expect(page.locator('.usage-line')).toContainText('2 h/j'); await expect(page.locator('.assumption-pointer')).toContainText('2 h par séance');await expect(page.locator('.assumption-pointer')).toContainText('24 appels supposés'); await page.getByRole('button',{name:'Ajuster les appels supposés'}).click();await expect(page.locator('#refine-results')).toHaveAttribute('open','');await expect(page.locator('#refine-form [name="agent-cadence"]')).toBeFocused(); await page.locator('#refine-form [name="agent-cadence"]').fill('20');await page.getByRole('button',{name:'Actualiser mon estimation'}).click();await expect(page.locator('.assumption-pointer')).toContainText('40 appels supposés');await expect(page.locator('.comparison')).toBeVisible(); await page.locator('#reset-guide').click();await expect(page.locator('.comparison')).toHaveCount(0); for(const width of [320,390,1440]){await page.setViewportSize({width,height:844});for(const p of ['daily','annual']){await page.locator(`[data-guide-period="${p}"]`).click();await page.evaluate(()=>scrollTo(0,0));await checkFirstScreen(page);}} }); test('hypothèse la plus influente modifiable, inconnues et coefficient explicite sans masquer les bornes',async({page})=>{ await choose(page);await page.locator('[name="question-unknown"]').check();await finish(page); await page.getByRole('button',{name:'Modifier cette hypothèse'}).click();await expect(page.locator('#refine-results')).toHaveAttribute('open',''); expect(await page.evaluate(()=>document.activeElement?.closest('#refine-form')!==null)).toBe(true); const before=JSON.parse(await page.locator('[data-kind="wh"]').getAttribute('data-exact')); await page.locator('#refine-form [name="question-energyScale"]').fill('2');await page.getByRole('button',{name:'Actualiser mon estimation'}).click(); const after=JSON.parse(await page.locator('[data-kind="wh"]').getAttribute('data-exact'));for(let i=0;i<3;i++)expect(after[i]).toBeCloseTo(before[i]*2,8); await page.locator('#reset-guide').click();await expect(page.locator('.comparison')).toHaveCount(0); }); test('avancé et guide synchronisés, périmètres eau non assimilés à une économie',async({page})=>{ await choose(page);await finish(page);const before=await page.locator('[data-kind="wh"]').getAttribute('data-exact'); await page.locator('#refine-results summary').click();await page.locator('[data-guide-advanced="question"]').click();await page.locator('#requests').fill('80');await page.locator('nav a[href="#comprendre"]').click(); await expect(page.locator('.comparison')).toBeVisible();await page.locator('#reset-guide').click();await expect(page.locator('[data-kind="wh"]')).toHaveAttribute('data-exact',before); await page.locator('#refine-results summary').click();await page.locator('#refine-form [name="refine-water"]').selectOption('total');await page.getByRole('button',{name:'Actualiser mon estimation'}).click(); await expect(page.locator('[data-kind="water"]')).toContainText('refroidissement + électricité');await expect(page.locator('.comparison')).toContainText('Non comparable'); }); test('accueil et quatre pages sans API distante sur mobile ; données CLEER conservées',async({page})=>{ const external=[],base=process.env.TEST_BASE_URL||'http://127.0.0.1:4173';page.on('request',r=>{if(new URL(r.url()).origin!==new URL(base).origin)external.push(r.url());});await page.setViewportSize({width:390,height:844});await page.goto('/'); for(const id of ['comprendre','simulateur','fabrication','methode']){await page.locator(`nav a[href="#${id}"]`).click();await expect(page.locator('#'+id)).toBeVisible();expect(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)).toBe(true);} await page.locator('#method-cleer summary').click();await expect(page.locator('#method-cleer')).toContainText('permission séparée');expect(external).toEqual([]); });