| 1 | // El interruptor </> Auto (barra) ahora también vive en Ajustes → Permisos de |
| 2 | // ejecución, como el mismo estado (misma clave de localStorage) — para que se |
| 3 | // pueda ver/gestionar desde un único sitio, sin tener que ir a la barra. |
| 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 | // Etiquetas en español (la interfaz sigue al idioma del navegador desde 7d5e790). |
| 11 | const ctx = await b.newContext({ locale: 'es-ES' }); |
| 12 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 13 | const p = await ctx.newPage(); |
| 14 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 15 | await p.waitForTimeout(1500); |
| 16 | |
| 17 | ok('por defecto, </> Auto está en modo automático (sin preguntar)', await p.evaluate(() => localStorage.getItem('elffusscode.autoedit') !== '0')); |
| 18 | |
| 19 | await p.click('#btn-settings'); |
| 20 | await p.waitForTimeout(300); |
| 21 | const checkbox = p.locator('#perm-autoedit'); |
| 22 | ok('el checkbox de Ajustes existe y aparece marcado por defecto', await checkbox.isChecked()); |
| 23 | |
| 24 | // desmarcarlo desde Ajustes debe apagar el modo auto también en la barra |
| 25 | await checkbox.uncheck(); |
| 26 | await p.waitForTimeout(150); |
| 27 | ok('desmarcar en Ajustes actualiza localStorage a modo Revisar', await p.evaluate(() => localStorage.getItem('elffusscode.autoedit') === '0')); |
| 28 | await p.click('#btn-settings'); // cerrar |
| 29 | await p.waitForTimeout(200); |
| 30 | const btnText = await p.locator('#btn-autoedit .ae-txt').innerText(); |
| 31 | ok('el botón </> de la barra refleja "Revisar" tras desmarcar en Ajustes', btnText === 'Revisar', btnText); |
| 32 | |
| 33 | // volver a marcarlo desde la BARRA debe reflejarse en Ajustes al reabrir. Desde |
| 34 | // 43f95b7 el interruptor vive en el menú «⚙︎ Modos»: se abre y se pulsa. |
| 35 | if (await p.locator('#modos-menu').isHidden()) await p.click('#btn-modos'); |
| 36 | await p.click('#btn-autoedit'); |
| 37 | await p.waitForTimeout(150); |
| 38 | await p.click('#btn-settings'); |
| 39 | await p.waitForTimeout(300); |
| 40 | ok('el checkbox de Ajustes refleja "Auto" tras activarlo desde la barra', await p.locator('#perm-autoedit').isChecked()); |
| 41 | |
| 42 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ PERMISOS DE EJECUCIÓN: mismo estado en Ajustes y en la barra'); |
| 43 | await b.close(); |
| 44 | process.exit(fails ? 1 : 0); |