Elffuss BraidHub

utopia-ia/elffuss-code public

9255fd1f0dc0 · 6.8 KiBRawPermalink
1// La landing: sin píldora fantasma y sin fallos mudos.
2//
3// 1. Sin descarga a medias, la píldora «Reanudar / Descartar» NO se ve. Antes
4// `.resume-clone { display:flex }` le ganaba al atributo hidden y salía
5// siempre, vacía y con dos botones sin manejador (también en producción).
6// 2. Con una descarga a medias sí sale, enlaza owner/repo al repositorio y
7// «Descartar» la quita.
8// 3. Clonar: URL vacía o no reconocida se dice ANTES de abrir el selector de
9// carpeta (antes se elegía carpeta y luego fallaba, o no pasaba nada).
10// 4. Abrir carpeta: cancelar el selector no es un error; cualquier otro fallo
11// se dice en la landing.
12// 5. Sin File System Access (Firefox, Safari): los botones que no pueden
13// funcionar se desactivan con el motivo, y se ofrece probar en la carpeta
14// privada del navegador.
15// Nada sale a la red: el selector de carpetas va de mentira y nunca se llega a
16// listar un repo.
17//
18// BASE=http://127.0.0.1:8898 node tests/landing.mjs
19import { chromium } from 'playwright';
20const BASE = process.env.BASE || 'http://localhost:8799';
21let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
22
23const b = await chromium.launch();
24const errs = [];
25const nueva = async ({ sinSelector = false } = {}) => {
26 const ctx = await b.newContext({ locale: 'es-ES' });
27 await ctx.addInitScript((sinSelector) => {
28 try { localStorage.setItem('elffusscode.model', 'rules'); } catch {}
29 if (sinSelector) { delete window.showDirectoryPicker; return; }
30 window.__picker = { llamadas: 0, error: 'AbortError' };
31 window.showDirectoryPicker = async () => { window.__picker.llamadas++; throw new DOMException('selector de prueba', window.__picker.error); };
32 }, sinSelector);
33 const p = await ctx.newPage({ viewport: { width: 1300, height: 850 } });
34 p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
35 return { ctx, p };
36};
37const estado = (p) => p.evaluate(() => document.getElementById('clone-status').textContent);
38
39// 1 · píldora oculta sin descarga a medias
40let { ctx, p } = await nueva();
41await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
42await p.waitForTimeout(1200);
43const pildora = await p.evaluate(() => {
44 const el = document.getElementById('resume-clone');
45 return { display: getComputedStyle(el).display, visible: !!(el.offsetWidth || el.offsetHeight) };
46});
47ok('1 · sin descarga a medias, la píldora Reanudar/Descartar no se ve', pildora.display === 'none' && !pildora.visible, JSON.stringify(pildora));
48ok('1 · …y sus botones no son paradas del tabulador', !(await p.locator('#resume-clone-btn').isVisible()) && !(await p.locator('#discard-clone-btn').isVisible()));
49
50// 3 · clonar: validar antes del selector
51await p.click('#clone-btn');
52await p.waitForTimeout(150);
53ok('3 · URL vacía: lo dice y no abre el selector', /Pega la URL/.test(await estado(p)) && await p.evaluate(() => window.__picker.llamadas) === 0, await estado(p));
54await p.fill('#clone-url', 'esto no es un repo');
55await p.press('#clone-url', 'Enter');
56await p.waitForTimeout(200);
57ok('3 · URL no reconocida: lo dice ANTES de abrir el selector', /URL no reconocida/.test(await estado(p)) && await p.evaluate(() => window.__picker.llamadas) === 0, await estado(p));
58await p.fill('#clone-url', 'https://github.com/octo/demo');
59await p.click('#clone-btn');
60await p.waitForTimeout(200);
61ok('3 · URL válida: abre el selector; cancelarlo no es un error', await p.evaluate(() => window.__picker.llamadas) === 1 && !/⚠️/.test(await estado(p)), await estado(p));
62
63// 4 · abrir carpeta: cancelar calla, otro fallo se dice
64await p.click('#open-project');
65await p.waitForTimeout(150);
66ok('4 · cancelar el selector de «Abrir carpeta» no muestra error', !/⚠️/.test(await estado(p)), await estado(p));
67await p.evaluate(() => { window.__picker.error = 'SecurityError'; });
68await p.click('#open-project');
69await p.waitForTimeout(150);
70ok('4 · cualquier otro fallo al abrir se dice en la landing', /No pude abrir la carpeta/.test(await estado(p)), await estado(p));
71
72// 2 · con descarga a medias: píldora visible, enlace y Descartar
73await p.evaluate(async () => {
74 const db = await import('/js/db.js');
75 const handle = await navigator.storage.getDirectory();
76 await db.set('kv', 'cloneJob', { url: 'https://github.com/octo/demo', host: 'github', owner: 'octo', repo: 'demo', branch: 'main', handle, files: [{ path: 'a.txt' }, { path: 'b.txt' }], done: ['a.txt'], skipped: 0 });
77});
78await p.reload({ waitUntil: 'domcontentloaded' });
79await p.waitForTimeout(1200);
80const banner = await p.evaluate(() => {
81 const el = document.getElementById('resume-clone');
82 const a = el.querySelector('.rc-text a');
83 return { visible: !!(el.offsetWidth || el.offsetHeight), texto: el.querySelector('.rc-text').textContent, href: a?.href, rel: a?.rel };
84});
85ok('2 · con una descarga a medias, la píldora sale con su progreso', banner.visible && /octo\/demo \(1\/2 ficheros\)/.test(banner.texto), JSON.stringify(banner));
86ok('2 · owner/repo enlaza al repositorio', banner.href === 'https://github.com/octo/demo' && /noopener/.test(banner.rel), JSON.stringify(banner));
87await p.click('#discard-clone-btn');
88await p.waitForTimeout(200);
89const trasDescartar = await p.evaluate(async () => {
90 const db = await import('/js/db.js');
91 return { visible: !!document.getElementById('resume-clone').offsetHeight, job: await db.get('kv', 'cloneJob') };
92});
93ok('2 · Descartar quita la píldora y olvida la descarga', !trasDescartar.visible && !trasDescartar.job, JSON.stringify(trasDescartar));
94await ctx.close();
95
96// 5 · navegador sin File System Access
97({ ctx, p } = await nueva({ sinSelector: true }));
98await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
99await p.waitForTimeout(1200);
100const sinFS = await p.evaluate(() => ({
101 abrir: document.getElementById('open-project').disabled, clonar: document.getElementById('clone-btn').disabled,
102 motivo: document.getElementById('clone-status').textContent, probar: !document.getElementById('try-browser').hidden,
103}));
104ok('5 · sin File System Access: abrir y clonar desactivados, con el motivo', sinFS.abrir && sinFS.clonar && /Chrome o Edge/.test(sinFS.motivo), JSON.stringify(sinFS));
105ok('5 · …y se ofrece probar en el navegador', sinFS.probar);
106await p.click('#try-browser');
107await p.waitForFunction(() => !document.getElementById('ide').hidden, null, { timeout: 30000 }).catch(() => {});
108ok('5 · «Probar en el navegador» abre el IDE', await p.evaluate(() => !document.getElementById('ide').hidden));
109await ctx.close();
110
111console.log('\n errores JS:', errs[0] || 'ninguno');
112ok('sin errores de página', errs.length === 0, errs.join(' | '));
113console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ LANDING SIN PÍLDORA FANTASMA NI FALLOS MUDOS');
114await b.close();
115process.exit(fails ? 1 : 0);