8 lines
3.0 KiB
JavaScript
8 lines
3.0 KiB
JavaScript
import fs from'node:fs';import assert from'node:assert/strict';import{parsePage,installDom,Element}from'./purchasing-workspace-dom.mjs';import{session}from'./sgf-single-http.mjs';
|
|
const nativeFetch=globalThis.fetch;const s=await session('purchasing:validator','stock');let r=await s.get('/stock/final',{headers:{Accept:'text/html'}});assert.equal(r.status,200);const html=await r.text(),document=parsePage(html);installDom(document);document.body=document.querySelector('body');document.getElementById=id=>document.querySelector('#'+id);globalThis.window={addEventListener(){}};let posted=0,confirmations=0;const calls=[];
|
|
globalThis.fetch=async(url,options)=>{if(url.startsWith('http:'))return nativeFetch(url,options);calls.push({url,body:options.body});if(url.endsWith('/confirm')){confirmations++;if(confirmations===1)throw Error('Simulated lost response');return{status:200,json:async()=>({replayed:true,operation_id:999999})};}if(options.method==='POST'){posted++;const q=await s.command(url,JSON.parse(options.body));return {status:q.status,json:async()=>q.value};}const q=await s.get(url);return {status:q.status,json:()=>q.json()};};
|
|
await import('../public/sgf-stock-final.mjs?dom-http');const $=id=>document.getElementById(id);const wait=async predicate=>{const deadline=Date.now()+15000;while(!predicate()&&Date.now()<deadline)await new Promise(r=>setTimeout(r,25));assert(predicate(),$('message').textContent);};await wait(()=>$('action').children.length>1);assert.equal($('action').value,'');assert.match($('summary').textContent,/0,5|0.5/);assert.match($('summary').textContent,/3,5|3.5/);await wait(()=>$('history').children.length>0);
|
|
$('action').value='count';$('action').onchange();$('quantity').value='3.500';const lots=$('inputs').querySelectorAll('input').filter(i=>i.id.startsWith('count'));assert.equal(lots.length,2);lots[0].value='1.500';lots[1].value='2.000';$('reason').value='Conferência DOM→HTTP sintética sem nova contagem confirmada.';await $('operation').onsubmit({preventDefault(){}});assert.equal(posted,1);assert.equal($('confirm').hidden,false);assert.match($('impact').textContent,/3500/);assert($('fields').disabled);
|
|
await $('confirm').onclick();assert($('retry').hidden===false);assert($('fields').disabled);const first=calls.filter(c=>c.url.endsWith('/confirm'))[0];await $('retry').onclick();assert.equal(confirmations,2);assert.equal(calls.filter(c=>c.url.endsWith('/confirm'))[1].body,first.body);assert.match($('receipt').textContent,/Recibo recuperado/);assert.equal($('fields').disabled,false);
|
|
delete globalThis.document;delete globalThis.window;const run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),file=run.root+'/private/receipt-composition-cc50a276c10c/stock-final-dom-http-20261110.json';fs.writeFileSync(file,JSON.stringify({passed:true,checks:10,real_http:['authenticated screen','current page','audit history','count preview with rollback'],confirmation_is_simulated:true,business_commands_confirmed:0,browser_visual_review:false},null,2));console.log(JSON.stringify({passed:true,checks:10,proof:file}));
|