Elffuss BraidHub

utopia-ia/elffuss-code public

71f77de4f55f · 5.7 KiBRawPermalink
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
8import { chromium } from 'playwright';
9const BASE = process.env.BASE || 'http://localhost:8799';
10let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
11
12const b = await chromium.launch();
13const ctx = await b.newContext({ locale: 'es-ES' });
14await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
15const p = await ctx.newPage({ viewport: { width: 1500, height: 900 } });
16const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
17await p.goto(BASE + '/manifest.json');
18await 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});
26await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
27await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
28
29async 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
43let a = await vista('#act-arch', '#arch-graph canvas');
44ok('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));
45const fila = await p.evaluate(() => { const b = document.querySelector('.view-list .vl-open[data-path="src/app.js"]'); return b?.getAttribute('aria-label'); });
46ok('1 · …cada fila dice qué abre y sus conexiones', /^Abrir src\/app\.js · \d+ conexiones$/.test(fila || ''), fila);
47await p.fill('.view-list .vl-filter', 'util');
48await p.waitForTimeout(100);
49const filtrado = await p.evaluate(() => ({ filas: [...document.querySelectorAll('.view-list .vl-open')].map(b => b.dataset.path), cuenta: document.querySelector('.view-list .vl-count').textContent }));
50ok('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));
51await p.locator('.view-list .vl-locate').first().click();
52await p.waitForTimeout(300);
53ok('1 · ◎ lo enseña en la vista sin cerrarla', !(await p.locator('#view-overlay').isHidden()));
54await p.focus('.view-list .vl-filter');
55await p.keyboard.press('Enter');
56await p.waitForSelector('#view-overlay[hidden]', { state: 'attached', timeout: 5000 }).catch(() => {});
57await p.waitForTimeout(400);
58const tab = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
59ok('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)
62const c = await vista('#act-city', '#city-canvas');
63ok('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));
64await p.focus('.view-list .vl-filter');
65await p.keyboard.press('ArrowDown');
66const primero = await p.evaluate(() => document.activeElement?.dataset?.path);
67await p.keyboard.press('ArrowDown');
68const segundo = await p.evaluate(() => document.activeElement?.dataset?.path);
69await p.keyboard.press('ArrowUp'); await p.keyboard.press('ArrowUp');
70const vuelve = await p.evaluate(() => document.activeElement?.classList.contains('vl-filter'));
71ok('2 · ↓ entra en la lista y la recorre; ↑ vuelve al buscador', !!primero && !!segundo && primero !== segundo && vuelve, JSON.stringify({ primero, segundo, vuelve }));
72await p.locator('.view-list .vl-locate').first().click();
73await p.waitForTimeout(300);
74ok('2 · ◎ centra el edificio sin cerrar la vista', !(await p.locator('#view-overlay').isHidden()));
75await p.locator('.view-list .vl-open[data-path="docs/notas.md"]').click();
76await p.waitForTimeout(500);
77const tab2 = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
78ok('2 · clic en una fila abre ese fichero', await p.locator('#view-overlay').isHidden() && tab2 === 'notas.md', tab2);
79
80console.log('\n errores JS:', errs[0] || 'ninguno');
81ok('sin errores de página', errs.length === 0, errs.join(' | '));
82console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTAS 3D CON LISTA: se buscan, se recorren y abren con el teclado');
83await b.close();
84process.exit(fails ? 1 : 0);