gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit95f5faae95f5faae|||PR jukebox#7 Drop needless let declarationsmre95f5faae/tests/jb3.mjs

25.3 KB

  1. // tests/jb3.mjs — the PLAYER GATE (mission JB3): shuffle without repeats over the generated 13,459-song database, the favourites shuffle respecting N, a play counted once at its
  2. // threshold, the album and copy rules, and in a real headless Chrome (tests/cdp.mjs, real clicks, keys and touches) the shuffle buttons, the now-playing overlay (open, close
  3. // button, Escape, swipe down), next / previous by button and key, the thumbnail placeholder in every row state, the lock screen's media session. 390 px first, then 1280.
  4. // node tests/jb3.mjs env as tests/ui.mjs (JUKEBOX_UI_PORT default 8712, JUKEBOX_UI_DIR, JUKEBOX_UI_SHOTS, JUKEBOX_UI_URL, HL_PORT_BASE for Chrome)
  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/JB3/gate-jb3'
  14. const shots = process.env.JUKEBOX_UI_SHOTS || join(dir, 'shots')
  15. const port = Number(process.env.JUKEBOX_UI_PORT || 8712)
  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. const j = async (p) => (await fetch(BASE + p)).json()
  49. const stats = (await j('/api/stats')).library
  50. // ---- the shuffle queue over the whole database ------------------------------------------------------------------------------
  51. const allIds = async (min) => { const ids = []; for (let off = 0; ; off += 200) { const r = await j('/api/songs?limit=200&offset=' + off + '&minPlays=' + min); for (const s of r.items) ids.push(s.id); if (off + 200 >= r.total) break } return ids }
  52. const every = await allIds(0)
  53. const q0 = await j('/api/queue?seed=4242&kind=favourites&minPlays=0&from=0&count=' + every.length)
  54. check('shuffle over everything: the pool is the 13,4xx songs shown', q0.pool === every.length && q0.pool > 13000, q0.pool + ' / ' + every.length)
  55. check('shuffle: every song once before any repeats (no id twice in the first round)', new Set(q0.ids).size === q0.ids.length && q0.ids.every((id) => every.includes(id) || true) && new Set(q0.ids.concat(every)).size === every.length)
  56. const q1 = await j('/api/queue?seed=4242&kind=favourites&minPlays=0&from=0&count=50')
  57. check('shuffle: the same seed gives the same order', JSON.stringify(q1.ids) === JSON.stringify(q0.ids.slice(0, 50)))
  58. const q2 = await j('/api/queue?seed=99&kind=favourites&minPlays=0&from=0&count=50')
  59. check('shuffle: another seed gives another order', JSON.stringify(q2.ids) !== JSON.stringify(q1.ids))
  60. const sortedFirst = every.slice(0, 50)
  61. check('shuffle: the order is not the list order', JSON.stringify(q1.ids) !== JSON.stringify(sortedFirst))
  62. const r2 = await j('/api/queue?seed=4242&kind=favourites&minPlays=0&from=' + every.length + '&count=' + every.length)
  63. check('shuffle: the second round is again every song once, in a new order', new Set(r2.ids).size === every.length && JSON.stringify(r2.ids.slice(0, 30)) !== JSON.stringify(q0.ids.slice(0, 30)))
  64. const fav5 = await allIds(5), fav9 = await allIds(9)
  65. const f5 = await j('/api/queue?seed=7&kind=favourites&minPlays=5&from=0&count=' + (fav5.length + 5))
  66. check('favourites shuffle with N = 5: the pool is the songs played at least 5 times', f5.pool === fav5.length && f5.pool < every.length, f5.pool + ' / ' + fav5.length)
  67. const set5 = new Set(fav5)
  68. check('favourites shuffle N = 5: every id is a favourite, each once, then the next round starts', new Set(f5.ids.slice(0, fav5.length)).size === fav5.length && f5.ids.every((id) => set5.has(id)))
  69. const f9 = await j('/api/queue?seed=7&kind=favourites&minPlays=9&from=0&count=' + fav9.length)
  70. const set9 = new Set(fav9)
  71. check('favourites shuffle respects N: with N = 9 the pool shrinks and only songs played 9 times or more come', f9.pool === fav9.length && f9.pool < f5.pool && f9.ids.every((id) => set9.has(id)), f9.pool + ' / ' + f5.pool)
  72. // ---- albums (CD markers) and copies ---------------------------------------------------------------------------------------
  73. const twins = (await j('/api/search?q=twin%20album')).albums.filter((a) => a.name === 'Twin Album')
  74. check('album grouping: "Twin Album CD 1" and "(Cd2)" are ONE album, not folders', twins.length === 1, JSON.stringify(twins.map((a) => a.name)))
  75. const copySong = (await j('/api/search?q=' + encodeURIComponent('Copied Song'))).songs.items
  76. check('copies: two files of one song (same artist and title, lengths 1.5 s apart) are listed once as "2 copies"; the 130 s version is its own song', copySong.length === 2 && copySong.filter((s) => s.copies === 2).length === 1 && copySong.filter((s) => s.copies === 1).length === 1, JSON.stringify(copySong.map((s) => [s.title, s.copies, s.duration])))
  77. // ---- counting by the API ---------------------------------------------------------------------------------------------------
  78. const target = every[3]
  79. const before = (await j('/api/songs?limit=200&offset=0')).items.find((s) => s.id === target)
  80. const posted = await fetch(BASE + '/api/played/' + target, { method: 'POST' }).then((r) => r.json())
  81. check('POST /api/played adds 1 to the jukebox counter and leaves the file count alone', posted.jukeboxPlays === 1 && posted.filePlays === before.filePlays, JSON.stringify(posted))
  82. check('POST /api/played of an unknown song is 404', (await fetch(BASE + '/api/played/nosuch', { method: 'POST' })).status === 404)
  83. check('GET /api/played is refused (405)', (await fetch(BASE + '/api/played/' + target)).status === 405)
  84. const songAfter = (await j('/api/songs?limit=200&offset=0')).items.find((s) => s.id === target)
  85. check('the shown play count is file count + jukebox count', songAfter.playCount === before.filePlays + 1 && songAfter.jukeboxPlays === 1, JSON.stringify([before.playCount, songAfter.playCount]))
  86. // ---- the browser, phone first --------------------------------------------------------------------------------------------
  87. browser = await launchBrowser()
  88. const page = await browser.newPage()
  89. const ev = (e) => page.evaluate(e)
  90. const shot = async (name) => { const s = await page.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(shots, name + '.png'), Buffer.from(s.data, 'base64')) }
  91. const press = async (key, code, vk, text) => { await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key, code, windowsVirtualKeyCode: vk, text }); await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key, code, windowsVirtualKeyCode: vk }) }
  92. const goto = async (path) => { await page.goto(BASE + path); await page.waitForSelector('jb-screen') }
  93. const playing = () => page.waitFor(`(() => { const a = document.querySelector('media-player audio'); return a && a.src.includes('/stream/') && a.currentTime > 0.4 && !a.paused })()`, { timeout: 30000, label: 'audio plays' })
  94. const nowTitle = () => ev(`(document.querySelector('.jb-bar .mp-cover h2')||{}).textContent`)
  95. const nowSrc = () => ev(`document.querySelector('media-player audio').src`)
  96. const open = () => ev(`document.querySelector('.jb-app').classList.contains('open')`)
  97. const changed = async (old) => { await page.waitFor(`document.querySelector('.jb-bar .mp-cover h2').textContent !== ${JSON.stringify(old)}`, { timeout: 15000, label: 'title changes' }); await sleep(300) }
  98. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 2, mobile: true })
  99. await page.send('Emulation.setTouchEmulationEnabled', { enabled: true, maxTouchPoints: 5 })
  100. await goto('/'); await page.waitForSelector('virtual-list .vl-row'); await sleep(800)
  101. check('Songs: "Shuffle my favourites" is there as an ordinary button like Shuffle (JB19: no longer the big one)', (await ev(`(() => { const b = document.querySelector('#shuffle-fav'), s = document.querySelector('#shuffle'); return b.getBoundingClientRect().width < 300 && Math.abs(b.getBoundingClientRect().height - s.getBoundingClientRect().height) < 3 && !b.classList.contains('jb-big') })()`)))
  102. await shot('songs-390')
  103. await page.click('#shuffle-fav'); await playing()
  104. const first = await nowTitle()
  105. check('Shuffle my favourites: a song plays and the bar shows it', first.length > 3 && (await ev(`document.querySelector('.jb-app').classList.contains('playing')`)))
  106. const startSrc = await nowSrc()
  107. const startId = startSrc.split('/stream/')[1]
  108. check('Shuffle my favourites: the song is one of the favourites (played at least 5 times)', set5.has(startId), startId)
  109. check('the bar is not the overlay yet', !(await open()))
  110. const barGeo = await ev(`(() => { const r = (s) => document.querySelector(s).getBoundingClientRect(); const bar = r('.jb-bar'); return { h: Math.round(bar.height), bottom: Math.round(bar.bottom), vh: innerHeight, prev: r('.jb-bar .jb-prev').width, next: r('.jb-bar .jb-next').width, play: r('.jb-bar .mp-play').width, shuffle: r('.jb-bar #jb-shuffle').width, repeat: r('.jb-bar #jb-repeat').width, back: document.querySelectorAll('.jb-bar .mp-back, .jb-bar .mp-forward').length, titleOk: r('.jb-bar .mp-cover h2').width > 60 } })()`)
  111. check('the bar: shuffle / previous / play / next / repeat shown (JB19: no 10 s buttons at all), title readable, progress bar half a finger', barGeo.h >= 68 && barGeo.h <= 84 && barGeo.bottom === barGeo.vh && barGeo.prev > 40 && barGeo.next > 40 && barGeo.play > 40 && barGeo.shuffle > 40 && barGeo.repeat > 40 && barGeo.back === 0 && barGeo.titleOk, JSON.stringify(barGeo))
  112. await shot('bar-390')
  113. // the overlay: a tap on the bar
  114. await page.click('.jb-bar .mp-cover h2'); await page.waitFor(`document.querySelector('.jb-app').classList.contains('open')`)
  115. await sleep(500)
  116. const ov = await ev(`(() => { const r = (s) => document.querySelector(s).getBoundingClientRect(); const vis = (s) => { const b = r(s); return b.width > 20 && b.height > 20 && b.top >= 0 && b.bottom <= innerHeight } ; const bar = r('.jb-bar'); const lis = [...document.querySelectorAll('.jb-bar ol.mp-queue li')].filter((l) => l.getBoundingClientRect().height > 0).length; return { bar: [Math.round(bar.left), Math.round(bar.top), Math.round(bar.width), Math.round(bar.height)], cover: Math.round(r('.jb-bar .mp-cover img').width), title: document.querySelector('.jb-bar .mp-cover h2').textContent, artist: document.querySelector('.jb-bar .mp-cover p').textContent, album: document.querySelector('.jb-bar .jb-album').textContent, controls: ['#jb-shuffle', '.jb-prev', '.mp-play', '.jb-next', '#jb-repeat', '.mp-mute', '.mp-speed', '.mp-times', 'mp-seek', '.jb-close'].map((s) => vis('.jb-bar ' + s)), queue: lis } })()`)
  117. check('Overlay (phone): a tap on the bar opens it full screen', ov.bar[0] === 0 && ov.bar[1] === 0 && ov.bar[2] === 390 && ov.bar[3] === 844, JSON.stringify(ov.bar))
  118. check('Overlay: large cover (≥ 200 px), title, artist and album are shown', ov.cover >= 200 && ov.title.length > 3 && ov.artist.length > 2 && ov.album.length > 2, JSON.stringify(ov))
  119. check('Overlay: shuffle, previous, play, next, repeat, mute, speed, times, seek line and close are all on screen', ov.controls.every((x) => x), JSON.stringify(ov.controls))
  120. check('Overlay: the queue lists the playing song and the 20 after it (21 rows at most)', ov.queue >= 20 && ov.queue <= 21, '' + ov.queue)
  121. await shot('overlay-390')
  122. // next and previous with the buttons
  123. await page.click('.jb-bar .jb-next'); await changed(first)
  124. const second = await nowTitle()
  125. await playing()
  126. check('Next (button): the next song of the shuffle plays', second !== first && (await nowSrc()) !== startSrc)
  127. await page.click('.jb-bar .jb-prev'); await changed(second); await playing()
  128. check('Previous (button) within 3 s: the song before plays again', (await nowTitle()) === first && (await nowSrc()) === startSrc)
  129. // the lock screen
  130. const ms = await ev(`(() => { const m = navigator.mediaSession; return m && m.metadata ? { title: m.metadata.title, artist: m.metadata.artist, album: m.metadata.album, art: m.metadata.artwork.length } : null })()`)
  131. check('Media session: title, artist, album and artwork are set for the lock screen', ms && ms.title === (await nowTitle()) && ms.artist.length > 2 && ms.album.length > 2 && ms.art === 1, JSON.stringify(ms))
  132. // close: button, Escape, swipe down
  133. await page.click('.jb-bar .jb-close'); await page.waitFor(`!document.querySelector('.jb-app').classList.contains('open')`)
  134. check('Overlay: the close button closes it', !(await open()))
  135. await page.click('.jb-bar .mp-cover h2'); await page.waitFor(`document.querySelector('.jb-app').classList.contains('open')`); await sleep(300)
  136. const touch = async (type, x, y) => page.send('Input.dispatchTouchEvent', { type, touchPoints: type === 'touchEnd' ? [] : [{ x, y }] })
  137. await touch('touchStart', 195, 150); for (let y = 170; y <= 330; y += 20) { await touch('touchMove', 195, y); await sleep(20) } ; await touch('touchEnd', 195, 330)
  138. await sleep(400)
  139. check('Overlay: a swipe down over the cover closes it', !(await open()))
  140. await touch('touchStart', 195, 780); await page.click('.jb-bar .mp-cover h2'); await page.waitFor(`document.querySelector('.jb-app').classList.contains('open')`); await touch('touchEnd', 195, 780)
  141. // a short swipe or one on the queue must not close it
  142. await sleep(300)
  143. await touch('touchStart', 195, 150); for (let y = 160; y <= 200; y += 10) { await touch('touchMove', 195, y); await sleep(20) } ; await touch('touchEnd', 195, 200); await sleep(300)
  144. check('Overlay: a short drag (40 px) does not close it', await open())
  145. await page.click('.jb-bar .jb-close'); await sleep(300)
  146. // the thumbnail placeholder stays in every row state
  147. await goto('/'); await page.waitForSelector('virtual-list .vl-row:not(.blank)'); await sleep(600)
  148. const thumbBg = () => ev(`(() => { const rows = [...document.querySelectorAll('.vl-row:not(.blank)')]; return rows.slice(0, 8).map((r) => { const t = r.querySelector('.vl-thumb'); const b = t ? t.getBoundingClientRect() : { width: 0 }; const cs = t ? getComputedStyle(t) : { backgroundColor: 'none' }; return [b.width > 20, cs.backgroundColor, r.className] }) })()`)
  149. const plain = await thumbBg()
  150. check('Rows: every row has a visible thumbnail box with a background', plain.every((x) => x[0] && x[1] !== 'rgba(0, 0, 0, 0)'), JSON.stringify(plain.slice(0, 2)))
  151. await page.click('virtual-list .vl-row:not(.blank)'); await playing(); await sleep(400)
  152. await page.focus('virtual-list .vl-row:not(.blank)')
  153. const marked = await thumbBg()
  154. check('Rows: the playing and the focused row keep their thumbnail placeholder', marked.every((x) => x[0] && x[1] !== 'rgba(0, 0, 0, 0)'), JSON.stringify(marked.slice(0, 3)))
  155. await goto('/search'); await page.type('#q', 'copied song'); await page.waitFor(`[...document.querySelectorAll('jb-hits h2')].some((x) => x.textContent.startsWith('Songs'))`, { timeout: 15000, label: 'songs heading' }); const sh = await ev(`[...document.querySelectorAll('jb-hits h2')].map((x) => x.textContent).join('|')`); check('Search: "copied song" finds the two songs (three files) and the heading counts them', sh.includes('Songs · 2'), sh)
  156. await page.focus('virtual-list .vl-row:not(.blank)'); await sleep(300)
  157. const sr = await thumbBg()
  158. check('Search: the result row with focus keeps its thumbnail placeholder', sr.length > 0 && sr.every((x) => x[0] && x[1] !== 'rgba(0, 0, 0, 0)'), JSON.stringify(sr))
  159. check('Search: the song in two folders shows once with "2 copies" in its row', (await ev(`[...document.querySelectorAll('.vl-row:not(.blank) .vl-sub')].map((e) => e.textContent).join('|')`)).includes('2 copies'))
  160. await page.type('#q', ''); await ev(`(() => { const q = document.querySelector('#q'); q.value = ''; q.dispatchEvent(new Event('input', { bubbles: true })) })()`)
  161. await page.type('#q', 'rosa'); await page.waitFor(`document.querySelectorAll('.vl-row:not(.blank)').length > 3`, { timeout: 15000 }); await sleep(500)
  162. await shot('search-390')
  163. const heads = await ev(`[...document.querySelectorAll('jb-hits h2')].map((h) => h.textContent)`)
  164. check('Search: the headings carry their own counts', heads.length > 0 && heads.every((h) => /\d/.test(h)), JSON.stringify(heads))
  165. // shuffle of a list: search
  166. await page.type('#q', ''); await ev(`(() => { const q = document.querySelector('#q'); q.value = ''; q.dispatchEvent(new Event('input', { bubbles: true })) })()`)
  167. await page.type('#q', 'rosa amber 16'); await sleep(1500)
  168. await page.click('#shuffle'); await playing()
  169. const sid = (await nowSrc()).split('/stream/')[1]
  170. const found = (await j('/api/search?q=' + encodeURIComponent('rosa amber 16') + '&limit=200')).songs.items.map((s) => s.id)
  171. check('Shuffle on the search list: the song that plays is one of the results', found.includes(sid))
  172. // a multi-CD album and its Shuffle
  173. await goto('/albums/' + twins[0].id); await page.waitForSelector('.vl-row:not(.blank)'); await sleep(900)
  174. const titles = await ev(`[...document.querySelectorAll('.vl-row:not(.blank) .vl-title')].map((e) => e.textContent)`)
  175. check('Multi-CD album: one album, the rows lead with disc and track ("1-1. …", "2-1. …")', titles.length >= 4 && titles.some((t) => t.startsWith('1-1.')) && titles.some((t) => t.startsWith('2-1.')), JSON.stringify(titles))
  176. check('Multi-CD album: the head says it has 2 discs', (await ev(`document.querySelector('jb-head').textContent`)).includes('2 discs'))
  177. await shot('album-twin-390')
  178. const albumIds = new Set((await j('/api/songs?limit=200&sort=artist&album=' + twins[0].id)).items.map((s) => s.id))
  179. await page.click('#shuffle'); await playing()
  180. const aid = (await nowSrc()).split('/stream/')[1]
  181. check('Shuffle on an album plays a song of that album (and the API knows the album)', albumIds.size >= 4 && albumIds.has(aid), aid)
  182. // favourites view
  183. await goto('/'); await page.waitForSelector('virtual-list .vl-row'); await page.click('#fav'); await sleep(900)
  184. check('Favourites view: the Shuffle my favourites button is there too', (await ev(`document.querySelector('#shuffle-fav').getBoundingClientRect().width`)) > 0)
  185. await page.focus('#favmin'); await ev(`document.querySelector('#favmin').select()`); await page.send('Input.insertText', { text: '11' })
  186. await page.waitFor(`document.querySelector('#count').textContent.startsWith(${JSON.stringify((await allIds(11)).length.toLocaleString('en-US'))})`, { timeout: 10000, label: 'N = 11' })
  187. const set11 = new Set(await allIds(11))
  188. await shot('favourites-390')
  189. const seen = new Set()
  190. for (let i = 0; i < 3; i++) { await page.click('#shuffle-fav'); await playing(); seen.add((await nowSrc()).split('/stream/')[1]); await sleep(300) }
  191. check('Favourites view: Shuffle my favourites uses the N of the field (11): every song that played has been played 11 times or more', [...seen].every((id) => set11.has(id)), JSON.stringify([...seen]))
  192. // counting a play: after half of the 60 s song, once
  193. await goto('/'); await page.waitForSelector('virtual-list .vl-row')
  194. await page.click('#shuffle-fav'); await playing()
  195. const c1 = (await nowSrc()).split('/stream/')[1]
  196. const c1title = await nowTitle()
  197. await page.click('.jb-bar .jb-next'); await sleep(1500) // skipped after 1.5 s: must not count
  198. await playing()
  199. const c2 = (await nowSrc()).split('/stream/')[1]
  200. const jbOf = async (id) => (await j('/api/search?q=' + encodeURIComponent(await ev(`document.querySelector('.jb-bar .mp-cover h2').textContent`)))).songs.items.find((s) => s.id === id)
  201. const t00 = Date.now()
  202. await sleep(20000)
  203. const at20 = await jbOf(c2)
  204. check('Counting: after 20 s of a 60 s song nothing is counted yet', at20 && at20.jukeboxPlays === 0, JSON.stringify(at20 && at20.jukeboxPlays))
  205. await page.waitFor(`(() => document.querySelector('media-player audio').currentTime > 31)()`, { timeout: 30000 })
  206. await sleep(2500)
  207. const at33 = await jbOf(c2)
  208. check('Counting: after half of the song (30 s) the play is counted: the jukebox counter is 1', at33 && at33.jukeboxPlays === 1, JSON.stringify(at33 && at33.jukeboxPlays))
  209. await sleep(6000)
  210. const at40 = await jbOf(c2)
  211. check('Counting: it counts once, not again while the song goes on', at40 && at40.jukeboxPlays === 1 && at40.playCount === at33.playCount, JSON.stringify(at40 && [at40.jukeboxPlays, at40.playCount]))
  212. console.log('counting took ' + (Date.now() - t00) + ' ms')
  213. const skipped = (await j('/api/search?q=' + encodeURIComponent(c1title))).songs.items.find((x) => x.id === c1)
  214. check('Counting: the song skipped after 1.5 s was not counted', skipped && skipped.jukeboxPlays === 0, JSON.stringify(skipped && skipped.jukeboxPlays))
  215. check('The page has no script errors', page.problems().filter((m) => m.level === 'error').length === 0, page.dumpConsole())
  216. // ---- desktop -------------------------------------------------------------------------------------------------------------
  217. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false })
  218. await page.send('Emulation.setTouchEmulationEnabled', { enabled: false })
  219. await goto('/'); await page.waitForSelector('virtual-list .vl-row:not(.blank)'); await sleep(600)
  220. await shot('songs-1280')
  221. await page.click('#shuffle-fav'); await playing(); await sleep(500)
  222. const bar2 = await ev(`(() => { const r = document.querySelector('.jb-bar').getBoundingClientRect(); return { h: Math.round(r.height), times: document.querySelector('.jb-bar .mp-times').getBoundingClientRect().width > 20 } })()`)
  223. check('Desktop: the bar has the times and a half-finger progress bar', bar2.h >= 76 && bar2.h <= 92 && bar2.times, JSON.stringify(bar2))
  224. await shot('bar-1280')
  225. await page.click('.jb-bar .mp-cover h2'); await page.waitFor(`document.querySelector('.jb-app').classList.contains('open')`); await sleep(500)
  226. const panel = await ev(`(() => { const b = document.querySelector('.jb-bar').getBoundingClientRect(); const h = document.querySelector('application-header').getBoundingClientRect(); const s = document.querySelector('jb-screen').getBoundingClientRect(); return { left: Math.round(b.left), top: Math.round(b.top), width: Math.round(b.width), bottom: Math.round(b.bottom), headerBottom: Math.round(h.bottom), screenRight: Math.round(s.right), cover: Math.round(document.querySelector('.jb-bar .mp-cover img').getBoundingClientRect().width), queue: [...document.querySelectorAll('.jb-bar ol.mp-queue li')].filter((l) => l.getBoundingClientRect().height > 0).length } })()`)
  227. check('Overlay (desktop): a side panel at the right under the header, the list beside it', panel.width === 384 && panel.left === 1280 - 384 && panel.top === panel.headerBottom && panel.bottom === 800 && panel.screenRight <= panel.left + 1, JSON.stringify(panel))
  228. check('Overlay (desktop): large cover and the queue of the next songs', panel.cover >= 150 && panel.queue >= 15, JSON.stringify(panel))
  229. await shot('overlay-1280')
  230. await page.click('.jb-bar .jb-close'); await page.waitFor(`!document.querySelector('.jb-app').classList.contains('open')`)
  231. await goto('/albums/' + twins[0].id); await page.waitForSelector('.vl-row:not(.blank)'); await sleep(900)
  232. await shot('album-twin-1280')
  233. await goto('/search'); await page.type('#q', 'rosa'); await page.waitFor(`document.querySelectorAll('.vl-row:not(.blank)').length > 3`, { timeout: 15000 }); await sleep(500)
  234. await shot('search-1280')
  235. await page.close()
  236. } catch (e) {
  237. fail++; console.log('FAIL the gate stopped: ' + (e && e.stack || e)); if (log) console.log(log.slice(-2000))
  238. } finally {
  239. await stop()
  240. }
  241. console.log(`\n${pass} passed, ${fail} failed`)
  242. process.exit(fail ? 1 : 0)

Branches

Latest commits

  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 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