30 lines
11 KiB
JavaScript
30 lines
11 KiB
JavaScript
const {chromium}=require('C:/Users/macbook/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
|
|
const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict');
|
|
const DIR=path.resolve('outputs/presentation-qa-20261121'),BASE='http://127.0.0.3:18724';
|
|
(async()=>{const b=await chromium.launch({headless:true,executablePath:'C:/Users/macbook/AppData/Local/ms-playwright/chromium-1243/chrome-win64/chrome.exe'});const result={scope:'Presentation only, isolated QA',errors:[],pages:[],v13:[],filters:[],actions:[]};
|
|
const context=async opts=>{const c=await b.newContext(opts);c.setDefaultTimeout(15000);c.setDefaultNavigationTimeout(20000);await c.route('**/*',r=>new URL(r.request().url()).origin===BASE?r.continue():r.abort());return c;};
|
|
try{
|
|
for(const mobile of [false,true]){const c=await context({viewport:mobile?{width:390,height:844}:{width:1440,height:1000}});const p=await c.newPage();p.on('pageerror',e=>result.errors.push(e.message));
|
|
const routes=['/carteira','/carteira?kind=cluster','/zonas','/oportunidades','/negocios','/clusters','/corredores','/formularios/fiscais','/formularios/fiscais?imposto=irpc','/documentos','/apoio'];
|
|
const details=new Set(['/carteira/dc8892ff-fdda-480c-81f1-2ffe0bfcb40b','/carteira/b30ecd8c-220d-4c7a-b1a7-704dc24d0933','/zonas/dc40c57e-a799-44d5-813c-5b80a83481dc','/zonas/0047f8a8-f3e0-402c-adb8-1d87476480ca']);
|
|
for(const route of routes){console.log(mobile,route);const r=await p.goto(BASE+route,{waitUntil:'domcontentloaded'});if(r.status()===404){result.pages.push({route,mobile,status:404});continue;}assert.equal(r.status(),200,route);await p.locator('h1').first().waitFor();await p.waitForTimeout(300);const root=p.locator('#portal-content');const text=await root.textContent();assert.doesNotMatch(text,/\bCOR-0[1-6]\b|resources\/js\/|C:\\laragon\\/);if(route.startsWith('/formularios/fiscais'))assert.doesNotMatch(text,/Exemplar e cobertura|SHA256:|\.xlsx|\.xlsm/);const overflow=await p.evaluate(()=>({body:document.documentElement.scrollWidth,width:innerWidth}));assert.ok(overflow.body<=overflow.width+1,JSON.stringify({route,mobile,overflow}));
|
|
if(!mobile){const nav=root.locator('nav[aria-label^="Acções de"]').first();if(await nav.count()){for(const href of await nav.locator('a').evaluateAll(a=>a.map(e=>e.getAttribute('href')))){assert.ok(href.startsWith('/')&&!href.startsWith('//'));const response=await c.request.get(BASE+href);assert.equal(response.status(),200,href);result.actions.push({from:route,href,status:200});}}}const links=await root.locator('a').evaluateAll(a=>a.map(x=>x.getAttribute('href')).filter(x=>x&&/^\/(?:carteira|zonas|oportunidades)\/[^/?]+/.test(x)));for(const href of links.slice(0,2))details.add(href);
|
|
result.pages.push({route,mobile,status:r.status(),overflow,textLength:text.length,groupedActions:await root.locator('nav[aria-label^="Acções de"]').count()});if(['/carteira','/zonas','/oportunidades'].includes(route)&&await root.locator('article').count())await root.locator('article').first().scrollIntoViewIfNeeded();if(['/carteira','/zonas','/oportunidades'].includes(route))await p.screenshot({path:path.join(DIR,`${mobile?'mobile':'desktop'}-${route.slice(1)}.png`)});
|
|
}
|
|
for(const route of details){console.log(mobile,route);const r=await p.goto(BASE+route,{waitUntil:'domcontentloaded'});await p.locator('h1').first().waitFor();const text=await p.locator('#portal-content').textContent();assert.doesNotMatch(text,/\bCOR-0[1-6]\b|resources\/js\/|C:\\laragon\\/);const bounds=await p.evaluate(()=>({body:document.documentElement.scrollWidth,width:innerWidth}));assert.ok(bounds.body<=bounds.width+1,JSON.stringify({route,mobile,bounds}));result.pages.push({route,mobile,status:r.status(),bounds});}
|
|
await p.goto(BASE+'/zonas?category=industrial_park&q=Balama&activity=');await p.locator('h1').first().waitFor();assert.match(await p.locator('select[name="category"] option[value="zee"]').textContent(),/registos/);const link=p.getByRole('link',{name:'Consultar ficha',exact:true}).first();const destination=new URL(await link.getAttribute('href'),BASE).href;await Promise.all([p.waitForURL(destination),link.click()]);const back=p.getByRole('link',{name:'Voltar à pesquisa',exact:true});await back.waitFor();result.filters.push({mobile,detail:p.url(),back:await back.getAttribute('href')});assert.match(await back.getAttribute('href'),/category=industrial_park/);assert.match(await back.getAttribute('href'),/q=Balama/);const returnUrl=new URL(await back.getAttribute('href'),BASE).href;await Promise.all([p.waitForURL(u=>u.pathname===new URL(returnUrl).pathname&&[...new URL(returnUrl).searchParams].every(([k,v])=>u.searchParams.get(k)===v)),back.click()]);assert.equal(await p.locator('select[name="category"]').inputValue(),'industrial_park');assert.equal(await p.locator('input[name="q"]').inputValue(),'Balama');await p.locator('summary').filter({hasText:'Mais filtros'}).click();await p.locator('input[name="activity"]').fill('energia');await p.waitForURL(u=>u.searchParams.get('activity')==='energia');assert.equal(await p.locator('select[name="category"]').inputValue(),'industrial_park');await p.getByRole('link',{name:'Remover Actividade',exact:true}).click();await p.waitForURL(u=>!u.searchParams.has('activity'));assert.equal(await p.locator('input[name="q"]').inputValue(),'Balama');result.filters.push({mobile,activityRemovedWithoutLosingGroupOrText:true});
|
|
await c.close();}
|
|
console.log('V13');const c=await context({viewport:{width:1440,height:1000}});const p=await c.newPage();p.on('pageerror',e=>result.errors.push(e.message));await p.goto(BASE+'/login');await p.getByLabel('Email',{exact:true}).fill('qa-v13-presentation-20261121@example.invalid');await p.getByLabel('Palavra-passe',{exact:true}).fill('password');await Promise.all([p.waitForURL(BASE+'/dashboard'),p.getByRole('button',{name:'Entrar',exact:true}).click()]);
|
|
const seed=JSON.parse(fs.readFileSync(path.join(DIR,'seed.json'),'utf8').replace(/^\uFEFF/,''));const url=BASE+'/simulador-fiscal?draft='+seed.draft;
|
|
await p.goto(url);await p.getByRole('button',{name:'5. Investimento e financiamento',exact:true}).click();
|
|
const help=async()=>{const ch=p.getByRole('checkbox',{name:'Orientações automáticas neste navegador'});if(await ch.isVisible())await ch.uncheck();const close=p.getByRole('button',{name:'Fechar ajuda',exact:true});if(await close.isVisible())await close.click();};await help();
|
|
const funding=p.getByText('Plano financeiro empresarial (pressupostos editáveis)',{exact:true});if(!await p.getByRole('button',{name:'Exportar plano JSON',exact:true}).isVisible())await funding.click();await help();
|
|
const exp=async name=>{const [d]=await Promise.all([p.waitForEvent('download'),p.getByRole('button',{name:'Exportar plano JSON',exact:true}).click()]);const data=JSON.parse(fs.readFileSync(await d.path(),'utf8'));fs.writeFileSync(path.join(DIR,name+'.json'),JSON.stringify(data,null,2));return data;};
|
|
console.log('export initial');const before=await exp('v13-before');const details=p.locator('summary').filter({hasText:'Crescimento, despesas discriminadas, capital e dividendos'}).locator('..');await details.locator('summary').click();await p.getByRole('checkbox',{name:'Discriminar o capital introduzido',exact:true}).check();await p.getByLabel('Capital do proprietário',{exact:true}).fill('700');await p.getByLabel('Capital do investidor',{exact:true}).fill('0');await p.getByLabel('Capital adicional angariado',{exact:true}).fill('0');await p.getByLabel('Capital próprio',{exact:true}).fill('600');
|
|
const summary=p.getByRole('region',{name:'Falta preencher ou corrigir',exact:true});await summary.waitFor();console.log(await summary.innerText());await details.locator('summary').click();await summary.scrollIntoViewIfNeeded();await p.screenshot({path:path.join(DIR,'v13-summary-desktop.png')});await summary.getByRole('link',{name:/^Capital do proprietário(?: —|$)/}).first().click();assert.notEqual(await details.getAttribute('open'),null);assert.equal(await p.getByLabel('Capital do proprietário',{exact:true}).evaluate(e=>document.activeElement===e),true);result.v13.push({case:'diagnostic opens closed section and focuses actual field',passed:true});
|
|
await p.getByLabel('Capital do proprietário',{exact:true}).fill('600');await p.waitForTimeout(300);const after=await exp('v13-after');const expected=structuredClone(before);expected.plan.fundingBreakdown={ownerCapital:'600',investorCapital:'0',additionalCapital:'0'};expected.plan.equity='600.00';assert.deepEqual(after,expected);result.v13.push({case:'navigation preserves all financial values; only explicit synthetic input differs',passed:true});
|
|
assert.equal(await summary.getByText(/capital discriminado/i).count(),0);await p.screenshot({path:path.join(DIR,'v13-desktop.png')});
|
|
await p.getByLabel('Capital do proprietário',{exact:true}).fill('700');await p.getByLabel('Capital próprio',{exact:true}).fill('600');await p.setViewportSize({width:390,height:844});await details.locator('summary').click();const target=summary.getByRole('link',{name:/^Capital do proprietário(?: —|$)/}).first();await target.focus();await p.keyboard.press('Enter');assert.equal(await p.getByLabel('Capital do proprietário',{exact:true}).evaluate(e=>document.activeElement===e),true);await p.screenshot({path:path.join(DIR,'v13-mobile.png')});result.v13.push({case:'mobile keyboard link opens and focuses field',passed:true});await p.getByLabel('Capital do proprietário',{exact:true}).fill('600');
|
|
await p.getByRole('navigation',{name:'Etapas do formulário',exact:true}).getByRole('button').last().click();await help();await p.getByRole('button',{name:'Validar este rascunho',exact:true}).click();const pending=p.locator('li > button').filter({hasText:/:/}).first();const pendingText=await pending.innerText();const reviewStep=await p.locator('[aria-current="step"]').innerText();await pending.click();await p.waitForTimeout(200);const active=await p.evaluate(()=>({tag:document.activeElement.tagName,id:document.activeElement.id,field:document.activeElement.closest('[id^="field-"]')?.id}));assert.ok(['INPUT','SELECT','TEXTAREA','BUTTON'].includes(active.tag),JSON.stringify(active));assert.ok(active.field,JSON.stringify(active));assert.notEqual(await p.locator('[aria-current="step"]').innerText(),reviewStep);result.v13.push({case:'final review changes step and focuses the real control',pendingText,active});await c.close();assert.equal(result.errors.length,0);result.status='presentation demonstrated in QA';fs.writeFileSync(path.join(DIR,'functional-receipt.json'),JSON.stringify(result,null,2));console.log(JSON.stringify(result));
|
|
}catch(e){fs.writeFileSync(path.join(DIR,'failed.json'),JSON.stringify({error:e.stack,result},null,2));throw e;}finally{await b.close()}})().catch(e=>{console.error(e.stack);process.exitCode=1});
|