Elffuss BraidHub

utopia-ia/elffuss-code public

main · 2.6 KiBRawPermalink
1// Vista previa HTML (como la de markdown) + disponible también desde el
2// menú contextual del explorador de ficheros (no solo el de la pestaña).
3import { chromium } from 'playwright';
4const OUT = (process.env.SCRATCH || '/tmp/elffuss-test');
5const BASE = process.env.BASE || 'http://localhost:8799';
6let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
7
8const b = await chromium.launch();
9const ctx = await b.newContext({ locale: 'es-ES' }); // los menús hablan el idioma del navegador; este test mira los textos en español
10await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
11const p = await ctx.newPage();
12await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
13await p.evaluate(async () => {
14 const o = await navigator.storage.getDirectory();
15 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(); };
16 await w('page.html', '<!doctype html><html><body><h1 id="marca">hola desde el HTML real</h1></body></html>');
17});
18await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
19
20// desde el EXPLORADOR (árbol), no desde una pestaña ya abierta
21const fileRow = p.locator('#tree .file', { hasText: 'page.html' });
22await fileRow.click({ button: 'right' });
23await p.waitForTimeout(150);
24ok('el árbol ofrece "Vista previa" para un .html', (await p.locator('#tree-menu .tm-item').allInnerTexts()).includes('Vista previa'));
25await p.click('#tree-menu .tm-item:has-text("Vista previa")');
26await p.waitForTimeout(300);
27
28ok('se abrió como pestaña y quedó en Vista previa', await p.locator('#tabs-bar .tab.tab-preview').count() === 1);
29ok('el editor Monaco se oculta', await p.locator('#editor').evaluate(el => getComputedStyle(el).display === 'none'));
30const frameCount = await p.locator('#md-preview-pane iframe').count();
31ok('se muestra un iframe real (no HTML escapado como texto)', frameCount === 1);
32const frame = p.frameLocator('#md-preview-pane iframe');
33ok('el HTML se renderiza DE VERDAD (el <h1> real existe en el DOM del iframe)', await frame.locator('#marca').count() === 1);
34ok('el texto del h1 real aparece', (await frame.locator('#marca').innerText()) === 'hola desde el HTML real');
35
36await p.screenshot({ path: OUT + '/htmlpreview.png' });
37console.log('captura → htmlpreview.png');
38console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTA PREVIA HTML (desde el explorador) OK');
39await b.close();
40process.exit(fails ? 1 : 0);