From 122c645f725bf4a5d31fcd647b9671cb869f84cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 25 Sep 2026 11:04:23 -0300 Subject: [PATCH] fix: stop Site timers from running after a product is closed The grade check and the layout preview run on short timers. When the item went to the cart inside that window, no product was open and both threw in the customer's browser, which also failed the browser tests intermittently. Each now returns when no product is open. The cart test waits for the empty state, which is painted on the next animation frame. Co-Authored-By: Claude Opus 5.5 --- tests/browser_test.mjs | 2 ++ web/site-packing.js | 2 ++ web/site-quality.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/browser_test.mjs b/tests/browser_test.mjs index 03bd02d..b5c458b 100644 --- a/tests/browser_test.mjs +++ b/tests/browser_test.mjs @@ -87,6 +87,8 @@ try{ await waitFor(()=>site.eval(`location.pathname==='/carrinho' && getComputedStyle($('carr')).display!=='none' && getComputedStyle($('foco')).display==='none'`),'cart page'); // Removing an item is one click and can be undone. await site.click('[data-rmi="0"]'); + // The empty state is painted on the next animation frame (site-steps.js). + await waitFor(()=>site.eval(`!$('carrVazio').hidden||document.documentElement.hasAttribute('data-sem-itens')`),'empty cart state'); assert.deepEqual(await site.eval(`({items:pedido.length,empty:!$('carrVazio').hidden||document.documentElement.hasAttribute('data-sem-itens'),undo:!$('desfazer').hidden})`),{items:0,empty:true,undo:true}); await site.click('#desfazerBtn'); assert.equal(await site.eval('pedido.length===1 && pedido[0].total===21.89 && $("desfazer").hidden'),true); diff --git a/web/site-packing.js b/web/site-packing.js index e9a3124..e4d4f35 100644 --- a/web/site-packing.js +++ b/web/site-packing.js @@ -302,6 +302,8 @@ function previaAoVivo(){ return; } tMont=setTimeout(()=>{ + // o produto pode ter sido fechado nesses 140 ms (item foi para o carrinho) + if(!modo) return; const prontas=artes.filter(a=>a.cm>0 && a.cm<=larguraFilme() && a.src); const W=Math.round(300*ZOOMS[zoomI]); $('vArea').classList.toggle('ampliado', zoomI>0); diff --git a/web/site-quality.js b/web/site-quality.js index 6c9c7d4..f7fcaac 100644 --- a/web/site-quality.js +++ b/web/site-quality.js @@ -88,6 +88,8 @@ let tAval=null; function agendaAvaliacao(){ clearTimeout(tAval); tAval=setTimeout(()=>{ + // o produto pode ter sido fechado nesses 220 ms (item foi para o carrinho) + if(!modo) return; const r=avaliar(); const el=$('aoVivo'); if(!el) return;