| 1 | // Las vistas 3D (Arquitectura y Ciudad) llevan al lado la lista de lo que |
| 2 | // pintan, para quien no puede (o no quiere) apuntar en un lienzo 3D: se busca |
| 3 | // escribiendo, se recorre con ↑/↓, Enter abre el fichero y ◎ lo enseña en la |
| 4 | // vista. Antes solo había el lienzo: con teclado o lector de pantalla no se |
| 5 | // podía llegar a ningún fichero desde ahí. |
| 6 | // |
| 7 | // BASE=http://localhost:8799 node tests/view-list.mjs |
| 8 | import { chromium } from 'playwright'; |
| 9 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 10 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 11 | |
| 12 | const b = await chromium.launch(); |
| 13 | const ctx = await b.newContext({ locale: 'es-ES' }); |
| 14 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 15 | const p = await ctx.newPage({ viewport: { width: 1500, height: 900 } }); |
| 16 | const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160))); |
| 17 | await p.goto(BASE + '/manifest.json'); |
| 18 | await p.evaluate(async () => { |
| 19 | const o = await navigator.storage.getDirectory(); |
| 20 | const w = async (path, txt) => { const parts = path.split('/'); const name = parts.pop(); let d = o; for (const x of parts) d = await d.getDirectoryHandle(x, { create: true }); const f = await d.getFileHandle(name, { create: true }); const s = await f.createWritable(); await s.write(txt); await s.close(); }; |
| 21 | await w('index.js', "import {app} from './src/app.js';\napp();"); |
| 22 | await w('src/app.js', "import {greet} from './utils.js';\nexport const app=()=>greet('x');"); |
| 23 | await w('src/utils.js', "export const greet=d=>String(d);"); |
| 24 | await w('docs/notas.md', '# notas'); |
| 25 | }); |
| 26 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 27 | await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 }); |
| 28 | |
| 29 | async function vista(boton, sel) { |
| 30 | await p.click(boton); |
| 31 | await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {}); |
| 32 | await p.waitForTimeout(300); |
| 33 | return p.evaluate(s => ({ |
| 34 | hay: !!document.querySelector('#view-body .view-list'), |
| 35 | nombre: document.querySelector('.view-list')?.getAttribute('aria-label'), |
| 36 | filas: [...document.querySelectorAll('.view-list .vl-open')].map(b => b.dataset.path), |
| 37 | cuenta: document.querySelector('.view-list .vl-count')?.textContent, |
| 38 | lienzo: !!document.querySelector(s), |
| 39 | }), sel); |
| 40 | } |
| 41 | |
| 42 | // 1 · Arquitectura |
| 43 | let a = await vista('#act-arch', '#arch-graph canvas'); |
| 44 | ok('1 · Arquitectura: junto al grafo, la lista de sus ficheros', a.hay && a.lienzo && JSON.stringify(a.filas) === '["index.js","src/app.js","src/utils.js"]', JSON.stringify(a)); |
| 45 | const fila = await p.evaluate(() => { const b = document.querySelector('.view-list .vl-open[data-path="src/app.js"]'); return b?.getAttribute('aria-label'); }); |
| 46 | ok('1 · …cada fila dice qué abre y sus conexiones', /^Abrir src\/app\.js · \d+ conexiones$/.test(fila || ''), fila); |
| 47 | await p.fill('.view-list .vl-filter', 'util'); |
| 48 | await p.waitForTimeout(100); |
| 49 | const filtrado = await p.evaluate(() => ({ filas: [...document.querySelectorAll('.view-list .vl-open')].map(b => b.dataset.path), cuenta: document.querySelector('.view-list .vl-count').textContent })); |
| 50 | ok('1 · escribir filtra la lista y lo dice («1 de 3»)', JSON.stringify(filtrado.filas) === '["src/utils.js"]' && filtrado.cuenta === '1 de 3', JSON.stringify(filtrado)); |
| 51 | await p.locator('.view-list .vl-locate').first().click(); |
| 52 | await p.waitForTimeout(300); |
| 53 | ok('1 · ◎ lo enseña en la vista sin cerrarla', !(await p.locator('#view-overlay').isHidden())); |
| 54 | await p.focus('.view-list .vl-filter'); |
| 55 | await p.keyboard.press('Enter'); |
| 56 | await p.waitForSelector('#view-overlay[hidden]', { state: 'attached', timeout: 5000 }).catch(() => {}); |
| 57 | await p.waitForTimeout(400); |
| 58 | const tab = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => ''); |
| 59 | ok('1 · Enter en el buscador abre el primero: la vista se cierra y el fichero queda abierto', await p.locator('#view-overlay').isHidden() && tab === 'utils.js', tab); |
| 60 | |
| 61 | // 2 · Ciudad (todos los ficheros, no solo el código) |
| 62 | const c = await vista('#act-city', '#city-canvas'); |
| 63 | ok('2 · Ciudad: la lista trae todos los ficheros del proyecto', c.hay && c.lienzo && c.filas.includes('docs/notas.md') && c.filas.includes('src/app.js'), JSON.stringify(c)); |
| 64 | await p.focus('.view-list .vl-filter'); |
| 65 | await p.keyboard.press('ArrowDown'); |
| 66 | const primero = await p.evaluate(() => document.activeElement?.dataset?.path); |
| 67 | await p.keyboard.press('ArrowDown'); |
| 68 | const segundo = await p.evaluate(() => document.activeElement?.dataset?.path); |
| 69 | await p.keyboard.press('ArrowUp'); await p.keyboard.press('ArrowUp'); |
| 70 | const vuelve = await p.evaluate(() => document.activeElement?.classList.contains('vl-filter')); |
| 71 | ok('2 · ↓ entra en la lista y la recorre; ↑ vuelve al buscador', !!primero && !!segundo && primero !== segundo && vuelve, JSON.stringify({ primero, segundo, vuelve })); |
| 72 | await p.locator('.view-list .vl-locate').first().click(); |
| 73 | await p.waitForTimeout(300); |
| 74 | ok('2 · ◎ centra el edificio sin cerrar la vista', !(await p.locator('#view-overlay').isHidden())); |
| 75 | await p.locator('.view-list .vl-open[data-path="docs/notas.md"]').click(); |
| 76 | await p.waitForTimeout(500); |
| 77 | const tab2 = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => ''); |
| 78 | ok('2 · clic en una fila abre ese fichero', await p.locator('#view-overlay').isHidden() && tab2 === 'notas.md', tab2); |
| 79 | |
| 80 | console.log('\n errores JS:', errs[0] || 'ninguno'); |
| 81 | ok('sin errores de página', errs.length === 0, errs.join(' | ')); |
| 82 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTAS 3D CON LISTA: se buscan, se recorren y abren con el teclado'); |
| 83 | await b.close(); |
| 84 | process.exit(fails ? 1 : 0); |