Elffuss BraidHub

utopia-ia/elffuss-code public

7c24e7b60e19 · 1.9 KiBRawPermalink
1// Historial del prompt del chat: ↑/↓ recuperan lo enviado y ciclan.
2import { chromium } from 'playwright';
3const BASE = process.env.BASE || 'http://localhost:8799';
4let fails = 0;
5const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
6
7const b = await chromium.launch({ args: ['--enable-unsafe-webgpu', '--use-angle=metal'] });
8const ctx = await b.newContext();
9await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
10const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
11await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
12await p.waitForTimeout(1500);
13
14const val = () => p.locator('#prompt').inputValue();
15const submit = async (t) => { await p.locator('#prompt').fill(t); await p.locator('#prompt').press('Enter'); await p.waitForTimeout(250); };
16
17await submit('primer mensaje');
18await submit('segundo mensaje');
19ok('el prompt se vacía al enviar', (await val()) === '');
20
21await p.locator('#prompt').focus();
22await p.keyboard.press('ArrowUp');
23ok('↑ recupera el último enviado', (await val()) === 'segundo mensaje', await val());
24await p.keyboard.press('ArrowUp');
25ok('↑↑ recupera el anterior', (await val()) === 'primer mensaje', await val());
26await p.keyboard.press('ArrowDown');
27ok('↓ vuelve al siguiente', (await val()) === 'segundo mensaje', await val());
28await p.keyboard.press('ArrowDown');
29ok('↓ al final restaura el borrador vacío', (await val()) === '', JSON.stringify(await val()));
30
31// persistencia entre recargas
32await p.reload({ waitUntil: 'domcontentloaded' });
33await p.waitForTimeout(1200);
34await p.locator('#prompt').focus();
35await p.keyboard.press('ArrowUp');
36ok('el historial persiste tras recargar', (await val()) === 'segundo mensaje', await val());
37
38console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ HISTORIAL DEL CHAT OK');
39await b.close();
40process.exit(fails ? 1 : 0);