jukebox
All repositories: gitoria
7.0 KB
// tests/jb14.mjs — JB14 (jukebox#14): the Songs screen opens the way it was left: the sort the listener chose is remembered, the sort control shows it,// and the rows really are in that order (before: the browser restored 'most played' in the control while the rows stayed sorted by artist).// Own server on a generated database of 300 songs, headless Chrome. (Header of the older gate follows.) JB13: Own server on a generated database of 300 songs (one 3 s tone), headless Chrome.// Songs sorted by plays and Favourites: the screen is open, a play is counted for another song through POST /api/played/<id> (the order// changes), then a row is tapped: the song that plays (currentSrc of the audio element) must be the tapped row's id. The queue goes on// from that song's place in the new order, and the rows on the screen refresh to what the server now has.// node tests/jb14.mjs env: JB14_PORT (default 8736), JB14_DIR (scratch), JB14_ROOT (checkout to test), HL_PORT_BASE (default 8520), JUKEBOX_COLD_MSimport { spawn, execFileSync } from 'node:child_process'import { rmSync, mkdirSync } from 'node:fs'import { dirname, join } from 'node:path'import { fileURLToPath } from 'node:url'process.env.HL_CHROME = process.env.HL_CHROME || '/opt/google/chrome/chrome'process.env.HL_PORT_BASE = process.env.HL_PORT_BASE || '8520'const { launchBrowser, sleep } = await import('./cdp.mjs')const root = process.env.JB14_ROOT || join(dirname(fileURLToPath(import.meta.url)), '..')const dir = process.env.JB14_DIR || '/media/STORAGE/claude-scratch/atlas/JB14/gate'const port = Number(process.env.JB14_PORT || 8736)const BASE = `http://127.0.0.1:${port}`const COLD_MS = Number(process.env.JUKEBOX_COLD_MS || 150000)let pass = 0, fail = 0const check = (name, ok, detail = '') => { console.log((ok ? 'ok ' : 'FAIL ') + name + (ok ? '' : ' — ' + detail)); if (ok) pass++; else fail++ }mkdirSync(dir, { recursive: true })process.env.TMPDIR = dirlet server = null, browser = null, log = ''async function stop() {if (browser) { try { await browser.close() } catch {} browser = null }if (server) { try { server.kill('SIGTERM') } catch {} await sleep(500); server = null }}process.on('SIGINT', async () => { await stop(); process.exit(1) })const storage = join(dir, 'storage')const tone = join(dir, 'tone3.mp3')rmSync(storage, { recursive: true, force: true })execFileSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=3', '-q:a', '9', tone])const cover = join(root, 'tests/fixtures/withcover/folder.jpg')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 })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'] })console.log('server pid ' + server.pid)server.stdout.on('data', (d) => { log += d }); server.stderr.on('data', (d) => { log += d })const api = async (path) => (await fetch(BASE + path)).json()try {for (const t0 = Date.now(); ; ) {try { if ((await fetch(BASE + '/api/stats')).ok) break } catch {}if (Date.now() - t0 > COLD_MS) { console.log(log); throw new Error('the server did not come up') }await sleep(500)}browser = await launchBrowser()console.log('chrome pid ' + browser.proc?.pid)const page = await browser.newPage()const ev = (e) => page.evaluate(e)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 }) }await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true })const titles = () => ev(`[...document.querySelectorAll('virtual-list .vl-row:not(.blank) .vl-title')].slice(0, 8).map((e) => e.textContent)`)const shown = () => ev(`document.querySelector('#sort').value`)const apiTitles = async (sort) => (await api('/api/songs?sort=' + sort + '&limit=8')).items.map((s) => s.title)const settle = async () => { await page.waitFor(`document.querySelectorAll('virtual-list .vl-row:not(.blank)').length > 4 && document.querySelector('virtual-list .vl-row .vl-title').textContent !== ''`, { label: 'rows' }); await sleep(700) }// some plays so that "most played" differs from the artist orderconst byArtist = (await api('/api/songs?sort=artist&limit=200')).itemsfor (const [i, n] of [[150, 4], [151, 3], [152, 2]]) for (let k = 0; k < n; k++) await fetch(BASE + '/api/played/' + byArtist[i].id, { method: 'POST' })await page.goto(BASE + '/')await settle()check('first visit: the control shows "artist" and the rows are in artist order', (await shown()) === 'artist' && JSON.stringify(await titles()) === JSON.stringify(await apiTitles('artist')), await shown())await page.focus('#sort')for (let i = 0; i < 3; i++) { await press('ArrowDown', 'ArrowDown', 40); await sleep(300) }await settle()check('chosen "most played": the rows are in plays order', (await shown()) === 'plays' && JSON.stringify(await titles()) === JSON.stringify(await apiTitles('plays')), JSON.stringify(await titles()))// the browser reloads the page (and may restore the control by itself)await page.send('Page.reload')await settle()const t1 = JSON.stringify(await titles())check('after a reload: the control shows "most played" and the rows ARE in plays order', (await shown()) === 'plays' && t1 === JSON.stringify(await apiTitles('plays')), `control ${await shown()}, rows ${t1}`)// a fresh tab (nothing restored by the browser): the screen opens the way it was leftconst tab2 = await browser.newPage()await tab2.goto(BASE + '/')await tab2.waitFor(`document.querySelectorAll('virtual-list .vl-row:not(.blank)').length > 4 && document.querySelector('virtual-list .vl-row .vl-title').textContent !== ''`, { label: 'rows in the fresh tab' })await sleep(700)const t2 = JSON.stringify(await tab2.evaluate(`[...document.querySelectorAll('virtual-list .vl-row:not(.blank) .vl-title')].slice(0, 8).map((e) => e.textContent)`))const c2 = await tab2.evaluate(`document.querySelector('#sort').value`)check('a fresh tab opens sorted by plays, the control says so', c2 === 'plays' && t2 === JSON.stringify(await apiTitles('plays')), `control ${c2}, rows ${t2}`)await tab2.close()// choosing another sort is remembered tooawait page.focus('#sort')await press('ArrowUp', 'ArrowUp', 38); await sleep(300); await press('ArrowUp', 'ArrowUp', 38) // album, then titleawait settle()await page.send('Page.reload')await settle()check('title chosen, reloaded: the control and the rows agree (title)', (await shown()) === 'title' && JSON.stringify(await titles()) === JSON.stringify(await apiTitles('title')), `control ${await shown()}`)} finally {await stop()}console.log(`${pass} passed, ${fail} failed`)process.exit(fail ? 1 : 0)
Branches
Latest commits
- cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
- f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
- 9f5c6532Merge branch 'status-22-pr' into mainJukebox
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre
- a01f3aa8ui gate: back to the top before the sort checks (the screen reopens where it was left)mre
- f7936c20Lists keep their scroll position across a reload (jukebox#20): per-list offsets in storage/ui.json, gate jb20mre
- d67906devirtual-list and icons from components.hybriel e5b98ec (centerId, scrollTop, onScroll)mre
- df7920ceRecords: R3 startedmre
- 0549f038Mission 010: jb20 livemre
- 273494e2STATUS rewrittenmre