Elffuss BraidHub

utopia-ia/elffuss-code public

178a8a01c6e9 · 2.6 KiBRawPermalink
1// Vista previa HTML: los <link rel=stylesheet href=...> y <script src=...>
2// LOCALES del proyecto se incrustan de verdad (antes salían sin CSS: un
3// iframe con srcdoc no tiene base URL y esas rutas relativas nunca resuelven).
4import { chromium } from 'playwright';
5const OUT = (process.env.SCRATCH || '/tmp/elffuss-test');
6const BASE = process.env.BASE || 'http://localhost:8799';
7let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
8
9const b = await chromium.launch();
10const ctx = await b.newContext({ locale: 'es-ES' }); // los menús hablan el idioma del navegador; este test mira los textos en español
11await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
12const p = await ctx.newPage();
13await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
14await p.evaluate(async () => {
15 const o = await navigator.storage.getDirectory();
16 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(); };
17 await w('style.css', 'body { background: rgb(17, 34, 51); } #marca { color: rgb(255, 0, 0); font-size: 40px; }');
18 await w('page.html', '<!doctype html><html><head><link rel="stylesheet" href="style.css"></head><body><h1 id="marca">hola</h1></body></html>');
19});
20await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500);
21
22await p.evaluate(async () => (await import('/js/ide.js')).openFile('page.html'));
23await p.waitForTimeout(300);
24// abre vista previa desde el menú de la pestaña
25await p.locator('#tabs-bar .tab', { hasText: 'page.html' }).click({ button: 'right' });
26await p.waitForTimeout(150);
27await p.click('#tab-menu .tm-item:has-text("Vista previa")');
28await p.waitForTimeout(500);
29
30const frame = p.frameLocator('#md-preview-pane iframe');
31const bg = await frame.locator('body').evaluate(el => getComputedStyle(el).backgroundColor);
32const color = await frame.locator('#marca').evaluate(el => getComputedStyle(el).color);
33const fontSize = await frame.locator('#marca').evaluate(el => getComputedStyle(el).fontSize);
34ok('el CSS externo (link href) se aplica de verdad — background', bg === 'rgb(17, 34, 51)', bg);
35ok('el CSS externo se aplica de verdad — color del texto', color === 'rgb(255, 0, 0)', color);
36ok('el CSS externo se aplica de verdad — font-size', fontSize === '40px', fontSize);
37
38await p.screenshot({ path: OUT + '/htmlpreview_css.png' });
39console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTA PREVIA HTML: CSS EXTERNO SE APLICA DE VERDAD');
40await b.close();
41process.exit(fails ? 1 : 0);