Elffuss BraidHub

utopia-ia/elffuss-code public

main · 10.4 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// Y la vista tapa el editor de verdad (partes 3 y 4): el foco entra en ella, el
8// editor de debajo queda inerte (el Tab no lo alcanza ni lo edita a ciegas) y al
9// cerrarla el foco vuelve a quien la abrió.
10//
11// BASE=http://localhost:8799 node tests/view-list.mjs
12import { chromium } from 'playwright';
13const BASE = process.env.BASE || 'http://localhost:8799';
14let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
15
16const b = await chromium.launch();
17const ctx = await b.newContext({ locale: 'es-ES' });
18await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
19const p = await ctx.newPage({ viewport: { width: 1500, height: 900 } });
20const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
21await p.goto(BASE + '/manifest.json');
22await p.evaluate(async () => {
23 const o = await navigator.storage.getDirectory();
24 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(); };
25 await w('index.js', "import {app} from './src/app.js';\napp();");
26 await w('src/app.js', "import {greet} from './utils.js';\nexport const app=()=>greet('x');");
27 await w('src/utils.js', "export const greet=d=>String(d);");
28 await w('docs/notas.md', '# notas');
29});
30await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
31await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
32
33async function vista(boton, sel) {
34 await p.click(boton);
35 await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
36 await p.waitForTimeout(300);
37 return p.evaluate(s => ({
38 hay: !!document.querySelector('#view-body .view-list'),
39 nombre: document.querySelector('.view-list')?.getAttribute('aria-label'),
40 filas: [...document.querySelectorAll('.view-list .vl-open')].map(b => b.dataset.path),
41 cuenta: document.querySelector('.view-list .vl-count')?.textContent,
42 lienzo: !!document.querySelector(s),
43 }), sel);
44}
45
46// 1 · Arquitectura
47let a = await vista('#act-arch', '#arch-graph canvas');
48ok('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));
49const fila = await p.evaluate(() => { const b = document.querySelector('.view-list .vl-open[data-path="src/app.js"]'); return b?.getAttribute('aria-label'); });
50ok('1 · …cada fila dice qué abre y sus conexiones', /^Abrir src\/app\.js · \d+ conexiones$/.test(fila || ''), fila);
51await p.fill('.view-list .vl-filter', 'util');
52await p.waitForTimeout(100);
53const filtrado = await p.evaluate(() => ({ filas: [...document.querySelectorAll('.view-list .vl-open')].map(b => b.dataset.path), cuenta: document.querySelector('.view-list .vl-count').textContent }));
54ok('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));
55await p.locator('.view-list .vl-locate').first().click();
56await p.waitForTimeout(300);
57ok('1 · ◎ lo enseña en la vista sin cerrarla', !(await p.locator('#view-overlay').isHidden()));
58await p.focus('.view-list .vl-filter');
59await p.keyboard.press('Enter');
60await p.waitForSelector('#view-overlay[hidden]', { state: 'attached', timeout: 5000 }).catch(() => {});
61await p.waitForTimeout(400);
62const tab = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
63ok('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);
64
65// 2 · Ciudad (todos los ficheros, no solo el código)
66const c = await vista('#act-city', '#city-canvas');
67ok('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));
68await p.focus('.view-list .vl-filter');
69await p.keyboard.press('ArrowDown');
70const primero = await p.evaluate(() => document.activeElement?.dataset?.path);
71await p.keyboard.press('ArrowDown');
72const segundo = await p.evaluate(() => document.activeElement?.dataset?.path);
73await p.keyboard.press('ArrowUp'); await p.keyboard.press('ArrowUp');
74const vuelve = await p.evaluate(() => document.activeElement?.classList.contains('vl-filter'));
75ok('2 · ↓ entra en la lista y la recorre; ↑ vuelve al buscador', !!primero && !!segundo && primero !== segundo && vuelve, JSON.stringify({ primero, segundo, vuelve }));
76await p.locator('.view-list .vl-locate').first().click();
77await p.waitForTimeout(300);
78ok('2 · ◎ centra el edificio sin cerrar la vista', !(await p.locator('#view-overlay').isHidden()));
79await p.locator('.view-list .vl-open[data-path="docs/notas.md"]').click();
80await p.waitForTimeout(500);
81const tab2 = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
82ok('2 · clic en una fila abre ese fichero', await p.locator('#view-overlay').isHidden() && tab2 === 'notas.md', tab2);
83
84// 3 · Con teclado, la vista tapa el editor DE VERDAD. Antes el foco se quedaba en
85// el botón y el Tab, tras la barra, el árbol y la pestaña, caía en el editor
86// tapado: cada Tab sangraba el fichero sin que se viera, y la lista no se
87// alcanzaba nunca con Tab hacia delante.
88{
89 await p.evaluate(async () => { await (await import('/js/ide.js')).openFile('src/app.js'); });
90 await p.waitForTimeout(500);
91 const fichero = () => p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue());
92 const antes = await fichero();
93 await p.focus('#act-arch');
94 await p.keyboard.press('Enter');
95 await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
96 await p.waitForTimeout(300);
97 const alAbrir = await p.evaluate(() => ({
98 foco: document.activeElement?.className, editorInerte: document.getElementById('editor').inert,
99 }));
100 ok('3 · Enter en Arquitectura: el foco entra en la vista (el buscador) y el editor de debajo queda inerte',
101 alAbrir.foco === 'vl-filter' && alAbrir.editorInerte === true, JSON.stringify(alAbrir));
102 await p.focus('#act-arch');
103 const paradas = [];
104 for (let i = 0; i < 14; i++) {
105 await p.keyboard.press('Tab');
106 paradas.push(await p.evaluate(() => {
107 const a = document.activeElement;
108 return a?.closest('.monaco-editor') ? 'EDITOR' : a?.closest('#view-overlay') ? 'VISTA' : (a?.id || a?.tagName);
109 }));
110 }
111 const despues = await fichero();
112 const pestana = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
113 ok('3 · Tab desde el botón llega a la lista de la vista y nunca al editor tapado',
114 paradas.includes('VISTA') && !paradas.includes('EDITOR'), paradas.join(' › '));
115 ok('3 · …y el fichero de debajo no cambia', despues === antes && !/sin guardar|unsaved/.test(pestana || ''), `${JSON.stringify(despues.slice(0, 30))} · ${pestana}`);
116 await p.focus('.view-list .vl-filter');
117 await p.keyboard.press('Escape');
118 await p.waitForTimeout(300);
119 const alCerrar = await p.evaluate(() => ({
120 oculta: document.getElementById('view-overlay').hidden, foco: document.activeElement?.id,
121 editorInerte: document.getElementById('editor').inert,
122 }));
123 ok('3 · Escape la cierra, el foco vuelve al botón y el editor vuelve a ser usable',
124 alCerrar.oculta && alCerrar.foco === 'act-arch' && alCerrar.editorInerte === false, JSON.stringify(alCerrar));
125 await p.focus('#act-city');
126 await p.keyboard.press('Enter');
127 await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
128 await p.waitForTimeout(300);
129 const ciudad = await p.evaluate(() => ({ foco: document.activeElement?.className, editorInerte: document.getElementById('editor').inert }));
130 ok('3 · la Ciudad igual: foco en su buscador y el editor inerte', ciudad.foco === 'vl-filter' && ciudad.editorInerte === true, JSON.stringify(ciudad));
131 await p.click('#view-close');
132 await p.waitForTimeout(300);
133 ok('3 · ✕ con el ratón también la cierra y suelta el editor',
134 await p.evaluate(() => document.getElementById('view-overlay').hidden && !document.getElementById('editor').inert));
135}
136
137// 4 · En el móvil el foco entra en la vista por su ✕, no por el buscador:
138// enfocar el buscador sacaría el teclado encima de la lista.
139{
140 const mctx = await b.newContext({ locale: 'es-ES', viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
141 await mctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
142 const m = await mctx.newPage();
143 m.on('pageerror', e => errs.push('móvil: ' + e.message.slice(0, 160)));
144 await m.goto(BASE + '/manifest.json');
145 await m.evaluate(async () => {
146 const o = await navigator.storage.getDirectory();
147 const f = await o.getFileHandle('index.js', { create: true }); const s = await f.createWritable(); await s.write("export const a = 1;"); await s.close();
148 });
149 await m.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
150 await m.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
151 await m.tap('#btn-drawer');
152 await m.waitForTimeout(300);
153 await m.tap('#act-arch');
154 await m.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
155 await m.waitForTimeout(300);
156 const movil = await m.evaluate(() => ({ foco: document.activeElement?.id || document.activeElement?.className, editorInerte: document.getElementById('editor').inert }));
157 ok('4 · móvil: el foco entra en la vista por su ✕ y el editor queda inerte', movil.foco === 'view-close' && movil.editorInerte === true, JSON.stringify(movil));
158 await mctx.close();
159}
160
161console.log('\n errores JS:', errs[0] || 'ninguno');
162ok('sin errores de página', errs.length === 0, errs.join(' | '));
163console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTAS 3D CON LISTA: se buscan, se recorren y abren con el teclado');
164await b.close();
165process.exit(fails ? 1 : 0);