| 1 | // Móvil: el cajón ☰ con el árbol y las herramientas. |
| 2 | // |
| 3 | // En un teléfono la barra de actividad, el árbol y la barra de menús están |
| 4 | // ocultos, así que en la vista Editor no había forma de abrir un fichero (solo |
| 5 | // enlaces del chat o @) y la Mente, el terminal, las vistas 3D y las skills |
| 6 | // eran inalcanzables. Ahora ☰ abre un cajón con todo eso. |
| 7 | // |
| 8 | // BASE=http://127.0.0.1:8898 node tests/mobile-drawer.mjs |
| 9 | import { chromium } from 'playwright'; |
| 10 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 11 | let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 12 | |
| 13 | const b = await chromium.launch(); |
| 14 | const ctx = await b.newContext({ locale: 'es-ES', viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true }); |
| 15 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 16 | await ctx.route(/soundcloud/, r => r.abort()); |
| 17 | const p = await ctx.newPage(); |
| 18 | const errs = []; p.on('pageerror', e => errs.push(e.message.slice(0, 160))); |
| 19 | |
| 20 | await p.goto(BASE + '/manifest.json'); |
| 21 | await p.evaluate(async () => { |
| 22 | const root = await navigator.storage.getDirectory(); |
| 23 | const w = await (await root.getFileHandle('README.md', { create: true })).createWritable(); await w.write('# Hola\n'); await w.close(); |
| 24 | }); |
| 25 | await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 26 | await p.waitForFunction(() => window.monaco && document.querySelector('#tree [data-path]'), null, { timeout: 30000 }); |
| 27 | const visible = sel => p.evaluate(sel => { const e = document.querySelector(sel); if (!e) return false; const r = e.getBoundingClientRect(); return r.width > 0 && r.height > 0 && getComputedStyle(e).display !== 'none'; }, sel); |
| 28 | |
| 29 | ok('en el móvil, el árbol y la barra de actividad empiezan ocultos', !(await visible('#sidebar')) && !(await visible('#activity'))); |
| 30 | ok('…y hay un botón ☰', await visible('#btn-drawer')); |
| 31 | await p.tap('#btn-drawer'); |
| 32 | await p.waitForTimeout(200); |
| 33 | ok('☰ abre el cajón con el árbol y las herramientas', await visible('#sidebar') && await visible('#activity') && await visible('#act-term') && await p.evaluate(() => document.getElementById('btn-drawer').getAttribute('aria-expanded') === 'true')); |
| 34 | await p.tap('#tree .file[data-path="README.md"]'); |
| 35 | await p.waitForTimeout(400); |
| 36 | const trasAbrir = await p.evaluate(() => ({ editor: document.body.classList.contains('show-editor'), cajon: document.body.classList.contains('drawer-open'), activa: document.querySelector('#tabs-bar .tab.active')?.dataset.path })); |
| 37 | ok('un fichero del cajón se abre en la vista Editor y el cajón se cierra', trasAbrir.editor && !trasAbrir.cajon && trasAbrir.activa === 'README.md', JSON.stringify(trasAbrir)); |
| 38 | await p.tap('#btn-drawer'); |
| 39 | await p.waitForTimeout(150); |
| 40 | await p.tap('#act-term'); |
| 41 | await p.waitForTimeout(400); |
| 42 | ok('desde el cajón se llega al terminal', await visible('#terminal-panel') && !(await p.evaluate(() => document.body.classList.contains('drawer-open')))); |
| 43 | await p.tap('#btn-drawer'); |
| 44 | await p.waitForTimeout(150); |
| 45 | await p.keyboard.press('Escape'); |
| 46 | await p.waitForTimeout(150); |
| 47 | ok('Escape cierra el cajón y devuelve el foco a ☰', await p.evaluate(() => !document.body.classList.contains('drawer-open'))); |
| 48 | await p.tap('#btn-drawer'); |
| 49 | await p.waitForTimeout(150); |
| 50 | await p.tap('#act-mind'); |
| 51 | await p.waitForSelector('#mind-overlay', { timeout: 45000 }).catch(() => {}); |
| 52 | ok('desde el cajón se llega a la Mente', await p.evaluate(() => !!document.getElementById('mind-overlay') && getComputedStyle(document.getElementById('mind-overlay')).display !== 'none')); |
| 53 | |
| 54 | console.log('\n errores JS:', errs[0] || 'ninguno'); |
| 55 | ok('sin errores de página', errs.length === 0, errs.join(' | ')); |
| 56 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ MÓVIL: EL CAJÓN LLEVA A TODO'); |
| 57 | await b.close(); |
| 58 | process.exit(fails ? 1 : 0); |