| 1 | // Ajustes: proveedores externos, feedback y «Acerca de». |
| 2 | // · «Servidor Elffuss (Ornith 9B)» ya no se ofrece (el servicio está parado y |
| 3 | // elegirlo fallaba siempre), aunque estuviera activado de antes. |
| 4 | // · La casilla de cada proveedor tiene nombre; al activarla el aviso lleva al |
| 5 | // selector de modelo (no al 🧠). |
| 6 | // · El feedback dice si llegó: si falla, lo dice y el texto se queda. |
| 7 | // · «Acerca de» enlaza el código, la comunidad, las incidencias y la licencia; |
| 8 | // el sello del build enlaza su commit solo si es un commit limpio. |
| 9 | // · Con el teclado el foco no cae a <body>: «Enviar» lo conserva mientras |
| 10 | // envía, y olvidar un hecho (o deshacerlo) lo lleva al ✕ que toca. |
| 11 | // |
| 12 | // BASE=http://localhost:8743 node tests/ux-ajustes.mjs |
| 13 | import { navegador, contexto, pagina, ok, hasta, avisos, fin, BASE } from './ux-comun.mjs'; |
| 14 | |
| 15 | const b = await navegador(); |
| 16 | const { ctx } = await contexto(b, { |
| 17 | extraInit: { 'elffuss.providers': JSON.stringify({ server: { enabled: true, baseURL: 'https://claw.elffuss.com/v1', model: 'ornith-9b', apiKey: '' } }) }, |
| 18 | }); |
| 19 | const { p, errores } = await pagina(ctx); |
| 20 | const foco = () => p.evaluate(() => { |
| 21 | const a = document.activeElement; |
| 22 | return !a || a === document.body ? 'BODY' : (a.getAttribute('aria-label') || a.textContent || a.id).trim().slice(0, 80); |
| 23 | }); |
| 24 | const abrirAjustes = async () => { await p.click('#tabs button[data-tab="ajustes"]'); await p.locator('#panel-ajustes .ext-block').waitFor(); }; |
| 25 | await abrirAjustes(); |
| 26 | await p.click('#panel-ajustes .ext-block > summary'); |
| 27 | ok('el servidor Ornith 9B no se ofrece en Ajustes', !(await p.locator('#panel-ajustes').innerText()).includes('Ornith')); |
| 28 | ok('…ni en el selector aunque estuviera activado de antes', !(await p.evaluate(() => |
| 29 | [...document.querySelectorAll('#model-select option')].some(o => o.value === 'ext:server')))); |
| 30 | |
| 31 | const casilla = p.locator('#prov-ollama'); |
| 32 | ok('la casilla de cada proveedor tiene nombre', await casilla.getAttribute('aria-label') === 'Activar Ollama (local)' |
| 33 | && await p.locator('label[for="prov-ollama"]').count() === 1); |
| 34 | await casilla.check(); |
| 35 | const aviso = p.locator('#toasts .toast', { hasText: 'Ollama' }); |
| 36 | ok('activarlo dice «elígelo en el selector de modelo», no «🧠»', await hasta(async () => /selector de modelo/.test(await aviso.innerText().catch(() => ''))) |
| 37 | && !/🧠/.test(await aviso.innerText())); |
| 38 | ok('…y aparece en el selector', await p.evaluate(() => [...document.querySelectorAll('#model-select option')].some(o => o.value === 'ext:ollama'))); |
| 39 | await aviso.locator('.toast-accion').click(); |
| 40 | ok('su botón lleva al selector de modelo', await p.evaluate(() => document.activeElement?.id === 'model-select')); |
| 41 | |
| 42 | // ── feedback ──────────────────────────────────────────────────────────────── |
| 43 | let estado = 500, recibido = null; |
| 44 | await p.route('**/proxy/report', async route => { recibido = route.request().postDataJSON(); await route.fulfill({ status: estado, body: estado === 200 ? '{"ok":true}' : 'caído' }); }); |
| 45 | await abrirAjustes(); |
| 46 | await p.fill('#tel-feedback', 'el botón X no hace nada'); |
| 47 | await p.locator('#panel-ajustes button:has-text("Enviar")').focus(); |
| 48 | await p.keyboard.press('Enter'); |
| 49 | ok('si el envío falla, lo dice y el texto se queda', await hasta(async () => (await avisos(p)).some(t => /No ha llegado/.test(t))) |
| 50 | && (await p.inputValue('#tel-feedback')) === 'el botón X no hace nada' && !(await avisos(p)).some(t => /gracias/.test(t))); |
| 51 | ok('…y con el teclado el foco sigue en «Enviar» (no cae a <body>)', (await foco()) === 'Enviar', await foco()); |
| 52 | ok('…y ofrece el sitio público de incidencias', await p.locator('#toasts .toast', { hasText: 'No ha llegado' }).locator('.toast-accion').innerText() === 'Abrir incidencias'); |
| 53 | estado = 200; |
| 54 | await p.click('#panel-ajustes button:has-text("Enviar")'); |
| 55 | ok('si llega, da las gracias y vacía el texto', await hasta(async () => (await avisos(p)).some(t => /gracias/.test(t))) |
| 56 | && (await p.inputValue('#tel-feedback')) === '' && recibido?.kind === 'feedback'); |
| 57 | ok('enviar feedback a mano no deja encendido el envío automático', !(await p.evaluate(async () => (await import('/js/telemetry.js')).isEnabled()))); |
| 58 | |
| 59 | // ── acerca de ─────────────────────────────────────────────────────────────── |
| 60 | const acerca = p.locator('#panel-ajustes [data-ruta="acerca"]'); |
| 61 | const hrefs = await acerca.locator('a').evaluateAll(as => as.map(a => [a.getAttribute('href'), a.getAttribute('rel')])); |
| 62 | ok('«Acerca de» enlaza el código, la comunidad y las incidencias (sin referrer)', |
| 63 | hrefs.some(([h]) => h === 'https://github.com/KikoCis/elffuss-claw') && hrefs.some(([h]) => h === 'https://git.elffuss.com/elffuss/claw') |
| 64 | && hrefs.some(([h]) => h === 'https://git.elffuss.com/elffuss/claw/issues') && hrefs.every(([, r]) => r === 'noopener noreferrer'), JSON.stringify(hrefs)); |
| 65 | ok('…dice la licencia y, en desarrollo, que no hay sello', /Apache-2\.0/.test(await acerca.innerText()) && /de desarrollo/.test(await acerca.innerText())); |
| 66 | const sellos = await p.evaluate(async () => { |
| 67 | const ui = await import('/js/ui.js'); |
| 68 | const limpio = ui.enlaceBuild('7b2385c'), sucio = ui.enlaceBuild('7b2385c-dirty'); |
| 69 | return { limpio: limpio.tagName + ' ' + limpio.getAttribute('href'), sucio: sucio.tagName + ' ' + (sucio.getAttribute('href') || '') }; |
| 70 | }); |
| 71 | ok('un sello limpio enlaza su commit en GitHub; uno «-dirty» no enlaza', sellos.limpio === 'A https://github.com/KikoCis/elffuss-claw/commit/7b2385c' && sellos.sucio === 'SPAN ', JSON.stringify(sellos)); |
| 72 | await p.goto(BASE + '/#/ajustes/acerca', { waitUntil: 'domcontentloaded' }); |
| 73 | await p.waitForFunction(() => !!window.elffuss?.agent); |
| 74 | ok('#/ajustes/acerca lleva a esa tarjeta', await hasta(() => p.evaluate(() => |
| 75 | document.querySelector('#panel-ajustes [data-ruta="acerca"]')?.classList.contains('resaltado')))); |
| 76 | |
| 77 | // ── memoria: se ve y se olvida hecho a hecho ──────────────────────────────── |
| 78 | await p.evaluate(async () => { |
| 79 | const db = await import('/js/db.js'); |
| 80 | await db.set('memory', 'mprueba', { id: 'mprueba', fact: 'le gusta el té verde', at: Date.now() }); |
| 81 | await db.set('memory', 'mprueba2', { id: 'mprueba2', fact: 'vive en Madrid', at: Date.now() + 1 }); |
| 82 | }); |
| 83 | await p.goto(BASE + '/#/memoria/mprueba', { waitUntil: 'domcontentloaded' }); |
| 84 | await p.waitForFunction(() => !!window.elffuss?.agent); |
| 85 | const hecho = p.locator('#panel-ajustes [data-ruta="mprueba"]'); |
| 86 | ok('#/memoria/<id> abre Ajustes y señala ese hecho (sin el texto en la URL)', await hasta(async () => |
| 87 | await hecho.evaluate(e => e.classList.contains('resaltado')).catch(() => false)) && !/t%C3%A9|té/.test(await p.evaluate(() => location.href))); |
| 88 | await hecho.locator('button[aria-label="Olvidar «le gusta el té verde»"]').focus(); |
| 89 | await p.keyboard.press('Enter'); |
| 90 | ok('✕ lo olvida…', await hasta(async () => await hecho.count() === 0) |
| 91 | && !(await p.evaluate(async () => (await (await import('/js/db.js')).get('memory', 'mprueba'))))); |
| 92 | ok('…con el teclado, el foco va al ✕ del hecho que queda en su sitio', await hasta(async () => (await foco()) === 'Olvidar «vive en Madrid»'), await foco()); |
| 93 | await p.locator('#toasts .toast', { hasText: 'Olvidado' }).locator('.toast-accion').focus(); |
| 94 | await p.keyboard.press('Enter'); |
| 95 | ok('…y «Deshacer» lo devuelve', await hasta(async () => await hecho.count() === 1)); |
| 96 | ok('…con el foco en su ✕', await hasta(async () => (await foco()) === 'Olvidar «le gusta el té verde»'), await foco()); |
| 97 | ok('el lema de la cabecera sale en español', (await p.locator('.brand .claim').first().innerText()) === 'las apps no existen: se crean'); |
| 98 | |
| 99 | // ── el modo básico señala el selector de modelo, no el 🧠 ─────────────────── |
| 100 | await p.fill('#prompt', 'hola'); |
| 101 | await p.press('#prompt', 'Enter'); |
| 102 | const enlace = p.locator('#log .msg.assistant a[href="#/modelo"]').last(); |
| 103 | ok('la ayuda del modo básico enlaza al «selector de modelo»', await hasta(async () => await enlace.count() === 1) |
| 104 | && !/selector 🧠/.test(await p.locator('#log').innerText())); |
| 105 | await enlace.click(); |
| 106 | ok('…y el enlace lo enfoca (y la URL vuelve a decir dónde estás)', await hasta(() => p.evaluate(() => |
| 107 | document.activeElement?.id === 'model-select' && location.hash !== '#/modelo'))); |
| 108 | |
| 109 | { |
| 110 | const { ctx: c2 } = await contexto(b, { locale: 'en-US' }); |
| 111 | const { p: e } = await pagina(c2); |
| 112 | ok('en inglés el lema de la cabecera sale en inglés', (await e.locator('.brand .claim').first().innerText()) === 'apps don’t exist: they get created'); |
| 113 | await c2.close(); |
| 114 | } |
| 115 | |
| 116 | ok('sin errores de página', errores.length === 0, errores.slice(0, 3).join(' | ')); |
| 117 | await fin(b, 'AJUSTES: sin Ornith roto, casillas con nombre, feedback honesto y «Acerca de» con enlaces'); |