| 1 | import { chromium } from 'playwright'; |
| 2 | const BASE = process.env.BASE || 'https://code.elffuss.com'; |
| 3 | let fails = 0; const ok = (n,c,e='')=>{console.log((c?'✅':'❌')+' '+n+(e?' — '+e:''));if(!c)fails++}; |
| 4 | const b = await chromium.launch(); const ctx = await b.newContext({ locale: 'es-ES' }); // los menús hablan el idioma del navegador; este test mira los textos en español |
| 5 | await ctx.addInitScript(()=>{try{localStorage.setItem('elffusscode.model','rules')}catch{}}); |
| 6 | const p = await ctx.newPage(); |
| 7 | await p.goto(BASE+'/',{waitUntil:'domcontentloaded'}); |
| 8 | await p.evaluate(async()=>{const o=await navigator.storage.getDirectory();const w=async(d,n,t)=>{const f=await d.getFileHandle(n,{create:true});const s=await f.createWritable();await s.write(t);await s.close()};await w(o,'hola.txt','contenido')}); |
| 9 | await p.goto(BASE+'/?test-opfs',{waitUntil:'domcontentloaded'}); await p.waitForTimeout(2500); |
| 10 | // botón derecho sobre el fichero |
| 11 | await p.locator('#tree').getByText('hola.txt').click({button:'right'}); |
| 12 | await p.waitForTimeout(300); |
| 13 | const items = await p.locator('#tree-menu .tm-item').allInnerTexts().catch(()=>[]); |
| 14 | ok('el menú contextual aparece con acciones', items.length>=3 && items.some(t=>/Eliminar/.test(t)) && items.some(t=>/Renombrar/.test(t)), items.join(' · ')); |
| 15 | // crear carpeta nueva vía menú (dialog) |
| 16 | p.once('dialog', d=>d.accept('nueva-carpeta')); |
| 17 | await p.locator('#tree-menu .tm-item', {hasText:'Nueva carpeta'}).click(); |
| 18 | await p.waitForTimeout(500); |
| 19 | const hasFolder = await p.locator('#tree').getByText('nueva-carpeta').count(); |
| 20 | ok('«Nueva carpeta» crea la carpeta en el árbol', hasFolder>0); |
| 21 | // eliminar el fichero vía menú (confirm) |
| 22 | await p.locator('#tree').getByText('hola.txt').click({button:'right'}); |
| 23 | await p.waitForTimeout(200); |
| 24 | p.once('dialog', d=>d.accept()); |
| 25 | await p.locator('#tree-menu .tm-item', {hasText:'Eliminar'}).click(); |
| 26 | await p.waitForTimeout(500); |
| 27 | const gone = await p.locator('#tree').getByText('hola.txt').count(); |
| 28 | ok('«Eliminar» quita el fichero del árbol', gone===0); |
| 29 | console.log(fails?`\n❌ ${fails} FALLO(S)`:'\n✅ MENÚ CONTEXTUAL OK'); |
| 30 | await b.close(); process.exit(fails?1:0); |