gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8ed6da458ed6da45|||PR README: media-player pin df9e7dfmre8ed6da45/tests/jb15.mjs

6.5 KB

  1. // 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
  2. // 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
  3. // 100 px or less (the big cover took the room), so the section at the bottom was cut off after a row or less.
  4. // 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).
  5. // node tests/jb15.mjs env: JB15_PORT (default 8721), JB15_DIR (scratch), JB15_ROOT (checkout to test), HL_PORT_BASE (default 8540), JUKEBOX_COLD_MS
  6. import { spawn, execFileSync } from 'node:child_process'
  7. import { rmSync, mkdirSync, writeFileSync } from 'node:fs'
  8. import { dirname, join } from 'node:path'
  9. import { fileURLToPath } from 'node:url'
  10. process.env.HL_CHROME = process.env.HL_CHROME || '/opt/google/chrome/chrome'
  11. process.env.HL_PORT_BASE = process.env.HL_PORT_BASE || '8540'
  12. const { launchBrowser, sleep } = await import('./cdp.mjs')
  13. const root = process.env.JB15_ROOT || join(dirname(fileURLToPath(import.meta.url)), '..')
  14. const dir = process.env.JB15_DIR || '/media/STORAGE/claude-scratch/atlas/JB15/gate'
  15. const port = Number(process.env.JB15_PORT || 8721)
  16. const BASE = `http://127.0.0.1:${port}`
  17. const COLD_MS = Number(process.env.JUKEBOX_COLD_MS || 150000)
  18. let pass = 0, fail = 0
  19. const check = (name, ok, detail = '') => { console.log((ok ? 'ok ' : 'FAIL ') + name + (ok ? '' : ' — ' + detail)); if (ok) pass++; else fail++ }
  20. mkdirSync(dir, { recursive: true })
  21. process.env.TMPDIR = dir
  22. let server = null, browser = null, log = ''
  23. async function stop() {
  24. if (browser) { try { await browser.close() } catch {} browser = null }
  25. if (server) { try { server.kill('SIGTERM') } catch {} await sleep(500); server = null }
  26. }
  27. process.on('SIGINT', async () => { await stop(); process.exit(1) })
  28. const storage = join(dir, 'storage')
  29. const tone = join(dir, 'tone300.mp3')
  30. rmSync(storage, { recursive: true, force: true })
  31. execFileSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=300', '-q:a', '9', tone])
  32. const cover = join(root, 'tests/fixtures/withcover/folder.jpg')
  33. 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 })
  34. 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'] })
  35. console.log('server pid ' + server.pid)
  36. server.stdout.on('data', (d) => { log += d }); server.stderr.on('data', (d) => { log += d })
  37. const SIZES = [[390, 844], [844, 390], [800, 1280], [1280, 800], [1024, 768], [1280, 900], [1280, 600], [1024, 552]]
  38. try {
  39. for (const t0 = Date.now(); ; ) {
  40. try { if ((await fetch(BASE + '/api/stats')).ok) break } catch {}
  41. if (Date.now() - t0 > COLD_MS) { console.log(log); throw new Error('the server did not come up') }
  42. await sleep(500)
  43. }
  44. browser = await launchBrowser()
  45. console.log('chrome pid ' + browser.proc?.pid)
  46. const page = await browser.newPage()
  47. const ev = (e) => page.evaluate(e)
  48. await page.send('Emulation.setDeviceMetricsOverride', { width: 800, height: 1280, deviceScaleFactor: 1, mobile: false })
  49. await page.goto(BASE + '/')
  50. await page.waitForSelector('virtual-list .vl-row:not(.blank)')
  51. await sleep(1200)
  52. await page.click('virtual-list .vl-row[data-index="2"]')
  53. await page.waitFor(`(() => { const a = document.querySelector('media-player audio'); return a && a.currentSrc.indexOf('/stream/') > 0 })()`, { timeout: 20000, label: 'a song plays' })
  54. await ev(`document.querySelector('media-player audio').pause()`)
  55. for (const [w, h] of SIZES) {
  56. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: false })
  57. await sleep(400)
  58. if (await ev(`!document.querySelector('.jb-app').classList.contains('open')`)) { await page.click('.jb-bar media-player .mp-cover'); await sleep(500) }
  59. const m = await ev(`(() => {
  60. const vh = innerHeight, vw = innerWidth
  61. const q = document.querySelector('.jb-bar media-player > div:not(.mp-cover)')
  62. 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 }
  63. 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)])
  64. const items = [...q.querySelectorAll('ol.mp-queue li')].filter((li) => getComputedStyle(li).display !== 'none')
  65. q.scrollTop = q.scrollHeight
  66. const last = items[items.length - 1].getBoundingClientRect(), qb = q.getBoundingClientRect()
  67. const bar = document.querySelector('.jb-bar')
  68. 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] }
  69. })()`)
  70. const bad = m.controls.filter(([, r]) => r !== 'ok')
  71. check(`${w}x${h}: every control of the overlay is inside the screen`, bad.length === 0, JSON.stringify(bad))
  72. check(`${w}x${h}: the queue has room for at least 3 rows (${m.qh} px)`, m.qh >= 3 * 44, 'queue ' + m.qh + ' px')
  73. 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 }))
  74. check(`${w}x${h}: the overlay itself does not overflow`, m.barScroll[0] <= m.barScroll[1] + 1, JSON.stringify(m.barScroll))
  75. // the close button really closes it, and the screen under it is usable again
  76. }
  77. await page.click('.jb-close')
  78. await page.waitFor(`!document.querySelector('.jb-app').classList.contains('open')`, { label: 'closed' })
  79. check('the close button closes the overlay', true)
  80. } catch (e) {
  81. check('gate ran to the end', false, String(e && e.message || e))
  82. } finally {
  83. await stop()
  84. }
  85. console.log(`${pass} passed, ${fail} failed`)
  86. 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