Elffuss BraidHub

utopia-ia/elffuss-code public

2df00d521f0c · 4.3 KiBRawPermalink
1// Menú contextual de pestañas (botón derecho) + Vista previa de markdown.
2import { chromium } from 'playwright';
3const OUT = (process.env.SCRATCH || '/tmp/elffuss-test');
4const BASE = process.env.BASE || 'http://localhost:8799';
5let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
6
7const b = await chromium.launch();
8const ctx = await b.newContext({ locale: 'es-ES' }); // los menús hablan el idioma del navegador; este test mira los textos en español
9await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
10const p = await ctx.newPage();
11await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
12await p.evaluate(async () => {
13 const o = await navigator.storage.getDirectory();
14 const w = async (n, t) => { const f = await o.getFileHandle(n, { create: true }); const s = await f.createWritable(); await s.write(t); await s.close(); };
15 await w('README.md', '# Titulo\n\nUn parrafo con **negrita**.');
16 await w('app.js', 'export const app = 1;');
17});
18await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
19
20await p.evaluate(async () => (await import('/js/ide.js')).openFile('README.md'));
21await p.evaluate(async () => (await import('/js/ide.js')).openFile('app.js'));
22await p.waitForTimeout(300);
23ok('2 pestañas abiertas', await p.locator('#tabs-bar .tab').count() === 2);
24
25// clic derecho en la pestaña README.md abre el menú custom (no el nativo)
26const readmeTab = p.locator('#tabs-bar .tab', { hasText: 'README.md' });
27await readmeTab.click({ button: 'right' });
28await p.waitForTimeout(150);
29ok('menú contextual de pestaña visible', await p.locator('#tab-menu').count() > 0);
30const items = await p.locator('#tab-menu .tm-item').allInnerTexts();
31ok('incluye Cerrar / Cerrar otras / Cerrar todas / Copiar ruta', ['Cerrar', 'Cerrar otras', 'Cerrar todas', 'Copiar ruta'].every(x => items.includes(x)), items.join(' · '));
32ok('README.md (markdown) ofrece Vista previa', items.includes('Vista previa'), items.join(' · '));
33
34// Vista previa: renderiza markdown en vez de mostrar el código fuente
35await p.click('#tab-menu .tm-item:has-text("Vista previa")');
36await p.waitForTimeout(200);
37ok('el editor Monaco se oculta en Vista previa', await p.locator('#editor').evaluate(el => getComputedStyle(el).display === 'none'));
38const previewHtml = await p.locator('#md-preview-pane').innerHTML();
39ok('el markdown se renderiza FORMATEADO (mismo motor que chat/Mente: título → <h4>, negrita → <b>)', /<h4/.test(previewHtml) && /<b>/.test(previewHtml), previewHtml.slice(0, 80));
40ok('la pestaña en Vista previa se marca en cursiva', await readmeTab.evaluate(el => el.classList.contains('tab-preview')));
41
42// clic derecho de nuevo → ahora ofrece volver a "Ver código fuente"
43await readmeTab.click({ button: 'right' });
44await p.waitForTimeout(150);
45const items2 = await p.locator('#tab-menu .tm-item').allInnerTexts();
46ok('toggle: ahora ofrece "Ver código fuente"', items2.includes('Ver código fuente'), items2.join(' · '));
47await p.click('#tab-menu .tm-item:has-text("Ver código fuente")');
48await p.waitForTimeout(200);
49ok('vuelve a mostrar Monaco (código fuente)', await p.locator('#editor').evaluate(el => getComputedStyle(el).display !== 'none'));
50
51// app.js (no markdown) NO ofrece Vista previa
52const appTab = p.locator('#tabs-bar .tab', { hasText: 'app.js' });
53await appTab.click({ button: 'right' });
54await p.waitForTimeout(150);
55const items3 = await p.locator('#tab-menu .tm-item').allInnerTexts();
56ok('app.js (no markdown) NO ofrece Vista previa', !items3.includes('Vista previa'), items3.join(' · '));
57await p.keyboard.press('Escape'); await p.mouse.click(700, 400); await p.waitForTimeout(100);
58
59// Cerrar otras
60await readmeTab.click({ button: 'right' });
61await p.waitForTimeout(150);
62await p.click('#tab-menu .tm-item:has-text("Cerrar otras")');
63await p.waitForTimeout(200);
64ok('«Cerrar otras» deja solo la pestaña activa', await p.locator('#tabs-bar .tab').count() === 1 && await p.locator('#tabs-bar .tab', { hasText: 'README.md' }).count() === 1);
65
66await p.screenshot({ path: OUT + '/tabmenu.png' });
67console.log('captura → tabmenu.png');
68console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ MENÚ DE PESTAÑAS + VISTA PREVIA MARKDOWN OK');
69await b.close();
70process.exit(fails ? 1 : 0);