Files
Investidor-V2/tools/portal-functional-lease-qa.cjs
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

28 lines
6.5 KiB
JavaScript

// The remaining lease editor criteria only; never modify the demonstrated sale case.
const {start,assert,sanitized}=require('./portal-functional-qa-lib.cjs');
void(async()=>{
const q=await start('functional-lease-editor-chromium-20261011');let ctx,page,id=q.prior.opportunity_id;
const title='Arrendamento — SIMULAÇÃO QA 11/10/2026, sem efeito jurídico';
const field=path=>page.locator(`[id="canonical.real_estate.${path}"]`);
async function actor(){if(ctx)await ctx.close();({ctx,page}=await q.context('promoter'));await q.login(page,'promoter');}
async function props(r){const html=await r.text(),attr=html.match(/data-page="([^"]+)"/);const raw=attr&&attr[1].startsWith('{')?attr[1].replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&#039;/g,"'"):html.match(/<script[^>]*type="application\/json"[^>]*>([\s\S]*?)<\/script>/)?.[1];return JSON.parse(raw).props;}
async function open(){const r=await q.open(page,`/minhas-oportunidades/${id}/edit`);assert.equal(r.status(),200);await field('transaction_type').waitFor();return props(r);}
async function save(status=200){await page.getByLabel('Motivo da alteração',{exact:true}).fill('Ensaio QA da variante arrendamento: rascunho incompleto recuperável e erros acessíveis junto à renda.');const pending=page.waitForResponse(r=>['POST','PUT'].includes(r.request().method())&&/^\/minhas-oportunidades\/(drafts|\d+\/draft)$/.test(new URL(r.url()).pathname));await page.getByRole('button',{name:'Guardar contrato no rascunho',exact:true}).click();const r=await pending,body=await r.json();assert.equal(r.status(),status);return body;}
try{
await actor();q.phase('Lease draft through the Promotor dashboard');
if(process.argv.includes('--recover-final')){assert(id&&q.prior.result==='passed');const p=await open();assert.equal(p.values.canonical.real_estate.rent,4500);assert.equal(await field('rent').inputValue(),'4500');assert.equal(await field('rent_periodicity').inputValue(),'monthly');await field('rent').focus();await field('rent').scrollIntoViewIfNeeded();await q.shot(page,'lease-values-recovered-visible',false);q.proof.checks={...q.prior.checks,corrected_values_visible_in_new_session:true};q.proof.creation_options=q.prior.creation_options;q.proof.opportunity_id=id;q.proof.pending=q.prior.pending;q.proof.AB_C37_not_repeated=true;q.proof.original_sale_case_31_preserved=true;q.proof.result='passed';q.save();console.log(JSON.stringify({result:'passed',opportunity_id:id,visible_recovery:true,mutation_requests:0,active_writes:0}));return;}
if(!id){await page.getByRole('link',{name:'Minhas oportunidades',exact:true}).first().click();await page.getByRole('link',{name:'Nova oportunidade',exact:true}).first().click();await page.waitForURL(/\/minhas-oportunidades\/create$/);const context=page.getByRole('combobox',{name:/^Organização e tipo autorizados/});await context.waitFor();q.proof.creation_options=await context.locator('option').evaluateAll(rows=>rows.map(o=>({value:o.value,label:o.textContent})));assert.equal(new Set(q.proof.creation_options.map(o=>o.value)).size,q.proof.creation_options.length,'One visible option per organization/category, despite multiple grants');q.proof.checks.creation_contexts_deduplicated=true;q.save();await context.locator('option[value$="|real_estate"]').first().waitFor({state:'attached'});const option=await context.locator('option[value$="|real_estate"]').first().getAttribute('value');assert(option,'Authorized real_estate context must already exist');await context.selectOption(option);
await page.locator('[id="canonical.official_title"]').fill(title);await field('transaction_type').selectOption('lease');
const saved=await save(201);id=saved.id;q.proof.opportunity_id=id;q.save();await page.waitForURL(new RegExp(`/minhas-oportunidades/${id}/edit$`));
}
let p=await open();assert.equal(p.values.canonical.real_estate.transaction_type,'lease');assert.equal(p.values.canonical.official_title,title);assert.equal(p.workflowState,'draft');assert(!p.values.canonical.real_estate.rent);q.proof.checks.incomplete_draft_saved=true;
await actor();p=await open();assert.equal(p.values.canonical.real_estate.transaction_type,'lease');assert.equal(p.workflowState,'draft');q.proof.checks.incomplete_draft_new_session=true;await q.shot(page,'lease-incomplete-recovered',false);
q.phase('Lease amount error beside the field');await field('rent').fill('-1');const rejected=await save(422);assert(rejected.errors['canonical.real_estate.rent']);const rent=field('rent');assert.equal(await rent.getAttribute('aria-invalid'),'true');assert.equal(await rent.getAttribute('aria-describedby'),'canonical.real_estate.rent-error');assert(await page.locator('[id="canonical.real_estate.rent-error"]').isVisible());assert.equal(await rent.inputValue(),'-1');q.proof.checks.rent_error_near_field=true;q.proof.checks.unsaved_input_preserved=true;await q.shot(page,'lease-rent-error',false);
await q.open(page,`/minhas-oportunidades/${id}/edit`);assert.notEqual(await field('rent').inputValue(),'-1');q.proof.checks.invalid_value_not_persisted=true;
await field('rent').fill('4500');await field('rent_periodicity').selectOption('monthly');await save();await actor();p=await open();assert.equal(p.values.canonical.real_estate.rent,4500);assert.equal(p.values.canonical.real_estate.rent_periodicity,'monthly');assert.equal(p.workflowState,'draft');q.proof.checks.corrected_values_new_session=true;
const api=await q.json(page,`/minhas-oportunidades/${id}/response`);assert.equal(api.status,200);q.proof.checks.response_recovered=true;
await q.shot(page,'lease-corrected-recovered',false);q.proof.pending=['Submissão/revisão/publicação específicas de arrendamento; o rascunho incompleto não constitui contrato ou direito real.'];q.proof.original_sale_case_31_preserved=true;q.proof.AB_C37_not_repeated=true;q.proof.result='passed';q.save();console.log(JSON.stringify({result:'passed',opportunity_id:id,checks:q.proof.checks,active_writes:0}));
}catch(e){q.proof.result='failed';q.proof.failure=sanitized(e);if(page&&!page.isClosed()){q.proof.last_route=new URL(page.url()).pathname;if(q.proof.last_route==='/minhas-oportunidades/create'){q.proof.create_ui_summary=(await page.locator('main').innerText()).slice(0,2400);const r=await q.open(page,'/minhas-oportunidades/create'),p=await props(r);q.proof.create_server_props={profileMode:p.profileMode,record:p.record,contexts:p.profileAccess?.contexts};await q.shot(page,'lease-create-diagnosis',false);}}q.save();console.log(JSON.stringify({result:'failed',failure:q.proof.failure,route:q.proof.last_route,active_writes:0}));process.exitCode=1;}
finally{if(ctx)await ctx.close();await q.browser.close();}
})();