| 1 | // Historial del prompt del chat en Claw: ↑/↓ recuperan lo enviado. |
| 2 | import { chromium } from 'playwright'; |
| 3 | import { CHROME_ARGS } from './chrome-args.mjs'; |
| 4 | const BASE = process.env.BASE || 'http://localhost:8788'; |
| 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 | // Ya «bienvenido»: el splash de primera visita es un diálogo modal con el foco |
| 11 | // en «Entrar», y el primer Enter era para él (no se enviaba «hola uno»). |
| 12 | await ctx.addInitScript(() => { try { localStorage.setItem('elffuss.model', 'rules'); localStorage.setItem('elffuss.welcomed', '1'); } catch {} }); |
| 13 | const p = await ctx.newPage({ viewport: { width: 1200, height: 860 } }); |
| 14 | await p.goto(BASE + '/', { waitUntil: 'domcontentloaded' }); |
| 15 | await p.waitForTimeout(1800); |
| 16 | |
| 17 | const val = () => p.locator('#prompt').inputValue(); |
| 18 | const submit = async (t) => { await p.locator('#prompt').fill(t); await p.locator('#prompt').press('Enter'); await p.waitForTimeout(250); }; |
| 19 | |
| 20 | await submit('hola uno'); |
| 21 | await submit('hola dos'); |
| 22 | await p.locator('#prompt').focus(); |
| 23 | await p.keyboard.press('ArrowUp'); |
| 24 | ok('↑ recupera el último', (await val()) === 'hola dos', await val()); |
| 25 | await p.keyboard.press('ArrowUp'); |
| 26 | ok('↑↑ recupera el anterior', (await val()) === 'hola uno', await val()); |
| 27 | await p.keyboard.press('ArrowDown'); |
| 28 | ok('↓ vuelve al siguiente', (await val()) === 'hola dos', await val()); |
| 29 | await p.keyboard.press('ArrowDown'); |
| 30 | ok('↓ al final restaura borrador', (await val()) === '', JSON.stringify(await val())); |
| 31 | |
| 32 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ HISTORIAL CHAT (CLAW) OK'); |
| 33 | await b.close(); |
| 34 | process.exit(fails ? 1 : 0); |