diff --git a/tests/browser_test.mjs b/tests/browser_test.mjs index 4c7da4e..79eeb22 100644 --- a/tests/browser_test.mjs +++ b/tests/browser_test.mjs @@ -24,6 +24,7 @@ const chrome=spawn(process.env.CHROME_BIN||'/usr/bin/google-chrome-stable',[ const pause=ms=>new Promise(r=>setTimeout(r,ms)); let stderr='';chrome.stderr.on('data',data=>stderr+=data.toString()); const clients=[]; +let kanban,testMachine; async function waitFor(fn,description,timeout=30000){const end=Date.now()+timeout;while(Date.now()q.approved.items[0].total_cents)`),itemCents); - const kanban=await page(kanbanOrigin); + kanban=await page(kanbanOrigin); await kanban.fill('#email',process.env.OPERATOR_EMAIL||'operator@example.test'); await kanban.fill('#password',process.env.OPERATOR_PASSWORD||'local-operator-only'); await kanban.eval('document.getElementById("login").requestSubmit()'); // Quotes live in their own tab; an automatic approval is listed as such. await waitFor(()=>kanban.eval('!document.getElementById("app").hidden'),'Kanban sign-in'); + // The test makes its own machine, so it runs on a fresh database and on its own. + testMachine=await kanban.eval(`api('/machines',{name:'Browser test '+Date.now(),products:['textil']}).then(r=>r.id)`); + await kanban.eval('load(true)'); + await waitFor(()=>kanban.eval(`board.machines.some(m=>m.id===${JSON.stringify(testMachine)})`),'test machine on the board'); assert.equal(await kanban.eval('sessionStorage.getItem("dtf-operator")'),null); assert.equal(await kanban.eval('document.getElementById("password").value'),''); await kanban.click('[data-tab="site"]'); @@ -222,9 +227,9 @@ try{ await waitFor(()=>kanban.eval(`!!document.querySelector('[data-order="${oid}"] [data-move]')`),'order panel'); // The Prumo report is on the card before the designer opens the file. await waitFor(()=>kanban.eval(`!!document.querySelector('[data-order="${oid}"] .prumo')`),'Prumo report'); - // No machine at payment (Dropstar, 2026-11-05): the pull chooses one. - await waitFor(()=>kanban.eval(`board.machines.some(m=>m.active&&m.products.includes('textil'))`),'a textile machine'); - const machineId=await kanban.eval(`board.machines.find(m=>m.active&&m.products.includes('textil')).id`); + // No machine at payment (Dropstar, 2026-11-05): the pull chooses one. It is + // the machine this test made after sign-in. + const machineId=testMachine; await kanban.eval(`(()=>{const s=document.querySelector('[data-order="${oid}"] select[aria-label="Máquina do pedido"]'); s.value=${JSON.stringify(machineId)};s.dispatchEvent(new Event('change',{bubbles:true}));})()`); await waitFor(()=>kanban.eval(`board.orders.find(o=>o.id==='${oid}').machine?.id===${JSON.stringify(machineId)}`),'machine chosen'); @@ -368,4 +373,10 @@ try{ console.log('Screenshots: output/local/site.png and output/local/kanban.png'); console.log('PASS: filename XSS escaping with CSP bypassed, no stored operator password, logout clears browser file blobs.'); }catch(error){console.error(error);if(stderr)console.error(stderr.slice(-1500));process.exitCode=1;} -finally{for(const p of clients)p.ws.close();chrome.kill();} +finally{ + if(testMachine&&kanban){ + try{await kanban.eval(`api('/machines/'+${JSON.stringify(testMachine)}+'/delete',{})`);} + catch(e){console.error('Could not delete the test machine '+testMachine+':',e.message||e);} + } + for(const p of clients)p.ws.close();chrome.kill(); +}