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