| 1 | // La búsqueda vive fija en la cabecera (como el «command center» de VS Code) y |
| 2 | // no detrás de una lupa en la barra lateral. Pulsarla o escribir en ella abre |
| 3 | // la paleta justo debajo. |
| 4 | import { chromium } from 'playwright'; |
| 5 | const BASE = process.env.BASE || 'http://localhost:8799'; |
| 6 | let fails = 0; |
| 7 | const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; |
| 8 | |
| 9 | const b = await chromium.launch(); |
| 10 | const errs = []; |
| 11 | async function abre(width) { |
| 12 | const ctx = await b.newContext({ viewport: { width, height: 800 }, locale: 'es-ES' }); |
| 13 | await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} }); |
| 14 | const p = await ctx.newPage(); |
| 15 | p.on('pageerror', e => errs.push(e.message.slice(0, 160))); |
| 16 | await p.goto(BASE + '/?test-opfs'); |
| 17 | await p.waitForFunction(() => !!document.querySelector('#editor .monaco-editor'), null, { timeout: 30000 }); |
| 18 | await p.waitForTimeout(400); |
| 19 | return { ctx, p }; |
| 20 | } |
| 21 | const paleta = p => p.evaluate(() => ({ abierta: !document.getElementById('palette').hidden, texto: document.getElementById('pal-input').value })); |
| 22 | |
| 23 | { |
| 24 | const { ctx, p } = await abre(1280); |
| 25 | ok('la lupa de la barra lateral ya no existe', !(await p.$('#act-search'))); |
| 26 | const r = await p.evaluate(() => { const s = document.getElementById('top-search'); const box = s?.getBoundingClientRect(); return { enCabecera: !!s?.closest('header'), visible: !!box?.width, texto: s?.querySelector('.ts-txt')?.textContent, kbd: s?.querySelector('.ts-kbd')?.textContent }; }); |
| 27 | ok('la búsqueda está fija en la cabecera, a la vista', r.enCabecera && r.visible, JSON.stringify(r)); |
| 28 | ok('…dice qué busca y su atajo', /Buscar archivos/.test(r.texto || '') && /P$/.test(r.kbd || ''), JSON.stringify(r)); |
| 29 | ok('⊕ control: antes de tocarla, la paleta está cerrada', !(await paleta(p)).abierta); |
| 30 | await p.click('#top-search'); |
| 31 | await p.waitForTimeout(250); |
| 32 | ok('pulsarla abre la paleta (y se queda abierta)', (await paleta(p)).abierta); |
| 33 | const debajo = await p.evaluate(() => { const s = document.getElementById('top-search').getBoundingClientRect(), q = document.getElementById('palette').getBoundingClientRect(); return { centroBarra: Math.round(s.left + s.width / 2), centroPaleta: Math.round(q.left + q.width / 2), barraAbajo: Math.round(s.bottom), paletaArriba: Math.round(q.top) }; }); |
| 34 | ok('…justo debajo de la barra y con su mismo centro', Math.abs(debajo.centroBarra - debajo.centroPaleta) <= 2 && debajo.paletaArriba >= debajo.barraAbajo && debajo.paletaArriba - debajo.barraAbajo <= 12, JSON.stringify(debajo)); |
| 35 | await p.keyboard.press('Escape'); |
| 36 | await p.waitForTimeout(200); |
| 37 | await p.focus('#top-search'); |
| 38 | await p.keyboard.press('a'); |
| 39 | await p.waitForTimeout(250); |
| 40 | const t = await paleta(p); |
| 41 | ok('con el foco en ella, escribir ya busca (la letra pasa a la paleta)', t.abierta && t.texto === 'a', JSON.stringify(t)); |
| 42 | await ctx.close(); |
| 43 | } |
| 44 | { |
| 45 | const { ctx, p } = await abre(390); |
| 46 | const r = await p.evaluate(() => { const s = document.getElementById('top-search'); const box = s.getBoundingClientRect(); return { visible: box.width > 0, ancho: Math.round(box.width), texto: getComputedStyle(s.querySelector('.ts-txt')).display, scrollX: document.documentElement.scrollWidth > innerWidth }; }); |
| 47 | ok('en el móvil queda como icono y sin desbordar la cabecera', r.visible && r.texto === 'none' && !r.scrollX, JSON.stringify(r)); |
| 48 | await p.click('#top-search'); |
| 49 | await p.waitForTimeout(250); |
| 50 | ok('…y también abre la paleta', (await paleta(p)).abierta); |
| 51 | await ctx.close(); |
| 52 | } |
| 53 | ok('sin errores de página', !errs.length, errs.join(' | ')); |
| 54 | await b.close(); |
| 55 | console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\nTodo en verde'); |
| 56 | process.exit(fails ? 1 : 0); |