All checks were successful
Build and deploy / Validate source (push) Successful in 47s
Build and deploy / Integration suite on a real stack (push) Successful in 3m38s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 1m20s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
171 lines
14 KiB
JavaScript
171 lines
14 KiB
JavaScript
// Screenshots for the guides, from the local stack seeded with fictional
|
|
// orders (seed.py). Runs in the browser-tests image: node shots.mjs <which>.
|
|
import {spawn} from 'node:child_process';
|
|
import {mkdtemp,readFile,writeFile,mkdir} from 'node:fs/promises';
|
|
import {tmpdir} from 'node:os';
|
|
|
|
const OUT='/shots';
|
|
const which=process.argv[2]||'kanban';
|
|
const profile=await mkdtemp(tmpdir()+'/dtf-shots-');
|
|
const chrome=spawn(process.env.CHROME_BIN||'/usr/bin/chromium',[
|
|
'--headless=new','--lang=pt-BR','--disable-gpu','--no-first-run','--no-sandbox','--hide-scrollbars','--font-render-hinting=none',
|
|
'--unsafely-treat-insecure-origin-as-secure=http://site,http://kanban',
|
|
'--remote-debugging-port=0','--user-data-dir='+profile,'about:blank'],{stdio:['ignore','ignore','pipe']});
|
|
const pause=ms=>new Promise(r=>setTimeout(r,ms));
|
|
async function waitFor(fn,what,timeout=30000){const end=Date.now()+timeout;while(Date.now()<end){try{if(await fn())return;}catch{}await pause(200);}throw new Error('Timeout: '+what);}
|
|
class Page{
|
|
constructor(ws){this.ws=ws;this.n=0;this.p=new Map();ws.onmessage=e=>{const d=JSON.parse(e.data);if(d.id&&this.p.has(d.id)){const x=this.p.get(d.id);this.p.delete(d.id);d.error?x.j(d.error):x.r(d.result);}};}
|
|
call(m,params={}){return new Promise((r,j)=>{const id=++this.n;this.p.set(id,{r,j});this.ws.send(JSON.stringify({id,method:m,params}));});}
|
|
async eval(e){const res=await this.call('Runtime.evaluate',{expression:e,awaitPromise:true,returnByValue:true});if(res.exceptionDetails)throw new Error(JSON.stringify(res.exceptionDetails).slice(0,400));return res.result.value;}
|
|
async size(w,h){await this.call('Emulation.setDeviceMetricsOverride',{width:w,height:h,deviceScaleFactor:2,mobile:false});await pause(300);}
|
|
async rect(selector,pad=0){return this.eval(`(()=>{const el=${selector.startsWith('(')?selector:`document.querySelector(${JSON.stringify(selector)})`};
|
|
const r=el.getBoundingClientRect();return {x:Math.max(0,r.left-${pad})+scrollX,y:Math.max(0,r.top-${pad})+scrollY,width:r.width+2*${pad},height:r.height+2*${pad}};})()`);}
|
|
async shot(name,clip){
|
|
const res=await this.call('Page.captureScreenshot',{format:'png',captureBeyondViewport:true,...(clip?{clip:{...clip,scale:1}}:{})});
|
|
await writeFile(`${OUT}/${name}.png`,Buffer.from(res.data,'base64'));console.log('shot',name,clip?Math.round(clip.width)+'x'+Math.round(clip.height):'page');
|
|
}
|
|
async el(name,selector,pad=0){await pause(250);await this.shot(name,await this.rect(selector,pad));}
|
|
}
|
|
let port;
|
|
await waitFor(async()=>{port=Number((await readFile(profile+'/DevToolsActivePort','utf8')).split('\n')[0]);return port;},'chrome');
|
|
async function open(url,w=1440,h=1000){
|
|
const tab=await (await fetch(`http://localhost:${port}/json/new?about:blank`,{method:'PUT'})).json();
|
|
const ws=new WebSocket(tab.webSocketDebuggerUrl);await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j;});
|
|
const p=new Page(ws);await p.call('Runtime.enable');await p.call('Page.enable');await p.size(w,h);
|
|
await p.call('Emulation.setLocaleOverride',{locale:'pt-BR'}).catch(()=>{});
|
|
await p.call('Network.enable').catch(()=>{});await p.call('Network.setUserAgentOverride',{userAgent:'Mozilla/5.0 Chrome/130 Safari/537.36',acceptLanguage:'pt-BR'}).catch(()=>{});
|
|
await p.call('Page.navigate',{url});await waitFor(()=>p.eval('document.readyState==="complete"'),'load '+url);await pause(800);return p;
|
|
}
|
|
await mkdir(OUT,{recursive:true});
|
|
|
|
try{
|
|
if(which==='kanban'){
|
|
const k=await open('http://kanban/',1440,1000);
|
|
await waitFor(()=>k.eval('!document.getElementById("login").hidden'),'login form');
|
|
await k.el('login','#login',24);
|
|
await k.eval(`(()=>{email.value=${JSON.stringify(process.env.OPERATOR_EMAIL||'operator@example.test')};password.value=${JSON.stringify(process.env.OPERATOR_PASSWORD||'local-operator-only')};
|
|
document.getElementById('login').requestSubmit();})()`);
|
|
await waitFor(()=>k.eval('typeof board!=="undefined"&&!!board&&board.orders.length>0'),'board');
|
|
// No refresh while shooting: the timer would repaint over the shots.
|
|
// No refresh while shooting: the timer would repaint over the shots.
|
|
await k.eval(`(()=>{window.load=async()=>{};})()`);
|
|
await pause(1500);
|
|
await k.shot('quadro',{x:0,y:0,width:1440,height:700});
|
|
const id=n=>`board.orders.find(o=>o.number===${n}).id`;
|
|
// The print queue column, top part.
|
|
await k.el('fila','(document.querySelector(\'section.col[data-state="fil"]\'))',0).catch(e=>console.log('fila',e.message));
|
|
// Panel of an order waiting for its final file.
|
|
await k.size(1440,1900);
|
|
await k.eval(`document.querySelector('[data-card="'+${id(11)}+'"]').click()`);
|
|
await waitFor(()=>k.eval(`!!document.querySelector('[data-order="'+${id(11)}+'"]')`),'panel');await pause(1200);
|
|
await k.shot('painel',{...(await k.rect('#panel')),height:900});
|
|
await k.el('arquivo-final','#panel .nextstep.lead',0);
|
|
await k.eval(`document.querySelector('#panel .more').click()`);await pause(300);
|
|
await k.shot('menu',{...(await k.rect('#panel')),height:520});
|
|
await k.eval(`document.body.click()`);
|
|
// An order in correction, and one whose correction came back.
|
|
for(const [n,name] of [[7,'correcao'],[8,'correcao-recebida'],[10,'contato']]){
|
|
await k.eval(`closePanel&&closePanel()`).catch(()=>{});await pause(300);
|
|
await k.eval(`document.querySelector('[data-card="'+${id(n)}+'"]').click()`);
|
|
await waitFor(()=>k.eval(`!!document.querySelector('[data-order="'+${id(n)}+'"]')`),'panel '+n);await pause(1200);
|
|
if(name==='correcao-recebida')await k.el(name,'#panel .nextstep.lead',0);
|
|
else if(name==='contato')await k.el(name,'#panel .callout.contact',0);
|
|
else await k.shot(name,{...(await k.rect('#panel')),height:350});
|
|
}
|
|
await k.eval(`closePanel&&closePanel()`).catch(()=>{});
|
|
await k.size(1440,1000);
|
|
// Quotes, payments, numbers.
|
|
await k.eval(`document.querySelector('[data-tab="quotes"]').click()`);await pause(1500);
|
|
await k.eval(`document.querySelector('#quote-list button, #quote-list [data-quote], #quote-list li')?.click()`).catch(()=>{});await pause(1500);
|
|
await k.shot('cotacoes',{x:0,y:0,width:1440,height:1000});
|
|
await k.eval(`document.querySelector('[data-tab="payments"]').click()`);await pause(1500);
|
|
await k.shot('pagamentos',{x:0,y:0,width:1440,height:300});
|
|
await k.eval(`document.querySelector('[data-tab="stats"]').click()`);await pause(2000);
|
|
await k.shot('numeros',{x:0,y:0,width:1440,height:900});
|
|
// Users and the edit dialog.
|
|
await k.eval(`document.querySelector('[data-tab="users"]').click()`);await pause(1500);
|
|
await k.el('usuarios','#tab-users',0);
|
|
await k.eval(`[...document.querySelectorAll('#users-list tr')].find(tr=>tr.textContent.includes('Bruno')).querySelector('button').click()`);await pause(600);
|
|
await k.el('usuario-editar','.modal-box',0);
|
|
await k.eval(`document.querySelector('.modal').remove()`);
|
|
// Integrações as in production, with fictional values; the folder as on the print room's computer.
|
|
await k.eval(`document.querySelector('[data-tab="integrations"]').click()`);await pause(1200);
|
|
await k.eval(`(()=>{window.syncFolder=async()=>{};window.load=async()=>{};
|
|
const now=new Date(),at=h=>new Date(now-h*3600e3).toISOString();
|
|
board.tiny={configured:true,connected:true,connected_by:'tiny@dropstar.test',orders_enabled:true,offline:true,connected_at:at(72),renewed_at:at(2)};
|
|
board.providers={...board.providers,payment:'mercadopago',
|
|
freight:{services:{jadlog:'Jadlog',pac:'Correios PAC',sedex:'Correios SEDEX'},box_cm:['63','15.5','15.5'],production_days:1,
|
|
base_kg:'0.3',per_metre_kg:'0.075',cubage_kg_m3:'300',cubed_kg:'4.541',metres_per_box:'60'},
|
|
mail:{adapter:'smtp',pending:0,last_sent:at(1),from:'nao-responda@dropstardtf.com.br'},
|
|
backup:{last_ok:new Date(now.getFullYear(),now.getMonth(),now.getDate(),3,0).toISOString(),bytes:418000,failed:null,requested:false}};
|
|
FOLDER.mode='folder';FOLDER.handle={name:'FlexiPRINT'};FOLDER.granted=true;FOLDER.when='rec';FOLDER.error='';FOLDER.status='';
|
|
FOLDER.saved=new Map(Array.from({length:12},(_,i)=>['u'+i,{place:'queue'}]));FOLDER.last=new Date(now-25*60e3);
|
|
renderIntegrations();})()`);
|
|
await pause(600);
|
|
await k.el('integracoes','#integrations',0);
|
|
await k.eval(`document.querySelector('#folder-card .integ-more').click()`);await pause(400);
|
|
await k.el('pasta','#folder-card',0);
|
|
await k.eval(`(()=>{FOLDER.granted=false;OPEN_INTEG.clear();paintFolder();})()`);await pause(400);
|
|
await k.el('pasta-liberar','#folder-card',0);
|
|
await k.el('aba-aviso','[data-tab="integrations"]',10);
|
|
}
|
|
if(which==='site'){
|
|
// Minha conta: the overview, and an order waiting for a correction.
|
|
if(process.argv[3]!=='cart'){const c=await open('http://site/conta/entrar',1440,1000);
|
|
await waitFor(()=>c.eval('!!document.getElementById("login")'),'portal');
|
|
await c.eval(`(()=>{document.getElementById('email').value='pedidos@camisetasipe.com.br';
|
|
document.getElementById('password').value='senha-de-exemplo-123';document.getElementById('login').requestSubmit();})()`);
|
|
await pause(2500);
|
|
await c.call('Page.navigate',{url:'http://site/conta'});await pause(2500);
|
|
await c.eval(`(()=>{for(const el of document.querySelectorAll('body *'))if(el.children.length===0&&el.textContent.includes('Ambiente de desenvolvimento local'))el.closest('div,p,section').style.display='none';window.scrollTo(0,0);})()`);await pause(400);
|
|
await c.shot('conta',{x:0,y:0,width:1440,height:540});
|
|
const seven=await c.eval(`fetch('/api/customer/orders?page=1&size=10').then(r=>r.json()).then(d=>(d.items.find(i=>i.number===7)||d.items.find(i=>i.state==='cor')).id)`);
|
|
await c.call('Page.navigate',{url:'http://site/conta/pedidos?order='+seven});await pause(2500);
|
|
await c.eval(`(()=>{for(const el of document.querySelectorAll('body *'))if(el.children.length===0&&el.textContent.includes('Ambiente de desenvolvimento local'))el.closest('div,p,section').style.display='none';window.scrollTo(0,0);})()`);await pause(400);
|
|
await c.shot('pedido-correcao',{x:0,y:0,width:1440,height:960});}
|
|
// The cart: artworks added for real, then the customer's details and the delivery options.
|
|
const s=await open('http://site/',1440,1000);
|
|
await waitFor(()=>s.eval(`typeof window.dtfCheckout==="function"&&!!document.querySelector('[data-modo="avulsa"]')`),'site');
|
|
await s.eval(`document.querySelector('[data-modo="avulsa"]').click()`);await pause(800);
|
|
await s.eval(`(async()=>{
|
|
const make=async(name,w,h,draw)=>{const c=document.createElement('canvas');c.width=w;c.height=h;const x=c.getContext('2d');draw(x,w,h);
|
|
return new File([await new Promise(r=>c.toBlob(r,'image/png'))],name,{type:'image/png'});};
|
|
const files=[await make('logo-frente.png',2362,1417,(x,w,h)=>{x.fillStyle='#F26B1D';x.beginPath();x.roundRect(0,0,w,h,120);x.fill();
|
|
x.fillStyle='#FFD23F';x.beginPath();x.arc(w*.24,h/2,h*.32,0,7);x.fill();x.fillStyle='#fff';x.font='bold '+(h*.26)+'px sans-serif';x.fillText('AURORA',w*.44,h*.6);}),
|
|
await make('escudo.png',1181,1181,(x,w,h)=>{x.fillStyle='#1B998B';x.beginPath();x.arc(w/2,h/2,w/2,0,7);x.fill();x.fillStyle='#fff';
|
|
x.font='bold '+(h*.2)+'px sans-serif';x.textAlign='center';x.fillText('ESCUDO',w/2,h*.57);}),
|
|
await make('patrocinio.png',2835,472,(x,w,h)=>{x.fillStyle='#E84855';x.fillRect(0,0,w,h);x.fillStyle='#fff';x.font='bold '+(h*.5)+'px sans-serif';
|
|
x.textAlign='center';x.fillText('PATROCÍNIO',w/2,h*.68);})];
|
|
const dt=new DataTransfer();files.forEach(f=>dt.items.add(f));
|
|
const inp=document.getElementById('inp');inp.files=dt.files;inp.dispatchEvent(new Event('change',{bubbles:true}));})()`);
|
|
await waitFor(()=>s.eval('artes.length===3&&artes.every(a=>a.src)'),'artworks measured',30000);
|
|
for(const [i,cm,q] of [[0,20,4],[1,10,8],[2,24,3]]){
|
|
await s.eval(`(()=>{const set=(sel,v)=>{const el=document.querySelectorAll(sel)[${i}];el.value=v;el.dispatchEvent(new Event('change',{bubbles:true}));};
|
|
set('[data-cm]',${cm});set('[data-q]',${q});})()`);await pause(500);
|
|
}
|
|
await pause(1200);
|
|
await s.eval(`(()=>{const c=document.getElementById('cienteOk');if(c&&!c.checked){c.checked=true;c.dispatchEvent(new Event('change',{bubbles:true}));}})()`);
|
|
await waitFor(()=>s.eval('!!itemAtual&&itemPodeEnviar(itemAtual)'),'item ready for the cart',60000);
|
|
await s.eval(`document.getElementById('bAdd').click()`);
|
|
await waitFor(()=>s.eval('location.pathname==="/carrinho"'),'cart page',20000);
|
|
await waitFor(()=>s.eval(`document.getElementById('carr').innerText.includes('Arquivos enviados')&&!document.getElementById('carr').innerText.includes('verificando')`),'uploads done',180000);
|
|
await s.eval(`(()=>{const g=id=>document.getElementById(id);const fill=(id,v)=>{const el=g(id);el.value=v;el.dispatchEvent(new Event('input',{bubbles:true}));};
|
|
fill('fNome','Juliana Martins');fill('fCnpj','31920485000165');fill('fZap','16991234567');fill('fMail','contato@estampariaaurora.com.br');
|
|
entrega.tipo='frete';entrega.cep='14015040';g('cepIn').value='14015-040';
|
|
entrega.opcoes=[{service:'pac',description:'Correios PAC',days:7,total_cents:2183},{service:'jadlog',description:'Jadlog',days:5,total_cents:2690},
|
|
{service:'sedex',description:'Correios SEDEX',days:3,total_cents:4417}];
|
|
entrega.servico='pac';entrega.valor=21.83;entrega.dias=7;entrega.cotado=true;
|
|
entrega.end={nome:'Juliana Martins',rua:'Rua São Sebastião',num:'820',comp:'Sala 4',bairro:'Centro',cidade:'Ribeirão Preto',uf:'SP'};
|
|
for(const [id,k] of [['eNome','nome'],['eRua','rua'],['eNum','num'],['eComp','comp'],['eBairro','bairro'],['eCidade','cidade'],['eUf','uf']])g(id).value=entrega.end[k];
|
|
pintaFretes();pintaEntrega();if(typeof pintaPedido==='function')pintaPedido();window.scrollTo(0,0);})()`);
|
|
await pause(800);
|
|
const h=await s.eval(`Math.ceil(document.getElementById('fretes').getBoundingClientRect().bottom+28)`);
|
|
await s.shot('carrinho',{x:0,y:0,width:1440,height:h});
|
|
// The order confirmation e-mail, as the customer's mail app shows it.
|
|
const m=await open('file:///g/email-pedido.html',720,1000);
|
|
const mh=await m.eval('Math.ceil(document.body.scrollHeight)');
|
|
await m.shot('email-pedido',{x:0,y:0,width:720,height:mh});
|
|
}
|
|
}catch(e){console.error(e);process.exitCode=1;}
|
|
finally{chrome.kill();}
|