Elffuss BraidHub

utopia-ia/elffuss-code public

Al arrancar sin ficheros, el aviso de «sin ficheros» y no un documento en blanco

El aviso existía, pero solo se ponía al cerrar la última pestaña. Al arrancar,
Monaco enseñaba su documento vacío con un «1» suelto. Test editor-vacio.mjs,
con control negativo: sin la línea, falla.
Changeset35d8f2574892194bc21c3eea57e4c30add0d2bf32298dd7dc30a37c2c6cf57ce
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-13 10:07 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-13 10:07 +02:00
Parents5deee259aed4

Browse the files at this changeset

2 files changed

added tests/editor-vacio.mjs +41 −0
@@ -0,0 +1,41 @@
1+// Al arrancar sin ficheros abiertos, el editor muestra el aviso de «sin
2+// ficheros» y no el documento vacío de Monaco con un «1». Al abrir un fichero
3+// el aviso desaparece, y al cerrar la última pestaña vuelve.
4+import { chromium } from 'playwright';
5+const BASE = process.env.BASE || 'http://localhost:8799';
6+let fails = 0;
7+const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
8+
9+const b = await chromium.launch();
10+const ctx = await b.newContext();
11+await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
12+const p = await ctx.newPage();
13+p.on('pageerror', e => { console.log('❌ pageerror: ' + e.message); fails++; });
14+await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
15+
16+// Esperar a que Monaco exista: si no, «no hay aviso» no prueba nada.
17+const listo = await p.waitForFunction(() => !!document.querySelector('#editor .monaco-editor'), null, { timeout: 30000 }).then(() => true, () => false);
18+ok('⊕ control: Monaco se ha montado', listo);
19+
20+const visible = () => p.evaluate(() => {
21+ const el = document.getElementById('editor-empty');
22+ return !!el && getComputedStyle(el).display !== 'none' && el.offsetHeight > 0;
23+});
24+ok('al arrancar sin ficheros se ve el aviso, no el documento en blanco', await visible());
25+
26+// Abrir un fichero lo quita.
27+await p.evaluate(async () => {
28+ const root = await navigator.storage.getDirectory();
29+ const fh = await root.getFileHandle('hola.js', { create: true });
30+ const w = await fh.createWritable(); await w.write('export const a = 1;\n'); await w.close();
31+ const code = await import('/js/tools/code.js');
32+ await code.openProject(root);
33+ const ide = await import('/js/ide.js');
34+ await ide.openFile('hola.js');
35+});
36+await p.waitForTimeout(300);
37+ok('al abrir un fichero el aviso desaparece', !(await visible()));
38+
39+await b.close();
40+console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\nTodo en verde');
41+process.exit(fails ? 1 : 0);
modified web/js/ide.js +4 −0
@@ -46,6 +46,10 @@
4646 minimap: { enabled: false },
4747 padding: { top: 8 },
4848 });
49+ // Al arrancar no hay ningún fichero abierto, y Monaco enseña su documento
50+ // vacío con un «1» suelto. El aviso de «sin ficheros» solo se ponía al CERRAR
51+ // la última pestaña, nunca al empezar. Abrir un fichero lo quita (openFile).
52+ if (!tabs.length) setEmptyState(true);
4953 editor.addCommand(monacoRef.KeyMod.CtrlCmd | monacoRef.KeyCode.KeyS, saveActive);
5054 editor.onDidChangeModelContent(() => {
5155 const tab = tabs.find(t => t.path === active);