| 1 | // Bug A: al cerrar la última pestaña → estado vacío (no Monaco en blanco). |
| 2 | // Bug B: abrir/cerrar/alternar vistas (grafo/ciudad) → siempre cargan bien. |
| 3 | import { chromium } from 'playwright'; |
| 4 | import { CHROME_ARGS } from './chrome-args.mjs'; |
| 5 | const OUT=(process.env.SCRATCH || '/tmp/elffuss-test'); |
| 6 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 7 | let fails=0; const ok=(n,c,e='')=>{console.log((c?'✅':'❌')+' '+n+(e?' — '+e:''));if(!c)fails++}; |
| 8 | const b=await chromium.launch({args:['--enable-unsafe-webgpu',...CHROME_ARGS]}); |
| 9 | const ctx=await b.newContext(); await ctx.addInitScript(()=>{try{localStorage.setItem('elffusscode.model','rules')}catch{}}); |
| 10 | const p=await ctx.newPage({viewport:{width:1500,height:900}}); |
| 11 | p.on('pageerror',e=>{if(!/allow-same-origin/.test(e.message))console.log(' pageerror:',e.message.slice(0,120))}); |
| 12 | await p.goto(BASE+'/',{waitUntil:'domcontentloaded'}); |
| 13 | await p.evaluate(async()=>{const o=await navigator.storage.getDirectory();const w=async(path,txt)=>{const pr=path.split('/');const nm=pr.pop();let d=o;for(const x of pr)d=await d.getDirectoryHandle(x,{create:true});const f=await d.getFileHandle(nm,{create:true});const s=await f.createWritable();await s.write(txt);await s.close()}; |
| 14 | await w('README.md','# demo'); await w('src/a.js',"import {b} from './b.js';\nexport const a=b;"); await w('src/b.js',"export const b=1;");}); |
| 15 | await p.goto(BASE+'/?test-opfs',{waitUntil:'domcontentloaded'}); await p.waitForTimeout(2500); |
| 16 | |
| 17 | // ── Bug A ── |
| 18 | await p.locator('#tree').getByText('README.md').first().click(); await p.waitForTimeout(700); |
| 19 | ok('al abrir un fichero, sin estado vacío', await p.evaluate(()=>{const e=document.getElementById('editor-empty');return !e||getComputedStyle(e).display==='none';})); |
| 20 | await p.locator('#tabs-bar .tab .tab-x').first().click(); await p.waitForTimeout(500); // cerrar la pestaña (su ✕ es un botón .tab-x) |
| 21 | ok('al cerrar la última pestaña → estado vacío visible', await p.evaluate(()=>{const e=document.getElementById('editor-empty');return !!e && getComputedStyle(e).display!=='none';})); |
| 22 | |
| 23 | // ── Bug B ── abrir/cerrar/alternar vistas varias veces |
| 24 | const openArch=async()=>{ await p.click('#act-arch'); await p.waitForTimeout(3500); return p.evaluate(()=>{const g=document.getElementById('arch-graph');return !!g && !!g.querySelector('canvas') && +g.dataset.nodes>0;}); }; |
| 25 | const openCity=async()=>{ await p.click('#act-city'); await p.waitForTimeout(3500); return p.evaluate(()=>{const c=document.getElementById('city-canvas');const gl=c&&(c.getContext('webgl2')||c.getContext('webgl'));return !!gl && !gl.isContextLost() && c.width>50; }); }; |
| 26 | ok('grafo carga (1ª vez)', await openArch()); |
| 27 | await p.click('#view-close'); await p.waitForTimeout(400); |
| 28 | ok('ciudad carga tras cerrar el grafo', await openCity()); |
| 29 | await p.click('#view-close'); await p.waitForTimeout(400); |
| 30 | ok('grafo RE-carga (reapertura)', await openArch()); |
| 31 | // alternar directo grafo→ciudad sin cerrar |
| 32 | ok('ciudad carga alternando directo desde el grafo', await openCity()); |
| 33 | ok('grafo carga alternando directo desde la ciudad', await openArch()); |
| 34 | await p.screenshot({path:OUT+'/bugs.png'}); |
| 35 | console.log(fails?`\n❌ ${fails} FALLO(S)`:'\n✅ BUGS (estado vacío + recarga de vistas) OK'); |
| 36 | await b.close(); process.exit(fails?1:0); |