gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit12a2623312a26233jukebox 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.mjsmre12a26233/tests/touch.mjs

12.2 KB

  1. // tests/touch.mjs — jukebox#12: THE LIST'S SCROLL HANDLE FOR A FINGER. A real headless Chrome with touch emulation (so `pointer: coarse` is true) on a generated database of
  2. // 13,450 songs (tools/make-test-db.hl): the virtual list must show a handle at least 44 px wide, drawn slim (the width is a transparent border), that follows the scroll position,
  3. // and a touch drag from the top of the list to the bottom must land on the last song. Desktop (a mouse) keeps the browser's own scroll bar: no handle there.
  4. // Fails on the code before JB12 (no handle exists). Screenshots at 390, 800 and 1280 px.
  5. // node tests/touch.mjs env: JUKEBOX_TOUCH_PORT (server, default 8750), HL_PORT_BASE (Chrome debug ports base+200.., default 8540 -> 8740-8749),
  6. // JUKEBOX_TOUCH_DIR (scratch + test storage, kept between runs so the database is made once), JUKEBOX_TOUCH_SHOTS (screenshots dir)
  7. import { spawn, execFileSync } from 'node:child_process'
  8. import { mkdirSync, writeFileSync, existsSync } from 'node:fs'
  9. import { dirname, join } from 'node:path'
  10. import { fileURLToPath } from 'node:url'
  11. process.env.HL_CHROME = process.env.HL_CHROME || '/opt/google/chrome/chrome'
  12. process.env.HL_PORT_BASE = process.env.HL_PORT_BASE || '8540'
  13. const { launchBrowser } = await import('./cdp.mjs')
  14. const root = join(dirname(fileURLToPath(import.meta.url)), '..')
  15. const dir = process.env.JUKEBOX_TOUCH_DIR || '/media/STORAGE/claude-scratch/atlas/JB12/gate-touch'
  16. const shots = process.env.JUKEBOX_TOUCH_SHOTS || join(dir, 'shots')
  17. const port = Number(process.env.JUKEBOX_TOUCH_PORT || 8750)
  18. const BASE = `http://127.0.0.1:${port}`
  19. let pass = 0, fail = 0
  20. const check = (name, ok, detail = '') => { console.log((ok ? 'ok ' : 'FAIL ') + name + (ok ? '' : ' — ' + detail)); if (ok) pass++; else fail++ }
  21. const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
  22. mkdirSync(shots, { recursive: true })
  23. let server = null, browser = null, log = ''
  24. async function stop() {
  25. if (browser) { try { await browser.close() } catch {} browser = null }
  26. if (server) { try { server.kill('SIGTERM') } catch {} await sleep(500); server = null }
  27. }
  28. process.on('SIGINT', async () => { await stop(); process.exit(1) })
  29. const storage = join(dir, 'storage')
  30. const tone = join(dir, 'tone.mp3')
  31. mkdirSync(dir, { recursive: true })
  32. if (!existsSync(join(storage, 'mpackdb'))) {
  33. execFileSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=60', '-q:a', '9', tone])
  34. const made = execFileSync(join(root, 'bin/hybriel'), [join(root, 'tools/make-test-db.hl'), tone, join(root, 'tests/fixtures/withcover/folder.jpg')], { env: { ...process.env, JUKEBOX_STORAGE: storage }, encoding: 'utf8', timeout: 600000 })
  35. console.log(made.trim())
  36. }
  37. 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'] })
  38. server.stdout.on('data', (d) => { log += d }); server.stderr.on('data', (d) => { log += d })
  39. for (const t0 = Date.now(); ; ) {
  40. try { if ((await fetch(BASE + '/')).ok) break } catch {}
  41. if (Date.now() - t0 > 150000) { console.log(log); await stop(); throw new Error('the server did not come up') }
  42. await sleep(500)
  43. }
  44. try {
  45. browser = await launchBrowser()
  46. const page = await browser.newPage()
  47. const ev = (e) => page.evaluate(e)
  48. const shot = async (name) => { const s = await page.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(shots, name + '.png'), Buffer.from(s.data, 'base64')) }
  49. const touch = (type, x, y) => page.send('Input.dispatchTouchEvent', { type, touchPoints: type === 'touchEnd' ? [] : [{ x, y, id: 1 }] })
  50. const view = async (w, h, coarse) => {
  51. await page.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: coarse })
  52. await page.send('Emulation.setTouchEmulationEnabled', { enabled: coarse, maxTouchPoints: coarse ? 5 : 1 })
  53. await page.goto(BASE + '/'); await page.waitForSelector('jb-screen'); await page.waitForSelector('virtual-list .vl-row:not(.blank)'); await sleep(900)
  54. }
  55. const handleBox = () => ev(`(() => { const h = document.querySelector('virtual-list vl-handle'); if (!h) return null; const r = h.getBoundingClientRect(), s = getComputedStyle(h); const sc = document.querySelector('.vl-scroller').getBoundingClientRect(); return { x: r.left, y: r.top, w: r.width, h: r.height, shown: s.display !== 'none' && s.visibility !== 'hidden' && r.width > 0, bl: s.borderLeftWidth, blc: s.borderLeftColor, br: s.borderRightWidth, clip: s.backgroundClip, bg: s.backgroundColor, sTop: sc.top, sBottom: sc.bottom, sRight: sc.right } })()`)
  56. const where = () => ev(`(() => { const s = document.querySelector('.vl-scroller'); const rows = [...document.querySelectorAll('virtual-list .vl-row:not(.blank)')]; return { top: s.scrollTop, max: s.scrollHeight - s.clientHeight, firstIdx: Number(rows[0].getAttribute('data-index')), lastIdx: Number(rows[rows.length - 1].getAttribute('data-index')), blank: document.querySelectorAll('.vl-row.blank').length } })()`)
  57. const dragFromTo = async (x, y0, y1, steps = 12) => { await touch('touchStart', x, y0); for (let i = 1; i <= steps; i++) { await touch('touchMove', x, y0 + (y1 - y0) * i / steps); await sleep(30) } ; await touch('touchEnd') }
  58. // ---- 800 x 1280 tablet, touch ---------------------------------------------------------------------------------------------
  59. await view(800, 1280, true)
  60. check('touch emulation: the page sees pointer: coarse', await ev(`matchMedia('(pointer: coarse)').matches`))
  61. const total = (await (await fetch(BASE + '/api/stats')).json()).library.songs
  62. console.log('songs in the test database: ' + total)
  63. let hb = await handleBox()
  64. check('tablet: the list has a scroll handle', !!hb && hb.shown, JSON.stringify(hb))
  65. check('tablet: the handle is at least 44 px wide', hb && hb.w >= 44, JSON.stringify(hb))
  66. check('tablet: the handle is tall enough to hit (≥ 44 px) and starts at the top', hb && hb.h >= 44 && Math.abs(hb.y - hb.sTop) <= 1, JSON.stringify(hb))
  67. check('tablet: the handle sits at the right edge of the list', hb && Math.abs(hb.x + hb.w - hb.sRight) <= 1, JSON.stringify(hb))
  68. const drawn = hb ? hb.w - parseFloat(hb.bl) - parseFloat(hb.br) : 0
  69. check('tablet: design — the tap area is wide but what is drawn stays slim (transparent border, colour clipped to the padding box, 6–16 px drawn)', hb && hb.blc === 'rgba(0, 0, 0, 0)' && hb.clip === 'padding-box' && drawn >= 6 && drawn <= 16, JSON.stringify(hb))
  70. check('tablet: design — the handle has a visible colour', hb && hb.bg !== 'rgba(0, 0, 0, 0)', hb && hb.bg)
  71. const hit = await ev(`(() => { const r = document.querySelector('virtual-list vl-handle').getBoundingClientRect(); const e = document.elementFromPoint(r.left + 5, r.top + r.height / 2); return e && e.tagName.toLowerCase() })()`)
  72. check('tablet: a touch on the handle area reaches the handle, not a row', hit === 'vl-handle', '' + hit)
  73. const rowHit = await ev(`(() => { const r = document.querySelector('.vl-row:not(.blank)').getBoundingClientRect(); const e = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); return e && !!e.closest('.vl-row') })()`)
  74. check('tablet: the rest of the row is still a row (tap target)', rowHit === true)
  75. const geo = await ev(`(() => { const rows = [...document.querySelectorAll('virtual-list .vl-row')].map((r) => r.getBoundingClientRect()); const aside = document.querySelector('.vl-row .vl-aside').getBoundingClientRect(); const hb = document.querySelector('vl-handle').getBoundingClientRect(); return { steps: rows.slice(1).map((r, i) => Math.round(r.top - rows[i].top)), h: rows[0].height, asideRight: aside.right, handleDrawnLeft: hb.left + 32 } })()`)
  76. check('tablet: rows are still 56 px apart and 56 px tall (dense list)', geo.steps.every((s) => s === 56) && geo.h === 56, JSON.stringify(geo.steps.slice(0, 5)))
  77. check('tablet: the rows\' right text stays clear of the drawn handle', geo.asideRight <= geo.handleDrawnLeft, JSON.stringify(geo))
  78. await shot('tablet-800-top')
  79. // a half drag first: the middle of the track is about the middle of the list
  80. const cx = hb.x + hb.w / 2
  81. const trackTop = hb.sTop + hb.h / 2, trackBottom = hb.sBottom - hb.h / 2
  82. await dragFromTo(cx, hb.y + hb.h / 2, (trackTop + trackBottom) / 2)
  83. await sleep(1200)
  84. let w = await where()
  85. check('tablet: a touch drag to the middle of the track lands in the middle of the list (45–55 %)', w.top / w.max > 0.45 && w.top / w.max < 0.55, JSON.stringify(w))
  86. check('tablet: rows are loaded where the drag landed (no blank rows)', w.blank === 0, JSON.stringify(w))
  87. hb = await handleBox()
  88. check('tablet: the handle shows where we are (about the middle of the box)', Math.abs((hb.y + hb.h / 2) - (trackTop + trackBottom) / 2) <= 3, JSON.stringify(hb))
  89. await shot('tablet-800-middle')
  90. // the full drag: top to bottom with touch events
  91. await dragFromTo(cx, hb.y + hb.h / 2, hb.sBottom - 2, 20)
  92. await sleep(1500)
  93. w = await where()
  94. check('tablet: a touch drag from the top of the track to the bottom lands at the end of the list', w.top >= w.max - 2, JSON.stringify(w))
  95. check('tablet: the last song (number 13,458) is in the page and loaded', w.lastIdx === 13457, JSON.stringify(w) + ' songs ' + total)
  96. check('tablet: no blank rows at the end', w.blank === 0, JSON.stringify(w))
  97. hb = await handleBox()
  98. check('tablet: the handle sits at the bottom of the box at the end', Math.abs((hb.y + hb.h) - hb.sBottom) <= 2, JSON.stringify(hb))
  99. await shot('tablet-800-end')
  100. // and back up with the grab offset: grab the handle at its lower part, move up to the top
  101. await dragFromTo(cx, hb.y + hb.h - 6, hb.sTop - 40, 20)
  102. await sleep(1200)
  103. w = await where()
  104. check('tablet: dragged back up past the top: the list is at the first row', w.top <= 1 && w.firstIdx === 0, JSON.stringify(w))
  105. // the finger scroll (a swipe on the rows) moves the handle too
  106. await ev(`document.querySelector('.vl-scroller').scrollTop = 56 * 6000`); await sleep(700)
  107. hb = await handleBox()
  108. const frac = (6000 * 56) / (await where()).max
  109. check('tablet: scrolling by other means moves the handle to the matching place', Math.abs((hb.y - hb.sTop) / (hb.sBottom - hb.sTop - hb.h) - frac) < 0.03, JSON.stringify({ hb, frac }))
  110. check('tablet: no script errors', page.problems().filter((m) => m.level === 'error').length === 0, page.dumpConsole())
  111. // ---- 390 phone, touch --------------------------------------------------------------------------------------------------------
  112. await view(390, 844, true)
  113. hb = await handleBox()
  114. check('phone 390: the handle is there and at least 44 px wide', !!hb && hb.shown && hb.w >= 44, JSON.stringify(hb))
  115. const g390 = await ev(`(() => { const rows = [...document.querySelectorAll('virtual-list .vl-row')].map((r) => r.getBoundingClientRect()); return rows.slice(1).map((r, i) => Math.round(r.top - rows[i].top)) })()`)
  116. check('phone 390: rows 56 px apart', g390.every((s) => s === 56))
  117. await dragFromTo(hb.x + hb.w / 2, hb.y + hb.h / 2, hb.sBottom - 2, 16)
  118. await sleep(1500)
  119. w = await where()
  120. check('phone 390: the touch drag lands at the end of the list', w.top >= w.max - 2 && w.lastIdx === 13457, JSON.stringify(w))
  121. await shot('phone-390-end')
  122. await ev(`document.querySelector('.vl-scroller').scrollTop = 0`); await sleep(700)
  123. await shot('phone-390-top')
  124. // ---- 1280 desktop, mouse: the look stays --------------------------------------------------------------------------------------
  125. await view(1280, 800, false)
  126. check('desktop: the page does not see a coarse pointer', await ev(`!matchMedia('(pointer: coarse)').matches`))
  127. hb = await handleBox()
  128. check('desktop: no handle is shown (the browser\'s own scroll bar stays)', !hb || !hb.shown, JSON.stringify(hb))
  129. const d = await ev(`(() => { const s = document.querySelector('.vl-scroller'); const c = getComputedStyle(s); return { pr: c.paddingRight, sw: c.scrollbarWidth, bar: s.offsetWidth - s.clientWidth } })()`)
  130. check('desktop: the list box is unchanged (no extra padding, native scroll bar kept)', d.pr === '0px' && d.sw === 'auto', JSON.stringify(d))
  131. await shot('desktop-1280')
  132. await page.close()
  133. } catch (e) {
  134. fail++; console.log('FAIL the gate stopped: ' + (e && e.stack || e)); if (log) console.log(log.slice(-2000))
  135. } finally {
  136. await stop()
  137. }
  138. console.log(`\n${pass} passed, ${fail} failed`)
  139. process.exit(fail ? 1 : 0)

Branches

Latest commits

  • 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
  • 2a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre
  • 93a44212jukebox: report, numbers of the full scan, notes on the index key rulemre
  • bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
  • 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre
  • d13987dfjukebox: library scanner, ID3 reader, mpackdb database and JSON API, with fixtures and a gatemre