Elffuss BraidHub

utopia-ia/elffuss-code public

main · 4.7 KiBRawPermalink
1// La vista (ciudad o arquitectura) tapa el editor. Si con ella abierta el
2// usuario abre OTRA cosa, la vista se cierra: antes esa otra cosa se abría
3// debajo, inerte, y parecía rota. La CONSOLA es la excepción: si está abierta
4// nada se le pone encima, así que convive con la vista, que termina sobre ella.
5//
6// Control: sin hacer nada, la ciudad sigue abierta. Sin él, un test que la
7// cerrara siempre pasaría igual.
8import { chromium } from 'playwright';
9const BASE = process.env.BASE || 'http://localhost:8799';
10let fails = 0;
11const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
12
13const b = await chromium.launch({ args: ['--use-gl=swiftshader', '--enable-unsafe-swiftshader'] });
14const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
15await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
16const p = await ctx.newPage();
17const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
18await p.goto(BASE + '/?test-opfs');
19await p.waitForFunction(() => !!document.querySelector('#editor .monaco-editor'), null, { timeout: 30000 });
20await p.evaluate(async () => {
21 const r = await navigator.storage.getDirectory();
22 const f = await r.getFileHandle('a.js', { create: true }); const w = await f.createWritable(); await w.write('x'); await w.close();
23 const c = await import('/js/tools/code.js'); await c.openProject(r);
24 await (await import('/js/ide.js')).refreshTree();
25});
26await p.waitForTimeout(500);
27
28const estado = () => p.evaluate(() => {
29 const t = document.getElementById('terminal-panel'), r = t.getBoundingClientRect();
30 let tapada = null;
31 if (r.height) { let e = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); tapada = true; while (e) { if (e === t) { tapada = false; break; } e = e.parentElement; } }
32 return { ciudad: !document.getElementById('view-overlay').hidden, consola: !t.hidden, consolaInerte: t.inert, consolaTapada: tapada, editorInerte: document.getElementById('editor').inert };
33});
34const abreCiudad = async () => { await p.click('#act-city'); await p.waitForFunction(() => !document.getElementById('view-overlay').hidden, null, { timeout: 10000 }); await p.waitForTimeout(600); };
35const limpia = () => p.evaluate(() => {
36 if (!document.getElementById('view-overlay').hidden) document.getElementById('view-close').click();
37 if (!document.getElementById('terminal-panel').hidden) document.getElementById('term-close').click();
38 document.getElementById('settings-panel').hidden = true;
39 document.getElementById('palette')?.setAttribute('hidden', '');
40});
41
42// control: sin tocar nada, la ciudad no se cierra sola
43await abreCiudad();
44await p.waitForTimeout(1500);
45ok('⊕ control: sin hacer nada, la ciudad sigue abierta', (await estado()).ciudad);
46await limpia(); await p.waitForTimeout(300);
47
48// la consola convive con la vista y NADA la tapa
49for (const [nombre, accion] of [
50 ['el botón', () => p.click('#act-term')],
51 ['Ctrl+`', () => p.keyboard.press('Control+`')],
52]) {
53 await abreCiudad();
54 await accion();
55 await p.waitForTimeout(700);
56 const e = await estado();
57 ok(`con la ciudad abierta, la consola (${nombre}) se ve entera y usable, y la ciudad sigue`, e.ciudad && e.consola && !e.consolaInerte && e.consolaTapada === false, JSON.stringify(e));
58 await limpia(); await p.waitForTimeout(300);
59}
60// y al revés: con la consola abierta, abrir la ciudad tampoco la tapa
61await p.click('#act-term'); await p.waitForTimeout(600);
62await abreCiudad();
63{ const e = await estado(); ok('con la consola abierta, abrir la ciudad no la tapa', e.ciudad && e.consola && !e.consolaInerte && e.consolaTapada === false, JSON.stringify(e)); }
64await limpia(); await p.waitForTimeout(300);
65
66for (const [nombre, accion] of [
67 ['la paleta de búsqueda', () => p.keyboard.press(process.platform === 'darwin' ? 'Meta+p' : 'Control+p')],
68 ['los ajustes', () => p.click('#act-settings')],
69 ['las extensiones', () => p.click('#act-ext')],
70 ['un fichero del árbol', async () => {
71 // el explorador alterna: se abre solo si está cerrado
72 await p.evaluate(() => { const sb = document.getElementById('sidebar'); if (getComputedStyle(sb).display === 'none') document.getElementById('act-files').click(); });
73 await p.locator('#tree .file').first().click();
74 }],
75]) {
76 await abreCiudad();
77 await accion();
78 await p.waitForTimeout(700);
79 const e = await estado();
80 ok(`con la ciudad abierta, abrir ${nombre} la cierra`, !e.ciudad, JSON.stringify(e));
81 await limpia(); await p.waitForTimeout(300);
82}
83
84ok('sin errores de página', !errs.length, errs.join(' | '));
85await b.close();
86console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\nTodo en verde');
87process.exit(fails ? 1 : 0);