gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7663965576639655Records: B1 questionmre76639655/tests/ui.mjs

24.6 KB

  1. // tests/ui.mjs — the jukebox's SCREEN GATE: its own server on a generated database of 13,450 songs (tools/make-test-db.hl, not the real library) and a real headless
  2. // Chrome (tests/cdp.mjs): real clicks, wheel scrolling and keys. Phone first (390 px), then 1280. Every song of the test database points at one 60 s tone (ffmpeg).
  3. // node tests/ui.mjs env: JUKEBOX_UI_PORT (server, default 8710), JUKEBOX_UI_CHROME (Chrome debug ports, HL_PORT_BASE+200..: default base 8500 → 8700-8709),
  4. // JUKEBOX_UI_DIR (scratch, default /media/STORAGE/claude-scratch/atlas/JB2/gate-ui), JUKEBOX_UI_SHOTS (screenshots dir), JUKEBOX_UI_URL (use a server that already runs: skips the start and the database)
  5. import { spawn, execFileSync } from 'node:child_process'
  6. import { rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs'
  7. import { dirname, join } from 'node:path'
  8. import { fileURLToPath } from 'node:url'
  9. process.env.HL_CHROME = process.env.HL_CHROME || '/opt/google/chrome/chrome'
  10. process.env.HL_PORT_BASE = process.env.HL_PORT_BASE || '8500'
  11. const { launchBrowser } = await import('./cdp.mjs')
  12. const root = join(dirname(fileURLToPath(import.meta.url)), '..')
  13. const dir = process.env.JUKEBOX_UI_DIR || '/media/STORAGE/claude-scratch/atlas/JB2/gate-ui'
  14. const shots = process.env.JUKEBOX_UI_SHOTS || join(dir, 'shots')
  15. const port = Number(process.env.JUKEBOX_UI_PORT || 8710)
  16. const BASE = process.env.JUKEBOX_UI_URL || `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. const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
  21. mkdirSync(shots, { recursive: true })
  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. // ---- the test database and the server --------------------------------------------------------------------------------------
  29. const storage = join(dir, 'storage')
  30. const tone = join(dir, 'tone.mp3')
  31. if (!process.env.JUKEBOX_UI_URL) {
  32. rmSync(storage, { recursive: true, force: true })
  33. mkdirSync(dir, { recursive: true })
  34. execFileSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=60', '-q:a', '9', tone])
  35. const cover = join(root, 'tests/fixtures/withcover/folder.jpg')
  36. const t0 = Date.now()
  37. const made = execFileSync(join(root, 'bin/hybriel'), [join(root, 'tools/make-test-db.hl'), tone, cover], { env: { ...process.env, JUKEBOX_STORAGE: storage }, encoding: 'utf8', timeout: 600000 })
  38. console.log(made.trim() + ' (' + (Date.now() - t0) + ' ms)')
  39. 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'] })
  40. server.stdout.on('data', (d) => { log += d }); server.stderr.on('data', (d) => { log += d })
  41. for (const t0 = Date.now(); ; ) {
  42. try { if ((await fetch(BASE + '/')).ok) break } catch {}
  43. if (Date.now() - t0 > COLD_MS) { console.log(log); throw new Error('the server did not come up') }
  44. await sleep(500)
  45. }
  46. }
  47. try {
  48. // ---- the JSON API and the audio route -------------------------------------------------------------------------------------
  49. const j = async (p) => (await fetch(BASE + p)).json()
  50. const stats = (await j('/api/stats')).library
  51. check('the test database has 13,459 files', stats.songs === 13459, JSON.stringify(stats))
  52. const byPlays = await j('/api/songs?sort=plays&limit=3')
  53. check('sort=plays: the most played first', byPlays.items.length === 3 && byPlays.items[0].playCount >= byPlays.items[1].playCount && byPlays.items[0].playCount === 12, JSON.stringify(byPlays.items.map((s) => s.playCount)))
  54. const some = (await j('/api/songs?sort=title&limit=1')).items[0]
  55. const full = readFileSync(tone)
  56. const get = (id, headers = {}, method = 'GET') => fetch(BASE + '/stream/' + id, { headers, method })
  57. let r = await get(some.id, { Range: 'bytes=0-99' })
  58. const b0 = Buffer.from(await r.arrayBuffer())
  59. check('stream: Range bytes=0-99 answers 206 with 100 bytes', r.status === 206 && b0.length === 100 && r.headers.get('content-range') === `bytes 0-99/${full.length}`, r.status + ' ' + r.headers.get('content-range'))
  60. check('stream: the bytes are the file\'s bytes', b0.equals(full.subarray(0, 100)))
  61. check('stream: content type audio/mpeg, Accept-Ranges bytes', r.headers.get('content-type') === 'audio/mpeg' && r.headers.get('accept-ranges') === 'bytes', r.headers.get('content-type'))
  62. r = await get(some.id, { Range: 'bytes=1000-1999' }); const b1 = Buffer.from(await r.arrayBuffer())
  63. check('stream: a range in the middle is the right slice', r.status === 206 && b1.equals(full.subarray(1000, 2000)))
  64. r = await get(some.id, { Range: 'bytes=-50' }); const b2 = Buffer.from(await r.arrayBuffer())
  65. check('stream: a suffix range gives the last 50 bytes', r.status === 206 && b2.equals(full.subarray(full.length - 50)))
  66. r = await get(some.id, { Range: `bytes=${full.length - 10}-` }); const b3 = Buffer.from(await r.arrayBuffer())
  67. check('stream: an open range runs to the end', r.status === 206 && b3.equals(full.subarray(full.length - 10)))
  68. r = await get(some.id, { Range: `bytes=${full.length + 5}-` })
  69. check('stream: a range past the end answers 416', r.status === 416, '' + r.status)
  70. r = await get(some.id, { Range: 'bytes=0-1,5-9' })
  71. check('stream: a list of ranges is not an error (answers 206 with the start)', r.status === 206)
  72. r = await get(some.id)
  73. check('stream: no Range header: the first chunk, 206', r.status === 206 && Buffer.from(await r.arrayBuffer()).length === Math.min(full.length, 1048576))
  74. r = await get('nosuchsong1'); check('stream: an unknown id is 404', r.status === 404, '' + r.status)
  75. r = await get('..%2F..%2Fetc%2Fpasswd'); check('stream: a path in the URL is 404, never read', r.status === 404, '' + r.status)
  76. r = await fetch(BASE + '/stream/' + some.id, { method: 'POST' }); check('stream: POST is refused', r.status === 405)
  77. r = await fetch(BASE + '/api/thumb/' + some.id); check('a thumbnail of an unknown cover is 404', r.status === 404)
  78. const withCover = (await j('/api/albums?limit=200')).items.find((a) => a.coverId)
  79. r = await fetch(BASE + '/api/thumb/' + withCover.coverId); const th = Buffer.from(await r.arrayBuffer())
  80. check('the thumbnail is a small jpeg', r.status === 200 && r.headers.get('content-type') === 'image/jpeg' && th.length < 20000 && th[0] === 0xff, r.status + ' ' + th.length)
  81. // ---- the screens, phone first --------------------------------------------------------------------------------------------
  82. browser = await launchBrowser()
  83. const page = await browser.newPage()
  84. const ev = (e) => page.evaluate(e)
  85. const shot = async (name) => { const s = await page.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(shots, name + '.png'), Buffer.from(s.data, 'base64')) }
  86. const press = async (key, code, vk) => { await page.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key, code, windowsVirtualKeyCode: vk }); await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key, code, windowsVirtualKeyCode: vk }) }
  87. const wheel = async (dy, x = 200, y = 400) => { await page.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x, y, deltaX: 0, deltaY: dy }) }
  88. const rowsInDom = () => ev(`document.querySelectorAll('virtual-list .vl-row').length`)
  89. const firstTitle = () => ev(`(document.querySelector('virtual-list .vl-row:not(.blank) .vl-title')||{}).textContent`)
  90. const goto = async (path) => { await page.goto(BASE + path); await page.waitForSelector('jb-screen') }
  91. const clientNav = async (href) => { await page.click('.menu-toggle'); await page.waitFor(`document.querySelector('app-sidebar:popover-open')`); await page.click(`app-sidebar a[href="${href}"]`); await page.waitFor(`location.pathname === ${JSON.stringify(href)}`) }
  92. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true })
  93. let t0 = Date.now()
  94. await goto('/')
  95. await page.waitForSelector('virtual-list .vl-row')
  96. console.log('first paint of Songs at 390: ' + (Date.now() - t0) + ' ms')
  97. await sleep(800)
  98. check('Songs: the count says 13,458 songs (a song in two folders is shown once)', (await ev(`document.querySelector('#count').textContent`)) === '13,458 songs')
  99. const n0 = await rowsInDom()
  100. check('Songs: only the rows near the viewport are in the page (< 100)', n0 > 5 && n0 < 100, '' + n0)
  101. const geo = await ev(`(() => { const rows = [...document.querySelectorAll('virtual-list .vl-row')].map((r) => r.getBoundingClientRect()); const r0 = document.querySelector('.vl-row'); const th = r0.querySelector('.vl-thumb').getBoundingClientRect(), tx = r0.querySelector('.vl-text').getBoundingClientRect(); return { steps: rows.slice(1).map((r, i) => Math.round(r.top - rows[i].top)), thumbMid: th.top + th.height / 2, textMid: tx.top + tx.height / 2, rowMid: rows[0].top + rows[0].height / 2, h: rows[0].height, titleSub: (() => { const t = r0.querySelector('.vl-title').getBoundingClientRect(), s = r0.querySelector('.vl-sub').getBoundingClientRect(); return Math.round(s.top - t.bottom) })() } })()`)
  102. check('Songs: the rows are 56 px apart, no looser (dense list)', geo.steps.every((s) => s === 56) && geo.h === 56, JSON.stringify(geo.steps.slice(0, 5)))
  103. check('Songs: thumbnail, text and row share one centre line (±1 px)', Math.abs(geo.thumbMid - geo.rowMid) <= 1 && Math.abs(geo.textMid - geo.rowMid) <= 1, JSON.stringify(geo))
  104. check('Songs: the title and its second line touch (gap ≤ 2 px)', geo.titleSub <= 2, '' + geo.titleSub)
  105. await shot('songs-390')
  106. // scroll to the end with the real wheel
  107. t0 = Date.now()
  108. for (let i = 0; i < 40; i++) { await wheel(60000); await sleep(60) }
  109. await page.waitFor(`(() => { const s = document.querySelector('.vl-scroller'); return s.scrollTop + s.clientHeight >= s.scrollHeight - 2 })()`, { timeout: 20000 })
  110. await sleep(1200)
  111. const end = await ev(`(() => { const rows = [...document.querySelectorAll('virtual-list .vl-row')]; return { n: rows.length, blank: rows.filter((r) => r.classList.contains('blank')).length, last: rows[rows.length - 1].getAttribute('data-index'), text: rows[rows.length - 1].textContent } })()`)
  112. console.log('scrolled to the end in ' + (Date.now() - t0) + ' ms')
  113. check('Songs: scrolled to the end of 13,450 rows the page still holds < 100 rows', end.n < 100, JSON.stringify(end))
  114. check('Songs: the last row is number 13,458 and its text arrived (no blank rows)', end.last === '13457' && end.blank === 0 && end.text.length > 5, JSON.stringify(end))
  115. // sort with the keyboard on the select
  116. await goto('/')
  117. await page.waitForSelector('virtual-list .vl-row')
  118. const apiFirst = async (q) => (await j('/api/songs?limit=1&' + q)).items[0].title
  119. await page.focus('#sort'); await press('ArrowDown', 'ArrowDown', 40)
  120. await page.waitFor(`document.querySelector('#sort').value === 'title'`)
  121. await page.waitFor(`document.querySelector('virtual-list .vl-row .vl-title').textContent !== ''`)
  122. await sleep(500)
  123. check('Sort by title: the first row is the API\'s first title', (await firstTitle()) === (await apiFirst('sort=title')), (await firstTitle()) + ' / ' + (await apiFirst('sort=title')))
  124. await press('ArrowDown', 'ArrowDown', 40); await sleep(900)
  125. check('Sort by album: the first row is the API\'s first album song', (await firstTitle()) === (await apiFirst('sort=album')), await firstTitle())
  126. await press('ArrowDown', 'ArrowDown', 40); await sleep(900)
  127. const playsRow = await ev(`document.querySelector('virtual-list .vl-row .vl-aside').textContent`)
  128. check('Sort by most played: the first row shows 12×', playsRow === '12×', playsRow)
  129. // favourites
  130. await goto('/')
  131. await page.waitForSelector('virtual-list .vl-row')
  132. const fav5 = (await j('/api/songs?minPlays=5&limit=1')).total
  133. check('the API knows the favourites count', fav5 === stats.playedAtLeast5, fav5 + ' / ' + stats.playedAtLeast5)
  134. await page.click('#fav')
  135. await page.waitFor(`document.querySelector('#count').textContent === ${JSON.stringify(fav5.toLocaleString('en-US') + ' songs')}`, { timeout: 10000, label: 'favourites count' })
  136. check('Favourites: the count line shows the songs played at least 5 times', true)
  137. const line = await ev(`(() => { const mid = (e) => { const r = e.getBoundingClientRect(); return r.top + r.height / 2 }; const c = document.querySelector('jb-count'); return [mid(c.querySelector('output')), mid(c.querySelector('input')), mid(c.querySelectorAll('span')[1]), c.getBoundingClientRect().height] })()`)
  138. check('Favourites: the count, the minimum field and the words stand on one line (centres within 6 px)', Math.max(...line.slice(0, 3)) - Math.min(...line.slice(0, 3)) <= 6, JSON.stringify(line))
  139. check('Favourites: the minimum is 5 by default', (await ev(`document.querySelector('#favmin').value`)) === '5')
  140. await shot('favourites-390')
  141. const fav9 = (await j('/api/songs?minPlays=9&limit=1')).total
  142. await page.focus('#favmin'); await ev(`document.querySelector('#favmin').select()`)
  143. await page.send('Input.insertText', { text: '9' })
  144. await page.waitFor(`document.querySelector('#count').textContent === ${JSON.stringify(fav9.toLocaleString('en-US') + ' songs')}`, { timeout: 10000, label: 'favourites 9' })
  145. check('Favourites: N adjustable, 9 changes the count', fav9 < fav5)
  146. const minPlaysSeen = await ev(`(async () => { const s = document.querySelector('.vl-scroller'); s.scrollTop = 56 * 40; await new Promise((r) => setTimeout(r, 900)); return [...document.querySelectorAll('.vl-row:not(.blank)')].length })()`)
  147. check('Favourites: rows are loaded after a scroll in the filtered list', minPlaysSeen > 5, '' + minPlaysSeen)
  148. // search through the phone's menu
  149. await goto('/')
  150. await page.waitForSelector('virtual-list .vl-row')
  151. await clientNav('/search')
  152. await page.waitForSelector('#q')
  153. check('Search: the header toggle opened the menu and the page changed without a reload', true)
  154. t0 = Date.now()
  155. await page.type('#q', 'zebra fixture')
  156. await page.waitFor(`(() => { const h = [...document.querySelectorAll('jb-hits h2')].find((x) => x.textContent.startsWith('Songs')); return !!h && h.textContent === 'Songs · 1' })()`, { timeout: 15000, label: 'search result' })
  157. console.log('search response (last key to the result): ' + (Date.now() - t0) + ' ms in all')
  158. const found = await ev(`[...document.querySelectorAll('virtual-list .vl-row:not(.blank) .vl-title')].map((e) => e.textContent)`)
  159. check('Search: the known song is found while typing', found.includes('Zebra Fixture Anthem'), JSON.stringify(found))
  160. await page.type('#q', ' nonexistentword')
  161. await page.waitFor(`document.querySelector('#count').textContent === 'Nothing found.'`, { timeout: 15000, label: 'every word must match' })
  162. check('Search: every word must match (a word that is not there finds nothing)', true)
  163. await ev(`(() => { const q = document.querySelector('#q'); q.value = ''; q.dispatchEvent(new Event('input', { bubbles: true })) })()`)
  164. await page.type('#q', 'quentin fixture')
  165. await page.waitFor(`(() => { const h = [...document.querySelectorAll('jb-hits h2')].find((x) => x.textContent.startsWith('Songs')); return !!h && h.textContent === 'Songs · 1' })()`, { timeout: 15000 })
  166. const hits = await ev(`[...document.querySelectorAll('jb-hits button .jb-name')].map((e) => e.textContent)`)
  167. check('Search: the artist and the album are found too', hits.includes('Quentin Fixture') && hits.includes('Known Album'), JSON.stringify(hits))
  168. await shot('search-390')
  169. await ev(`(() => { const q = document.querySelector('#q'); q.value = ''; q.dispatchEvent(new Event('input', { bubbles: true })) })()`)
  170. await page.type('#q', 'xyzzy')
  171. await page.waitFor(`document.querySelector('#count').textContent === 'Nothing found.'`, { timeout: 15000 })
  172. check('Search: no match shows 0 songs', true)
  173. await ev(`(() => { const q = document.querySelector('#q'); q.value = ''; q.dispatchEvent(new Event('input', { bubbles: true })) })()`)
  174. await page.type('#q', 'zebra fixture')
  175. await page.waitFor(`(() => { const h = [...document.querySelectorAll('jb-hits h2')].find((x) => x.textContent.startsWith('Songs')); return !!h && h.textContent === 'Songs · 1' })()`, { timeout: 15000 })
  176. // play the found song: a tap on its row
  177. await page.click('virtual-list .vl-row:not(.blank)')
  178. await page.waitFor(`(() => { const a = document.querySelector('media-player audio'); return a && a.currentTime > 0.6 && !a.paused })()`, { timeout: 20000, label: 'currentTime advances' })
  179. const audio1 = await ev(`(() => { const a = document.querySelector('media-player audio'); return { src: a.src, t: a.currentTime, paused: a.paused } })()`)
  180. check('Play: the song plays (currentTime advances)', audio1.t > 0.6 && !audio1.paused && audio1.src.includes('/stream/'), JSON.stringify(audio1))
  181. const bar = await ev(`(() => { const b = document.querySelector('.jb-bar').getBoundingClientRect(); return { h: Math.round(b.height), bottom: Math.round(b.bottom), vh: innerHeight, w: Math.round(b.width) } })()`)
  182. check('Play: the player bar sits at the bottom of the phone screen and the progress bar is half a finger', bar.h <= 84 && bar.h >= 68 && bar.bottom === bar.vh, JSON.stringify(bar))
  183. const barGeo = await ev(`(() => { const r = (s) => document.querySelector(s).getBoundingClientRect(); const bar = r('.jb-bar'); const seek = r('.jb-bar mp-seek'); const track = r('.jb-bar mp-seek .mp-track'); const t = r('.jb-bar .mp-cover h2'); return { seekAbove: seek.bottom <= r('.jb-bar .mp-play').top + 2, seekTop: Math.round(seek.top - bar.top), seekH: Math.round(seek.height), trackH: Math.round(track.height), title: document.querySelector('.jb-bar .mp-cover h2').textContent, titleInside: t.top >= bar.top && t.bottom <= bar.bottom && t.width > 40, buttons: [...document.querySelectorAll('.jb-bar mp-buttons button')].filter((b) => b.getBoundingClientRect().width > 0).length } })()`)
  184. check('Play: the progress bar is on top, 22 px tall, the title is inside the bar, play / pause in the media player, previous and next beside it', barGeo.seekAbove && barGeo.seekTop <= 2 && barGeo.seekH >= 20 && barGeo.seekH <= 26 && barGeo.trackH >= 20 && barGeo.trackH <= 26 && barGeo.title === 'Zebra Fixture Anthem' && barGeo.titleInside && barGeo.buttons === 1, JSON.stringify(barGeo))
  185. await shot('player-390')
  186. // the song goes on while the screen changes
  187. await clientNav('/artists')
  188. await page.waitForSelector('virtual-list .vl-row:not(.blank)')
  189. await sleep(1500)
  190. const audio2 = await ev(`(() => { const a = document.querySelector('media-player audio'); return { src: a.src, t: a.currentTime, paused: a.paused } })()`)
  191. check('Play: it keeps playing when the screen changes to Artists', audio2.src === audio1.src && audio2.t > audio1.t && !audio2.paused, JSON.stringify([audio1, audio2]))
  192. const lastRow = await ev(`(() => { const r = document.querySelector('virtual-list .vl-row:not(.blank)').getBoundingClientRect(); const b = document.querySelector('.jb-bar').getBoundingClientRect(); const s = document.querySelector('.vl-scroller').getBoundingClientRect(); return { scrollerBottom: Math.round(s.bottom), barTop: Math.round(b.top) } })()`)
  193. check('Play: the list ends where the bar starts (nothing hidden under it)', lastRow.scrollerBottom <= lastRow.barTop + 1, JSON.stringify(lastRow))
  194. // artist -> albums and songs; album -> songs in track order, large cover
  195. await page.click('virtual-list .vl-row:not(.blank)')
  196. await page.waitFor(`location.pathname.startsWith('/artists/')`)
  197. await page.waitForSelector('#name')
  198. const artistName = await ev(`document.querySelector('#name').textContent`)
  199. check('Artist: a tap opens the artist (name on top)', artistName.length > 2, artistName)
  200. check('Artist: albums and songs tabs', (await ev(`document.querySelectorAll('jb-tabs button[data-tab]').length`)) === 2)
  201. await page.click('jb-tabs button[data-tab="songs"]')
  202. await page.waitFor(`document.querySelector('jb-tabs button[data-tab="songs"]').classList.contains('on')`)
  203. await sleep(700)
  204. check('Artist: the songs tab lists their songs', (await ev(`document.querySelectorAll('.vl-row:not(.blank)').length`)) > 0)
  205. await page.click('jb-tabs button[data-tab="albums"]')
  206. await page.waitFor(`document.querySelector('jb-tabs button[data-tab="albums"]').classList.contains('on') && !document.querySelector('.vl-row:not(.blank) .vl-aside').textContent.includes(':')`, { timeout: 15000, label: 'albums tab' })
  207. await sleep(500)
  208. await page.click('virtual-list .vl-row:not(.blank)')
  209. try { await page.waitFor(`location.pathname.startsWith('/albums/')`, { timeout: 5000 }) } catch (e) {
  210. console.log('DIAG after the tap on an album row: ' + await ev(`location.pathname + ' | ' + document.querySelector('jb-tabs button.on').textContent + ' | ' + [...document.querySelectorAll('.vl-row:not(.blank)')].slice(0, 2).map((r) => r.outerHTML.slice(0, 200)).join(' || ')`))
  211. throw e
  212. }
  213. await page.waitForSelector('jb-head img#cover, jb-head .jb-nocover')
  214. await sleep(900)
  215. const alb = await ev(`(() => { const c = document.querySelector('jb-head img#cover') || document.querySelector('jb-head .jb-nocover'); const r = c.getBoundingClientRect(); const titles = [...document.querySelectorAll('.vl-row:not(.blank) .vl-title')].map((e) => e.textContent); return { cover: Math.round(r.width), top: Math.round(r.top), titles, vw: innerWidth } })()`)
  216. check('Album: the cover is large on top (≥ 250 px wide at 390)', alb.cover >= 250, JSON.stringify(alb))
  217. const nums = alb.titles.map((t) => parseInt(t, 10))
  218. check('Album: the songs are in track order', nums.length > 3 && nums.every((n, i) => i === 0 || n > nums[i - 1]), JSON.stringify(alb.titles))
  219. await shot('album-390')
  220. await page.click('virtual-list .vl-row:not(.blank)')
  221. await page.waitFor(`document.querySelector('media-player audio').src.includes('/stream/') && document.querySelector('media-player audio').currentTime < 3`, { timeout: 20000 })
  222. await sleep(1500)
  223. check('Album: a tap plays that song', await ev(`!document.querySelector('media-player audio').paused && document.querySelector('media-player audio').currentTime > 0.5`))
  224. check('The page has no script errors', page.problems().filter((m) => m.level === 'error').length === 0, page.dumpConsole())
  225. // ---- desktop ---------------------------------------------------------------------------------------------------------------
  226. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false })
  227. await goto('/')
  228. await page.waitForSelector('virtual-list .vl-row:not(.blank)')
  229. await sleep(800)
  230. check('Desktop: the menu stands in the header (Songs, Artists, Albums, Search)', (await ev(`[...document.querySelectorAll('application-header main-menu a')].map((a) => a.textContent).join(',')`)) === 'Songs,Artists,Albums,Search')
  231. check('Desktop: rows are in the page (< 100)', (await rowsInDom()) < 100 && (await rowsInDom()) > 5)
  232. await shot('songs-1280')
  233. await goto('/search'); await page.type('#q', 'zebra'); await page.waitFor(`(() => { const h = [...document.querySelectorAll('jb-hits h2')].find((x) => x.textContent.startsWith('Songs')); return !!h && h.textContent === 'Songs · 1' })()`, { timeout: 15000 })
  234. await shot('search-1280')
  235. await goto('/albums'); await page.waitForSelector('virtual-list .vl-row:not(.blank)'); await sleep(1500); await page.click('virtual-list .vl-row:not(.blank)')
  236. await page.waitFor(`location.pathname.startsWith('/albums/')`); await sleep(1200)
  237. await shot('album-1280')
  238. await page.click('virtual-list .vl-row:not(.blank)')
  239. await page.waitFor(`(() => { const a = document.querySelector('media-player audio'); return a && a.currentTime > 0.6 && !a.paused })()`, { timeout: 20000 })
  240. await sleep(500)
  241. const bar2 = await ev(`(() => { const bar = document.querySelector('.jb-bar').getBoundingClientRect(); const t = document.querySelector('.jb-bar .mp-cover h2').getBoundingClientRect(); return { title: document.querySelector('.jb-bar .mp-cover h2').textContent, inside: t.top >= bar.top && t.bottom <= bar.bottom && t.width > 40, times: document.querySelector('.jb-bar .mp-times').getBoundingClientRect().width > 20 } })()`)
  242. check('Desktop: a song without a cover still shows its title in the bar, and the times', bar2.title.length > 3 && bar2.inside && bar2.times, JSON.stringify(bar2))
  243. await shot('player-1280')
  244. check('Desktop: the player bar plays', true)
  245. await page.close()
  246. } catch (e) {
  247. fail++; console.log('FAIL the gate stopped: ' + (e && e.stack || e)); if (log) console.log(log.slice(-2000))
  248. } finally {
  249. await stop()
  250. }
  251. console.log(`\n${pass} passed, ${fail} failed`)
  252. process.exit(fail ? 1 : 0)

Branches

Latest commits

  • 76639655Records: B1 questionmre
  • d7906b36Records: mission 005 startedmre
  • d3df773cMission 005: doc linemre
  • 6a5d840aMission 005: jukebox#22mre
  • 13e5e748Records: mission 004 startedmre
  • a8098271Mission 004: jukebox#21mre
  • df8f5205Records: jukebox#19-21, #11 closedmre
  • b7a4e692Records: hybriel#298mre
  • 9bcbb017Records: day38b waits for day39 fixmre
  • f80504e1Records: day38b repro sentmre
  • 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
  • 68aace7fRecords: mission 003 day38bmre
  • d105d8a9Records: mpackdb integrity check cleanmre
  • 6e980c53Records: mpackdb rule refinementmre
  • 6d335ac4Records: storage copy rulingmre
  • 7eb2898dRecords: mpackdb second-opener rule until day38mre
  • b011f98eRecords: style form live on day35mre
  • 60d90cb2Records: L1 woken for the restartmre
  • 75ae544fRecords: restart waits for the connection to closemre
  • e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre