jukebox
All repositories: gitoria
6.5 KB
// tests/jb15.mjs — JB15 (jukebox#15): the now-playing overlay must show ALL its controls and a usable part of the queue at every screen size, and the// last queued song must be reachable (scrolled into view). Before the fix a short screen (a tablet in landscape, a phone on its side) gave the queue// 100 px or less (the big cover took the room), so the section at the bottom was cut off after a row or less.// Own server on a generated database of 300 songs, headless Chrome (a gate; the proof of the change itself is done in his Chrome on lisbeth, see the report).// node tests/jb15.mjs env: JB15_PORT (default 8721), JB15_DIR (scratch), JB15_ROOT (checkout to test), HL_PORT_BASE (default 8540), JUKEBOX_COLD_MSimport { spawn, execFileSync } from 'node:child_process'import { rmSync, mkdirSync, writeFileSync } from 'node:fs'import { dirname, join } from 'node:path'import { fileURLToPath } from 'node:url'process.env.HL_CHROME = process.env.HL_CHROME || '/opt/google/chrome/chrome'process.env.HL_PORT_BASE = process.env.HL_PORT_BASE || '8540'const { launchBrowser, sleep } = await import('./cdp.mjs')const root = process.env.JB15_ROOT || join(dirname(fileURLToPath(import.meta.url)), '..')const dir = process.env.JB15_DIR || '/media/STORAGE/claude-scratch/atlas/JB15/gate'const port = Number(process.env.JB15_PORT || 8721)const BASE = `http://127.0.0.1:${port}`const COLD_MS = Number(process.env.JUKEBOX_COLD_MS || 150000)let pass = 0, fail = 0const check = (name, ok, detail = '') => { console.log((ok ? 'ok ' : 'FAIL ') + name + (ok ? '' : ' — ' + detail)); if (ok) pass++; else fail++ }mkdirSync(dir, { recursive: true })process.env.TMPDIR = dirlet server = null, browser = null, log = ''async function stop() {if (browser) { try { await browser.close() } catch {} browser = null }if (server) { try { server.kill('SIGTERM') } catch {} await sleep(500); server = null }}process.on('SIGINT', async () => { await stop(); process.exit(1) })const storage = join(dir, 'storage')const tone = join(dir, 'tone300.mp3')rmSync(storage, { recursive: true, force: true })execFileSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=300', '-q:a', '9', tone])const cover = join(root, 'tests/fixtures/withcover/folder.jpg')execFileSync(join(root, 'bin/hybriel'), [join(root, 'tools/make-test-db.hl'), tone, cover, '300'], { env: { ...process.env, JUKEBOX_STORAGE: storage }, encoding: 'utf8', timeout: 600000 })server = spawn(join(root, 'bin/hybriel'), ['project.hl'], { cwd: root, env: { ...process.env, JUKEBOX_PORT: String(port), JUKEBOX_STORAGE: storage, JUKEBOX_AUTOSCAN: '0', JUKEBOX_WATCH: '0', HL_HOST: '127.0.0.1' }, stdio: ['ignore', 'pipe', 'pipe'] })console.log('server pid ' + server.pid)server.stdout.on('data', (d) => { log += d }); server.stderr.on('data', (d) => { log += d })const SIZES = [[390, 844], [844, 390], [800, 1280], [1280, 800], [1024, 768], [1280, 900], [1280, 600], [1024, 552]]try {for (const t0 = Date.now(); ; ) {try { if ((await fetch(BASE + '/api/stats')).ok) break } catch {}if (Date.now() - t0 > COLD_MS) { console.log(log); throw new Error('the server did not come up') }await sleep(500)}browser = await launchBrowser()console.log('chrome pid ' + browser.proc?.pid)const page = await browser.newPage()const ev = (e) => page.evaluate(e)await page.send('Emulation.setDeviceMetricsOverride', { width: 800, height: 1280, deviceScaleFactor: 1, mobile: false })await page.goto(BASE + '/')await page.waitForSelector('virtual-list .vl-row:not(.blank)')await sleep(1200)await page.click('virtual-list .vl-row[data-index="2"]')await page.waitFor(`(() => { const a = document.querySelector('media-player audio'); return a && a.currentSrc.indexOf('/stream/') > 0 })()`, { timeout: 20000, label: 'a song plays' })await ev(`document.querySelector('media-player audio').pause()`)for (const [w, h] of SIZES) {await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: false })await sleep(400)if (await ev(`!document.querySelector('.jb-app').classList.contains('open')`)) { await page.click('.jb-bar media-player .mp-cover'); await sleep(500) }const m = await ev(`(() => {const vh = innerHeight, vw = innerWidthconst q = document.querySelector('.jb-bar media-player > div:not(.mp-cover)')const inside = (s) => { const e = document.querySelector(s); if (!e) return 'missing'; const b = e.getBoundingClientRect(); const cs = getComputedStyle(e); if (cs.display === 'none') return 'hidden'; return (b.top >= -1 && b.bottom <= vh + 1 && b.left >= -1 && b.right <= vw + 1) ? 'ok' : 'outside ' + Math.round(b.top) + '..' + Math.round(b.bottom) + ' of ' + vh }const controls = ['.jb-close', '.jb-bar mp-seek', '.jb-bar #jb-shuffle', '.jb-bar button.jb-prev', '.jb-bar .mp-play', '.jb-bar button.jb-next', '.jb-bar #jb-repeat', '.jb-bar .mp-times', '.jb-bar .mp-mute', '.jb-bar .mp-speed'].map((s) => [s, inside(s)])const items = [...q.querySelectorAll('ol.mp-queue li')].filter((li) => getComputedStyle(li).display !== 'none')q.scrollTop = q.scrollHeightconst last = items[items.length - 1].getBoundingClientRect(), qb = q.getBoundingClientRect()const bar = document.querySelector('.jb-bar')return { controls, qh: Math.round(qb.height), n: items.length, lastIn: last.bottom <= qb.bottom + 1 && last.bottom <= vh + 1 && last.top >= qb.top - 1, rem: parseFloat(getComputedStyle(document.documentElement).fontSize), barScroll: [bar.scrollHeight, bar.clientHeight] }})()`)const bad = m.controls.filter(([, r]) => r !== 'ok')check(`${w}x${h}: every control of the overlay is inside the screen`, bad.length === 0, JSON.stringify(bad))check(`${w}x${h}: the queue has room for at least 3 rows (${m.qh} px)`, m.qh >= 3 * 44, 'queue ' + m.qh + ' px')check(`${w}x${h}: the last queued song can be scrolled into view`, m.lastIn && m.n >= 20, JSON.stringify({ lastIn: m.lastIn, n: m.n }))check(`${w}x${h}: the overlay itself does not overflow`, m.barScroll[0] <= m.barScroll[1] + 1, JSON.stringify(m.barScroll))// the close button really closes it, and the screen under it is usable again}await page.click('.jb-close')await page.waitFor(`!document.querySelector('.jb-app').classList.contains('open')`, { label: 'closed' })check('the close button closes the overlay', true)} catch (e) {check('gate ran to the end', false, String(e && e.message || e))} finally {await stop()}console.log(`${pass} passed, ${fail} failed`)process.exit(fail ? 1 : 0)
Branches
Latest commits
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
- 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
- 1fecd6a7Merge branch 'records-day39' into mainJukebox
- d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
- 5fa19e89Merge branch 'day39' into mainJukebox
- cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
- f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
- 9f5c6532Merge branch 'status-22-pr' into mainJukebox
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre