| 1 | // Feedback claro al enviar (antes el botón siempre se veía igual, sin |
| 2 | // distinguir enviado/pensando) + Enter explícito tras recuperar del |
| 3 | // historial con ↑ (antes dependía del submit-on-Enter nativo del <form>). |
| 4 | import { chromium } from 'playwright'; |
| 5 | const OUT = (process.env.SCRATCH || '/tmp/elffuss-test'); |
| 6 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 7 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 8 | |
| 9 | const b = await chromium.launch(); |
| 10 | const ctx = await b.newContext(); |
| 11 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 12 | const p = await ctx.newPage(); |
| 13 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); await p.waitForTimeout(1500); |
| 14 | |
| 15 | // proveedor lento para poder observar el estado "enviando" |
| 16 | await p.evaluate(() => { |
| 17 | window.elffussClaw.agent.provider = { |
| 18 | chat: async (h, s, onToken) => { await new Promise(r => setTimeout(r, 1200)); onToken('ok'); return 'ok'; }, |
| 19 | }; |
| 20 | }); |
| 21 | |
| 22 | ok('el botón de enviar empieza normal (sin "sending")', !(await p.locator('#btn-send').evaluate(el => el.classList.contains('sending')))); |
| 23 | await p.fill('#prompt', 'hola'); |
| 24 | await p.press('#prompt', 'Enter'); |
| 25 | await p.waitForTimeout(150); |
| 26 | // Desde 2421c1b el botón NO se deshabilita mientras genera: pasa a ■ Parar. |
| 27 | ok('el botón de enviar pasa a ■ PARAR mientras genera (sending + is-stop, clicable)', await p.locator('#btn-send').evaluate(el => el.classList.contains('sending') && el.classList.contains('is-stop') && !el.disabled)); |
| 28 | await p.waitForTimeout(1500); |
| 29 | ok('al terminar, el botón vuelve a su estado normal', await p.locator('#btn-send').evaluate(el => !el.classList.contains('sending') && !el.disabled)); |
| 30 | |
| 31 | // historial con ArrowUp + Enter EXPLÍCITO (requestSubmit, no submit nativo) |
| 32 | await p.click('#prompt'); |
| 33 | await p.press('#prompt', 'ArrowUp'); |
| 34 | await p.waitForTimeout(80); |
| 35 | const recalled = await p.inputValue('#prompt'); |
| 36 | ok('ArrowUp recupera el último mensaje', recalled === 'hola', recalled); |
| 37 | await p.press('#prompt', 'Enter'); |
| 38 | await p.waitForTimeout(150); |
| 39 | ok('Enter tras ArrowUp limpia el input (se mandó)', (await p.inputValue('#prompt')) === ''); |
| 40 | ok('Enter tras ArrowUp SÍ manda directamente (2 mensajes de usuario)', await p.locator('.msg.user').count() === 2); |
| 41 | |
| 42 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ FEEDBACK DE ENVÍO + HISTORIAL→ENTER OK'); |
| 43 | await b.close(); |
| 44 | process.exit(fails ? 1 : 0); |