gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit0433e9a80433e9a8jukebox: records: gitoria remote added and pushedmre0433e9a8/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 button.jb-prev', '.jb-bar .mp-back', '.jb-bar .mp-play', '.jb-bar .mp-forward', '.jb-bar button.jb-next', '.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

  • 0433e9a8jukebox: records: gitoria remote added and pushedmre
  • 1722d707jukebox: records: repo creation handed to Gitoriamre
  • b42e7dfbjukebox: conductor records (CONDUCTOR.md, STATUS.md), old STATUS archivedmre
  • 1b0d0bc1jukebox: a startup error prints its message before exit 1 (hybriel#247)mre
  • b19c478bjukebox JB18 (jukebox#17): onto Hybriel set-day31 (b287cd82, contains the SIGPIPE fix 6d2ca454): plugins/core and plugins/web re-vendored, bin/ from the set; a client that closes /stream while it is written no longer kills the server (90 aborted streams survived, the old bin died with exit 141 on the first)mre
  • 73867a2ejukebox#2: Style blocks in the language's nested form (rules named after the View's own elements, pseudo-classes nested, merged duplicates); the same CSS rules, the pages look the samemre
  • 06c548d6jukebox JB15: report, log linemre
  • 980859cbjukebox JB15 (jukebox#15): the now-playing overlay on a short screen (tablet or phone on its side) gave the queue 12 to 100 px because the big cover took the room; the cover now shrinks with the screen height and goes away under 41rem, the queue keeps 3+ rows; gate tests/jb15.mjs at 8 sizesmre
  • 9efc40ffjukebox#12 #14: Grok session 1793246574527-181160mre
  • 7d58b36ejukebox JB13 (jukebox#13): Next and Previous ask for the songs after / before the current song's id in the current order, not for place + 1; gate tests/jb13.mjs checks Next with the queue down to one song after the order changedmre
  • 51358794jukebox JB14 (jukebox#14): the Songs screen opens sorted the way it was left (kept on the server in storage/ui.json), the sort control shows the sort the rows really have (selected options, autocomplete off); gate tests/jb14.mjsmre
  • cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mre
  • 88d3d5c1jukebox JB12b (jukebox#12): the scroll handle is big (2.75rem x 4rem, accent colour, grip) and drawn on every device, no media query; native bar hidden; gate tests/touch.mjs checks the drawn width with and without touchmre
  • b58e4495jukebox JB11 (jukebox#11): the next song starts in the ended event on the same audio element, so it also starts with the screen locked; gate tests/jb11.mjs (hidden tab, no frames)mre
  • 12a26233jukebox JB12 (jukebox#12): the long lists get a scroll handle a finger can use on touch screens (44 px tap area, slim look, drag through all rows), gate tests/touch.mjsmre
  • 0f2157a9jukebox JV1: onto Hybriel set-day27b: readBytes and stat for /stream and the mp3 tags (no dd, head or tail), startup fault exits 1, fs and mpackdb plugins re-vendored; songs with a comma in the title are indexed againmre
  • 63d0f2eejukebox ST1 (jukebox#2): styles of main, songs and search moved into their own Style blocks (styles.hl 81 to 8 rules, pixel-identical at 390 and 1280); artist and album wait for an hl:web fixmre
  • c5b8fde9jukebox JB3b: keyboard gap repro as a reportmre
  • 9daebb4bjukebox JB3b: shuffle, now-playing overlay, next and previous, play counting, media session, gates; keyboard left open (Hybriel gap)mre
  • 59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre