gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7d58b36e7d58b36ejukebox 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 changedmre7d58b36e/tests/touch.mjs

14.2 KB

  1. // tests/touch.mjs — jukebox#12 (JB12b): THE LIST'S SCROLL HANDLE FOR A FINGER, BIG and on EVERY device (no media query decides). 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. The handle is also checked with pointer fine (a tablet in desktop mode; CDP cannot fake any-pointer) and with NO touch emulation at all (a plain desktop): visible there too, drawn >= 40 px wide, >= 4rem tall.
  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/JB12b/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, mode = '') => {
  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.send('Emulation.setEmulatedMedia', { features: mode === 'anyCoarse' ? [{ name: 'pointer', value: 'fine' }, { name: 'any-pointer', value: 'coarse' }] : [] })
  54. await page.goto(BASE + '/'); await page.waitForSelector('jb-screen'); await page.waitForSelector('virtual-list .vl-row:not(.blank)'); await sleep(900)
  55. }
  56. 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 - parseFloat(s.borderLeftWidth) - parseFloat(s.borderRightWidth), box: 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, rad: s.borderTopLeftRadius, sw: getComputedStyle(document.querySelector('.vl-scroller')).scrollbarWidth, vis: s.visibility, op: s.opacity, sTop: sc.top, sBottom: sc.bottom, sRight: sc.right } })()`)
  57. 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 } })()`)
  58. 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') }
  59. // ---- 800 x 1280 tablet, touch ---------------------------------------------------------------------------------------------
  60. await view(800, 1280, true)
  61. check('touch emulation: the page sees pointer: coarse', await ev(`matchMedia('(pointer: coarse)').matches`))
  62. const total = (await (await fetch(BASE + '/api/stats')).json()).library.songs
  63. console.log('songs in the test database: ' + total)
  64. let hb = await handleBox()
  65. check('tablet: the list has a scroll handle', !!hb && hb.shown, JSON.stringify(hb))
  66. check('tablet: DRAWN width of the visible handle is at least 40 px (and 44 px box)', hb && hb.w >= 40 && hb.box >= 44, JSON.stringify(hb))
  67. check('tablet: the handle is at least 4rem (64 px) tall', hb && hb.h >= 64, JSON.stringify(hb))
  68. check('tablet: the handle box is at least 44 px wide', hb && hb.box >= 44, JSON.stringify(hb))
  69. 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))
  70. check('tablet: the handle sits at the right edge of the list', hb && Math.abs(hb.x + hb.box - hb.sRight) <= 1, JSON.stringify(hb))
  71. check('tablet: design — fully drawn (no transparent border strip), rounded, solid accent colour', hb && parseFloat(hb.bl) === 0 && parseFloat(hb.br) === 0 && hb.bg !== 'rgba(0, 0, 0, 0)' && parseFloat(hb.rad) >= 12, JSON.stringify(hb))
  72. check('tablet: the native scroll bar is hidden (one handle only)', hb && hb.sw === 'none', JSON.stringify(hb))
  73. 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() })()`)
  74. check('tablet: a touch on the handle area reaches the handle, not a row', hit === 'vl-handle', '' + hit)
  75. 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') })()`)
  76. check('tablet: the rest of the row is still a row (tap target)', rowHit === true)
  77. 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 } })()`)
  78. 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)))
  79. check('tablet: the rows\' right text stays clear of the drawn handle', geo.asideRight <= geo.handleDrawnLeft, JSON.stringify(geo))
  80. await shot('tablet-800-top')
  81. // a half drag first: the middle of the track is about the middle of the list
  82. const cx = hb.x + hb.box / 2
  83. const trackTop = hb.sTop + hb.h / 2, trackBottom = hb.sBottom - hb.h / 2
  84. await dragFromTo(cx, hb.y + hb.h / 2, (trackTop + trackBottom) / 2)
  85. await sleep(1200)
  86. let w = await where()
  87. 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))
  88. check('tablet: rows are loaded where the drag landed (no blank rows)', w.blank === 0, JSON.stringify(w))
  89. hb = await handleBox()
  90. 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))
  91. await shot('tablet-800-middle')
  92. // the full drag: top to bottom with touch events
  93. await dragFromTo(cx, hb.y + hb.h / 2, hb.sBottom - 2, 20)
  94. await sleep(1500)
  95. w = await where()
  96. 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))
  97. check('tablet: the last song (number 13,458) is in the page and loaded', w.lastIdx === 13457, JSON.stringify(w) + ' songs ' + total)
  98. check('tablet: no blank rows at the end', w.blank === 0, JSON.stringify(w))
  99. hb = await handleBox()
  100. 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))
  101. await shot('tablet-800-end')
  102. // and back up with the grab offset: grab the handle at its lower part, move up to the top
  103. await dragFromTo(cx, hb.y + hb.h - 6, hb.sTop - 40, 20)
  104. await sleep(1200)
  105. w = await where()
  106. check('tablet: dragged back up past the top: the list is at the first row', w.top <= 1 && w.firstIdx === 0, JSON.stringify(w))
  107. // the finger scroll (a swipe on the rows) moves the handle too
  108. await ev(`document.querySelector('.vl-scroller').scrollTop = 56 * 6000`); await sleep(700)
  109. hb = await handleBox()
  110. const frac = (6000 * 56) / (await where()).max
  111. 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 }))
  112. check('tablet: no script errors', page.problems().filter((m) => m.level === 'error').length === 0, page.dumpConsole())
  113. // ---- 390 phone, touch --------------------------------------------------------------------------------------------------------
  114. await view(390, 844, true)
  115. hb = await handleBox()
  116. check('phone 390: the handle is there, DRAWN at least 40 px wide', !!hb && hb.shown && hb.w >= 40, JSON.stringify(hb))
  117. 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)) })()`)
  118. check('phone 390: rows 56 px apart', g390.every((s) => s === 56))
  119. await dragFromTo(hb.x + hb.box / 2, hb.y + hb.h / 2, hb.sBottom - 2, 16)
  120. await sleep(1500)
  121. w = await where()
  122. check('phone 390: the touch drag lands at the end of the list', w.top >= w.max - 2 && w.lastIdx === 13457, JSON.stringify(w))
  123. await shot('phone-390-end')
  124. await ev(`document.querySelector('.vl-scroller').scrollTop = 0`); await sleep(700)
  125. await shot('phone-390-top')
  126. // ---- a tablet in desktop mode reports pointer: fine; headless Chrome cannot fake any-pointer: coarse over CDP, so the handle must not depend on any pointer query: the plain cases below prove it ----
  127. check('no media query decides: the handle rule is not inside any @media in the stylesheet', await ev(`[...document.styleSheets].every((ss) => { try { return [...ss.cssRules].every((r) => !(r.media && r.cssText.includes('vl-handle') )) } catch { return true } })`))
  128. // ---- 800 and 1280 with NO touch emulation at all: the handle is there too -------------------------------------------------------
  129. await view(800, 1280, false)
  130. check('no touch: the page sees no coarse pointer at all (like a tablet in desktop mode or with a stylus would)', await ev(`!matchMedia('(pointer: coarse)').matches && !matchMedia('(any-pointer: coarse)').matches`))
  131. hb = await handleBox()
  132. check('no touch 800: the handle is visible without any touch emulation, DRAWN at least 40 px wide, 64 px tall', !!hb && hb.shown && hb.w >= 40 && hb.h >= 64, JSON.stringify(hb))
  133. await shot('plain-800')
  134. await view(1280, 800, false)
  135. hb = await handleBox()
  136. check('desktop 1280: the handle is visible, DRAWN at least 40 px wide, 64 px tall, at the right edge', !!hb && hb.shown && hb.w >= 40 && hb.h >= 64 && Math.abs(hb.x + hb.box - hb.sRight) <= 1, JSON.stringify(hb))
  137. 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 } })()`)
  138. check('desktop 1280: rows keep clear of the handle (padding right 48 px, native bar hidden)', d.pr === '48px' && d.sw === 'none' && d.bar === 0, JSON.stringify(d))
  139. const hit2 = await ev(`(() => { const r = document.querySelector('virtual-list vl-handle').getBoundingClientRect(); const e = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); return e && e.tagName.toLowerCase() })()`)
  140. check('desktop 1280: a click on the handle reaches the handle', hit2 === 'vl-handle', '' + hit2)
  141. await shot('desktop-1280')
  142. await page.close()
  143. } catch (e) {
  144. fail++; console.log('FAIL the gate stopped: ' + (e && e.stack || e)); if (log) console.log(log.slice(-2000))
  145. } finally {
  146. await stop()
  147. }
  148. console.log(`\n${pass} passed, ${fail} failed`)
  149. process.exit(fail ? 1 : 0)

Branches

Latest commits

  • 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
  • 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