Redesign player navigation, add personal listening stats and improve lyrics
Build and Publish / Build and Publish Docker Image (push) Successful in 2m36s
Build and Publish / Build and Publish Docker Image (push) Successful in 2m36s
This commit is contained in:
1 parent
bc0a1f38c8
commit
bdbee5beb3
38 files changed
+2041
-810
No files matched your search
@@ -0,0 +1,100 @@
|
||||
// Render with FURU_PODCAST_RENDER_FIXTURE=1 cargo test renders_podcast_navigation_and_views.
|
||||
const assert = require('node:assert/strict');
|
||||
const {readFileSync} = require('node:fs');
|
||||
const {chromium} = require(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
||||
|
||||
const html = readFileSync('target/podcast-player-fixture.html', 'utf8');
|
||||
const alpine = readFileSync('target/podcast-alpine.min.js', 'utf8');
|
||||
const seeder = {title: 'Hours', artist_names: ['Singer'], release_title:'Dawn', release_id: 7,
|
||||
content_id:'b3:abc', track_id:3, listened_ms:180000, completed:true, device_name:'Browser'};
|
||||
const overview = {
|
||||
artists: { title:'Singer', artist_id: 8, plays: 5, detail:'', artist_names:[] },
|
||||
tracks: { ...seeder, plays:5, detail:'Singer' },
|
||||
releases: { ...seeder, title:'Dawn', plays:5, detail:'Singer' },
|
||||
};
|
||||
|
||||
async function run(browser, width, locale) {
|
||||
const page = await browser.newPage({viewport:{width, height:850}, timezoneId:'Europe/Madrid', locale});
|
||||
page.setDefaultTimeout(6000);
|
||||
const errors = [];
|
||||
const queries = [];
|
||||
let fail = false;
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await page.route('**/*', async route => {
|
||||
const url = new URL(route.request().url());
|
||||
const send = json => route.fulfill({json});
|
||||
if (url.hostname === 'listens.test' && url.pathname === '/') {
|
||||
return route.fulfill({contentType:'text/html', body: html.replace(/(<html[^>]*\blang=)"[^"]+"/, '$1"'+locale+'"')});
|
||||
}
|
||||
if (url.hostname === 'cdn.jsdelivr.net' && url.pathname.includes('alpine')) {
|
||||
return route.fulfill({contentType:'application/javascript', body: alpine});
|
||||
}
|
||||
if (url.pathname === '/api/player/listening') {
|
||||
const query = Object.fromEntries(url.searchParams);
|
||||
queries.push(query);
|
||||
if (fail) return route.fulfill({status:503,json:{}});
|
||||
if (query.view === 'overview') {
|
||||
return send({plays:5, tracks:1, listened_seconds:900, ranking:[overview[query.kind]],
|
||||
daily:[{day:query.to,plays:5,listened_seconds:900}]});
|
||||
}
|
||||
const selected = query.from !== 'all';
|
||||
const date = selected ? query.from : '2026-03-28';
|
||||
return send({page:+query.page, limit:25, total:selected ? 1 : 26, items:[{...seeder,
|
||||
id:'event-'+query.page, title:'Hours '+query.page, started_at_ms: Date.parse(date+'T18:05:00Z')}]});
|
||||
}
|
||||
if (url.pathname === '/api/player/tracks-by-ids') {
|
||||
const ids = route.request().postDataJSON().ids;
|
||||
assert.deepEqual(ids, [3]);
|
||||
return send([{id:3,title:'Hours',duration_seconds:180,artists:[],featured_artists:[],stream_url:'/audio'}]);
|
||||
}
|
||||
if (url.pathname === '/api/player/artists') return send({items:[],total:0,has_more:false});
|
||||
return send([]);
|
||||
});
|
||||
await page.goto('http://listens.test/#listening');
|
||||
const content = page.locator('.my-listening');
|
||||
await content.locator('.listening-totals').waitFor();
|
||||
assert.equal(await content.locator('h1').innerText(), locale === 'ru' ? 'Мои прослушивания' : 'My listening');
|
||||
assert.equal(await content.locator('.listening-day').count(), 30);
|
||||
assert.equal(await content.getByRole('link',{name:'Singer',exact:true}).getAttribute('href'), '#artist/8');
|
||||
await content.locator('select').selectOption('7');
|
||||
await page.waitForFunction(() => document.querySelectorAll('.listening-day').length === 7);
|
||||
assert.equal(queries.at(-1).tz, 'Europe/Madrid');
|
||||
const expectedDay = queries.at(-1).to;
|
||||
await content.locator('.listening-rank-kinds button').nth(1).click();
|
||||
await content.locator('.listening-ranks button').waitFor();
|
||||
await page.evaluate(() => {Alpine.store('queue').playRelease = (tracks, idx) => {window.lastPlayed = tracks[idx].id;};});
|
||||
await content.locator('.listening-ranks button').click();
|
||||
await page.waitForFunction(() => window.lastPlayed === 3);
|
||||
await content.locator('.listening-rank-kinds button').nth(2).click();
|
||||
assert.equal(await content.getByRole('link',{name:'Dawn',exact:true}).getAttribute('href'), '#release/7');
|
||||
await content.locator('.listening-day:not(:disabled)').click();
|
||||
await page.waitForURL('**/#listening/history?day=' + expectedDay);
|
||||
await content.locator('.listening-history-row').waitFor();
|
||||
assert.equal(queries.at(-1).from, expectedDay);
|
||||
assert.equal(queries.at(-1).to, expectedDay);
|
||||
await content.locator('.listening-date-filter a').click();
|
||||
await page.waitForURL('**/#listening/history');
|
||||
await content.locator('.listening-pager:visible button').last().click();
|
||||
await content.getByRole('button',{name:'Hours 2',exact:true}).waitFor();
|
||||
await content.locator('details summary').click();
|
||||
const action = content.locator('details[open] button').first();
|
||||
assert.ok(await action.isVisible());
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false);
|
||||
fail = true;
|
||||
await content.locator('.listening-tabs a').first().click();
|
||||
await content.locator('[role=alert]:visible').waitFor();
|
||||
fail = false;
|
||||
await content.locator('[role=alert] button').click();
|
||||
await content.locator('.listening-totals').waitFor();
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const browser = await chromium.launch({headless:true,...(process.env.CHROME_PATH ? {executablePath:process.env.CHROME_PATH} : {})});
|
||||
try {
|
||||
await run(browser, 1366, 'en');
|
||||
await run(browser, 320, 'ru');
|
||||
console.log('Personal listening overview, playback, day drill-down, history and retry passed on desktop and mobile.');
|
||||
} finally { await browser.close(); }
|
||||
})().catch(error => { console.error(error); process.exitCode = 1; });
|
||||
@@ -11,11 +11,17 @@ const text=Array.from({length:24},(_,i)=>`[00:${String(i*2).padStart(2,'0')}.00]
|
||||
for(const viewport of [{width:1440,height:1000},{width:390,height:844}]){
|
||||
const page=await browser.newPage({viewport,reducedMotion:'reduce'}),errors=[];
|
||||
page.on('pageerror',e=>errors.push(e.message));
|
||||
let holdLyrics=false,releaseLyrics;
|
||||
const waiting=new Promise(resolve=>{releaseLyrics=resolve;});
|
||||
await page.route('**/*',async route=>{
|
||||
const u=new URL(route.request().url());
|
||||
if(u.hostname==='lyrics-ui.test'&&u.pathname==='/') return route.fulfill({contentType:'text/html',body:html});
|
||||
if(u.hostname==='cdn.jsdelivr.net'&&u.pathname.includes('alpine'))return route.fulfill({contentType:'application/javascript',body:alpine});
|
||||
if(u.pathname==='/api/player/lyrics/1')return route.fulfill({json:{versions:[{id:'plain',label:'Plain translation',plain_text:'A plain text translation',source:'manual'},{id:'timed',label:'Original',synced_lrc:text,source:'lrclib'}]}});
|
||||
if(u.pathname==='/api/player/lyrics/1'){
|
||||
if(holdLyrics)await waiting;
|
||||
const alternatives=holdLyrics?Array.from({length:8},(_,i)=>({id:'translation-'+i,label:'Alternative translation '+(i+1),plain_text:'Full text '+i,source:'manual'})):[];
|
||||
return route.fulfill({json:{versions:[{id:'plain',label:'Plain translation',plain_text:'A plain text translation',source:'manual'},{id:'timed',label:'Original',synced_lrc:text,source:'lrclib'},...alternatives]}});
|
||||
}
|
||||
if(u.pathname==='/api/player/lyrics/2')return route.fulfill({json:{versions:[]}});
|
||||
if(u.pathname==='/api/player/lyrics/3')return route.fulfill({json:{versions:[{id:'plain',label:'Plain',plain_text:'Third track lyrics\nAnother line',source:'manual'}]}});
|
||||
if(u.pathname==='/api/player/artists')return route.fulfill({json:{items:[],total:0,has_more:false}});
|
||||
@@ -38,7 +44,7 @@ const text=Array.from({length:24},(_,i)=>`[00:${String(i*2).padStart(2,'0')}.00]
|
||||
const bounds=await page.locator('.lyrics-dialog').boundingBox();
|
||||
assert.equal(Math.round(bounds.width),viewport.width);assert.equal(Math.round(bounds.height),viewport.height);
|
||||
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);
|
||||
await page.selectOption('#lyrics-version','1');
|
||||
await page.getByRole('button',{name:'Plain translation',exact:true}).click();
|
||||
await page.waitForFunction(()=>document.querySelector('.lyrics-plain')?.textContent==='A plain text translation');
|
||||
await page.evaluate(()=>{Alpine.store('player').currentTrack={id:2,title:'No lyrics',artists:[]};Alpine.store('player').currentTime=0;});
|
||||
await page.waitForFunction(()=>Alpine.store('lyrics').loadedKey==='2'&&!Alpine.store('lyrics').loading);
|
||||
@@ -46,11 +52,34 @@ const text=Array.from({length:24},(_,i)=>`[00:${String(i*2).padStart(2,'0')}.00]
|
||||
await page.evaluate(()=>Alpine.store('player').currentTrack={id:3,title:'Plain lyrics track',artists:[]});
|
||||
await page.waitForFunction(()=>document.querySelector('.lyrics-plain')?.textContent.includes('Third track'));
|
||||
await page.keyboard.press('Escape');assert.equal(await page.locator('.lyrics-overlay').count(),0);
|
||||
holdLyrics=true;
|
||||
await page.evaluate(()=>{document.execCommand=command=>{
|
||||
if(command!=='copy')return false;
|
||||
window.copiedLyrics=document.activeElement.value;
|
||||
return true;
|
||||
};});
|
||||
await page.evaluate(t=>Alpine.store('library').openTrackInfo(t),track);
|
||||
await page.getByRole('button',{name:'Available · view',exact:true}).click();
|
||||
await page.locator('.lyrics-heading .lyrics-status').getByText('Loading lyrics…').waitFor();
|
||||
assert.ok((await page.locator('.lyrics-dialog').boundingBox()).height<viewport.height/2,'loading uses a compact header');
|
||||
releaseLyrics();
|
||||
await page.waitForSelector('.lyrics-line');
|
||||
assert.equal(await page.locator('.lyrics-fullscreen').count(),0);
|
||||
assert.ok((await page.locator('.lyrics-dialog').boundingBox()).height<viewport.height);
|
||||
const heading=await page.locator('.lyrics-header').boundingBox(),first=await page.locator('.lyrics-line').first().boundingBox();
|
||||
assert.ok(first.y-heading.y-heading.height<20,'lyrics start immediately after the header');
|
||||
const copy=page.getByRole('button',{name:'Copy lyrics',exact:true});
|
||||
await copy.click();
|
||||
assert.equal(await page.evaluate(()=>window.copiedLyrics),text.split('\n').map(line=>line.slice(line.indexOf(']')+1).trim()).join('\n'));
|
||||
assert.equal(await page.locator('.lyrics-copy-result').textContent(),'Copied');
|
||||
const choices=page.getByRole('group',{name:'Lyrics version'});
|
||||
assert.equal(await choices.getByRole('button',{pressed:true}).textContent(),'LRCLIB');
|
||||
if(viewport.width<600) assert.ok(await choices.evaluate(el=>el.scrollWidth>el.clientWidth),'versions scroll inside the footer');
|
||||
await choices.getByRole('button',{name:'Alternative translation 8',exact:true}).click();
|
||||
assert.equal(await choices.getByRole('button',{pressed:true}).textContent(),'Alternative translation 8');
|
||||
await copy.click();
|
||||
assert.equal(await page.evaluate(()=>window.copiedLyrics),'Full text 7');
|
||||
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);
|
||||
assert.deepEqual(errors,[]);
|
||||
await page.close();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,20 @@ const near=(a,b,message)=>assert.ok(Math.abs(a-b)<1,`${message}: ${a} vs ${b}`);
|
||||
},tracks);
|
||||
await page.waitForSelector('.playlist-track-row');
|
||||
const row=page.locator('.playlist-track-row').first(),pop=row.locator('.popularity-info-btn'),heart=row.locator('.like-btn');
|
||||
if(viewport.width===1440){
|
||||
const title=row.locator('.track-title');
|
||||
await page.evaluate(()=>{
|
||||
Alpine.store('queue').playRelease=(tracks,index)=>{window.playedFromRow=tracks[index].id;};
|
||||
});
|
||||
await title.dblclick({position:{x:12,y:8}});
|
||||
assert.equal(await page.evaluate(()=>window.playedFromRow),tracks[0].id,'double click plays the row');
|
||||
assert.equal(await page.evaluate(()=>getSelection().toString()),'','playing does not select the title');
|
||||
const box=await title.boundingBox();
|
||||
await page.mouse.move(box.x+2,box.y+8);
|
||||
await page.mouse.down();await page.mouse.move(box.x+56,box.y+8,{steps:8});await page.mouse.up();
|
||||
assert.ok((await page.evaluate(()=>getSelection().toString())).trim(),'drag still selects title text');
|
||||
await page.evaluate(()=>getSelection().removeAllRanges());
|
||||
}
|
||||
const initial=await pop.boundingBox(),heartBefore=await heart.boundingBox();
|
||||
const icon=await row.locator('.lyrics-presence').boundingBox();assert.ok(icon.x+icon.width<=initial.x,'lyrics appear to the left of popularity');
|
||||
await page.evaluate(()=>Alpine.store('library').currentPlaylist.tracks[0].has_lyrics=false);
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
// Render the player fixture with FURU_PODCAST_RENDER_FIXTURE=1 before running.
|
||||
const assert = require('node:assert/strict');
|
||||
const { readFileSync } = require('node:fs');
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'playwright');
|
||||
|
||||
const html = readFileSync('target/podcast-player-fixture.html', 'utf8');
|
||||
const alpine = readFileSync('target/podcast-alpine.min.js', 'utf8');
|
||||
const likes = { id: -1, kind: 'likes', title: 'Likes', track_count: 14, is_own: true };
|
||||
const owned = { id: 7, kind: 'user', title: 'Initial D', track_count: 3, is_own: true };
|
||||
const pin = { id: 9, kind: 'release', title: 'Ocean Rain', href: '#release/9' };
|
||||
|
||||
async function checkCollection(browser) {
|
||||
const page = await browser.newPage();
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
const saved = { id: 8, kind: 'user', title: 'Shared mix', is_saved: true, is_public: true, track_count: 4 };
|
||||
const publicMix = { id: 9, kind: 'user', title: 'Public mix', is_public: true, track_count: 6 };
|
||||
const artist = {id: 42, name: 'Echo', track_count: 1};
|
||||
let pins = [];
|
||||
await page.route('**/*', route => {
|
||||
const {hostname, pathname} = new URL(route.request().url());
|
||||
if (hostname === 'sidebar.test' && pathname === '/') return route.fulfill({contentType: 'text/html', body: html});
|
||||
if (hostname === 'cdn.jsdelivr.net' && pathname.includes('alpine')) return route.fulfill({contentType: 'application/javascript', body: alpine});
|
||||
if (pathname === '/api/player/pins' && route.request().method() === 'POST') {
|
||||
const item = route.request().postDataJSON();
|
||||
pins = item.pinned ? [{...item, kind: 'playlist'}] : [];
|
||||
}
|
||||
const responses = {
|
||||
'/api/player/playlists': [likes, owned, saved, publicMix], '/api/player/pins': pins,
|
||||
'/api/player/me': {id: 1, name: 'Listener'}, '/api/player/follows': {artist_ids: [artist.id], artists: [artist]},
|
||||
'/api/player/artists': {items: [], total: 0, has_more: false},
|
||||
};
|
||||
return route.fulfill({json: responses[pathname] || []});
|
||||
});
|
||||
await page.goto('http://sidebar.test/#collection');
|
||||
const entries = page.locator('.collection-list');
|
||||
await entries.getByText(owned.title).waitFor();
|
||||
await entries.getByText(saved.title).waitFor();
|
||||
assert.equal(await entries.getByText(publicMix.title).count(), 0);
|
||||
const ownedRow = entries.locator('.collection-row').filter({hasText: owned.title});
|
||||
await ownedRow.locator('.collection-more').click();
|
||||
await ownedRow.getByRole('button', {name: 'Rename'}).waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await ownedRow.locator('.collection-popup').waitFor({state: 'hidden'});
|
||||
const pinButton = entries.locator('.collection-row').filter({hasText: saved.title}).locator('.collection-pin');
|
||||
const sidebar = page.locator('.sidebar-left .music-shortcuts');
|
||||
await pinButton.click();
|
||||
await sidebar.getByText(saved.title).waitFor();
|
||||
assert.equal(await pinButton.getAttribute('aria-pressed'), 'true');
|
||||
await page.reload();
|
||||
await sidebar.getByText(saved.title).waitFor();
|
||||
await pinButton.click();
|
||||
await sidebar.getByText(saved.title).waitFor({state: 'hidden'});
|
||||
await page.locator('.collection-tabs a[href="#collection?tab=artists"]').click();
|
||||
await entries.getByText(artist.name).waitFor();
|
||||
assert.equal(await entries.locator('a').getAttribute('href'), '#artist/42');
|
||||
await page.locator('.sidebar-left a[href="#artists"]').click();
|
||||
await page.locator('.collection-tabs a[href="#artists?tab=playlists"]').click();
|
||||
await entries.getByText(publicMix.title).waitFor();
|
||||
assert.equal(await entries.getByText(owned.title).count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
|
||||
async function checkSidebar(browser, mobile) {
|
||||
const page = await browser.newPage({ viewport: { width: mobile ? 375 : 1280, height: 800 } });
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await page.route('**/*', route => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.hostname === 'sidebar.test' && url.pathname === '/') return route.fulfill({ contentType: 'text/html', body: html });
|
||||
if (url.hostname === 'cdn.jsdelivr.net' && url.pathname.includes('alpine')) return route.fulfill({ contentType: 'application/javascript', body: alpine });
|
||||
const responses = {
|
||||
'/api/player/artists': { items: [], total: 0, has_more: false },
|
||||
'/api/player/me': { id: 1, name: 'Listener', role: mobile ? 'user' : 'admin' },
|
||||
'/api/player/playlists': [likes, owned], '/api/player/playlists/-1': { ...likes, tracks: [] },
|
||||
'/api/player/pins': mobile ? [pin] : [],
|
||||
};
|
||||
return route.fulfill({ json: responses[url.pathname] || [] });
|
||||
});
|
||||
await page.goto('http://sidebar.test/');
|
||||
const menuButton = page.locator('.mobile-library-btn');
|
||||
const nav = page.locator(mobile ? 'dialog .music-nav' : '.sidebar-left .music-nav');
|
||||
if (mobile) await menuButton.click();
|
||||
await nav.getByRole('link', { name: mobile ? pin.title : owned.title }).waitFor();
|
||||
assert.deepEqual(await nav.locator('.music-nav-pages a').allTextContents().then(values => values.map(value => value.trim())),
|
||||
['Catalog', 'My music', 'Podcasts', 'My listening']);
|
||||
await nav.getByRole('link', { name: /Liked songs/ }).click();
|
||||
await page.waitForURL('**/#playlist/-1');
|
||||
await page.waitForFunction(() => Alpine.store('library').currentPlaylist?.id === -1);
|
||||
if (mobile) {
|
||||
await page.locator('dialog').waitFor({ state: 'detached' });
|
||||
await menuButton.click();
|
||||
await page.locator('dialog:modal').waitFor();
|
||||
await nav.getByRole('link', { name: /Liked songs/ }).click();
|
||||
await page.locator('dialog').waitFor({ state: 'detached' });
|
||||
assert.equal(new URL(page.url()).hash, '#playlist/-1');
|
||||
await menuButton.click();
|
||||
await page.locator('dialog:modal').waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await page.locator('dialog').waitFor({ state: 'detached' });
|
||||
assert.ok(await menuButton.evaluate(element => element === document.activeElement));
|
||||
} else {
|
||||
await page.goto('http://sidebar.test/#artists?tab=playlists');
|
||||
await page.waitForFunction(() => Alpine.store('library').view === 'published');
|
||||
assert.equal(await nav.getByRole('link', { name: 'Catalog' }).getAttribute('aria-current'), 'page');
|
||||
}
|
||||
const trigger = page.locator(mobile ? '.mobile-account-chip' : '.sidebar-account-trigger');
|
||||
const panel = page.locator(mobile ? '#mobile-account-actions' : '#sidebar-account-actions');
|
||||
await trigger.click();
|
||||
await panel.getByRole('button', { name: 'Settings' }).waitFor();
|
||||
assert.equal(await panel.getByRole('link', { name: 'Admin Panel' }).count(), mobile ? 0 : 1);
|
||||
assert.equal(await panel.getByRole('link', { name: 'Log out' }).getAttribute('href'), '/logout');
|
||||
await page.keyboard.press('Escape');
|
||||
await panel.waitFor({ state: 'hidden' });
|
||||
await trigger.click();
|
||||
await panel.getByRole('button', { name: 'Settings' }).click();
|
||||
await page.locator('.user-settings-modal').waitFor();
|
||||
assert.equal(await panel.isVisible(), false);
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const browser = await chromium.launch({
|
||||
headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}),
|
||||
});
|
||||
try {
|
||||
await checkSidebar(browser, false);
|
||||
await checkSidebar(browser, true);
|
||||
await checkCollection(browser);
|
||||
console.log('Desktop and mobile navigation and account controls passed.');
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
})().catch(error => { console.error(error); process.exitCode = 1; });
|
||||
@@ -0,0 +1,65 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const {readFileSync} = require('node:fs');
|
||||
const {test} = require('node:test');
|
||||
const vm = require('node:vm');
|
||||
const script = readFileSync(__dirname + '/../templates/player/listening_scripts.html', 'utf8').replace(/<\/?script>/g, '');
|
||||
|
||||
function setup(fetch, stores = {}) {
|
||||
const Alpine = {store(name, state) {if (state) stores[name] = state; return stores[name];}};
|
||||
vm.runInNewContext(script, {Alpine, fetch, URLSearchParams, AbortController,
|
||||
document:{documentElement:{lang:'en'}, addEventListener(evt, fn) {fn();}}});
|
||||
return stores.listening;
|
||||
}
|
||||
const response = value => ({ok:true,json:async () => value});
|
||||
|
||||
test('a slow overview cannot replace a newer view, and history uses the selected calendar day', async () => {
|
||||
const requests = [];
|
||||
const listening = setup((url, options) => new Promise(resolve => requests.push({url,options,resolve})));
|
||||
const first = listening.enter('overview');
|
||||
const second = listening.enter('history','2026-10-25');
|
||||
assert.equal(requests[0].options.signal.aborted, true);
|
||||
const q = new URL(requests[1].url, 'https://player.test').searchParams;
|
||||
assert.equal(q.get('from'),'2026-10-25');
|
||||
assert.equal(q.get('to'),'2026-10-25');
|
||||
requests[1].resolve(response({items:[],page:1,limit:25,total:0}));
|
||||
await second;
|
||||
requests[0].resolve(response({ranking:[],daily:[],plays:0,tracks:0,listened_seconds:0}));
|
||||
await first;
|
||||
assert.equal(listening.overview, null);
|
||||
assert.equal(listening.loading, false);
|
||||
const third = listening.enter('history','2026-02-31');
|
||||
assert.equal(new URL(requests[2].url, 'https://player.test').searchParams.get('from'), 'all');
|
||||
requests[2].resolve(response({items:[],page:1,limit:25,total:0}));
|
||||
await third;
|
||||
});
|
||||
|
||||
test('leaving and reentering during a track lookup never replaces the queue later', async () => {
|
||||
const requests = [];
|
||||
const library = {view:'listening'};
|
||||
const plays = [];
|
||||
const queue = {playRelease(...args) {plays.push(args);}};
|
||||
const listening = setup((url) => new Promise(resolve => requests.push({url,resolve})), {library, queue});
|
||||
listening.tab = 'history';
|
||||
const row = {id:'after', track_id:2, content_id:'content'};
|
||||
listening.history = {items:[row]};
|
||||
const click = listening.play(row);
|
||||
library.view = 'artists';
|
||||
library.view = 'listening';
|
||||
const visit = listening.enter('overview');
|
||||
requests[0].resolve(response([{id:2}]));
|
||||
await click;
|
||||
requests[1].resolve(response({ranking:[],daily:[],plays:0,tracks:0,listened_seconds:0}));
|
||||
await visit;
|
||||
assert.equal(plays.length, 0);
|
||||
assert.equal(listening.actionError, '');
|
||||
assert.equal(listening.tab, 'overview');
|
||||
});
|
||||
|
||||
test('the chart fills quiet calendar days including the leap day', () => {
|
||||
const listening = setup(() => assert.fail('Unexpected request'));
|
||||
const points = listening.dailyPoints([{day:'2024-03-01',listened_seconds:60,plays:1}],
|
||||
{from:'2024-02-28',to:'2024-03-01'});
|
||||
assert.deepEqual(Array.from(points, row => [row.day,row.height]), [
|
||||
['2024-02-28',0], ['2024-02-29',0], ['2024-03-01',100],
|
||||
]);
|
||||
});
|
||||
@@ -13,6 +13,7 @@ function storeFor(fetch, guest = false) {
|
||||
document: {
|
||||
addEventListener: (_, initialize) => initialize(),
|
||||
documentElement: {lang: 'en'},
|
||||
querySelector: () => null,
|
||||
},
|
||||
Alpine: {
|
||||
store: (name, value) => name === 'lyrics' ? (lyrics = value) : {},
|
||||
@@ -39,6 +40,7 @@ test('saved lyrics display first and peer alternatives preserve the selection',
|
||||
const load = lyrics.load({id: '4'});
|
||||
await new Promise(resolve => setImmediate(resolve));
|
||||
assert.equal(lyrics.currentVersion().id, 'local');
|
||||
assert.equal(lyrics.status(), '', 'saved lyrics are ready while the peer lookup is pending');
|
||||
assert.match(url, /\/federation\/tracks\/lyrics\?content_id=b3%3A/);
|
||||
release(reply([version('duplicate', 'Words'), version('peer', 'New words')]));
|
||||
await load;
|
||||
@@ -46,6 +48,17 @@ test('saved lyrics display first and peer alternatives preserve the selection',
|
||||
assert.equal(lyrics.currentVersion().id, 'local');
|
||||
});
|
||||
|
||||
test('a peer track with a known local copy previews saved lyrics first', async () => {
|
||||
const urls = [];
|
||||
const lyrics = storeFor(async endpoint => {
|
||||
urls.push(endpoint);
|
||||
return reply(endpoint.includes('/federation/') ? [] : [version('local', 'Words')]);
|
||||
});
|
||||
await lyrics.load({id: 'fed:' + id, content_id: id, federation_pending: true, availability: {local: {track_id: 7}}});
|
||||
assert.equal(urls[0], '/api/player/lyrics/7');
|
||||
assert.equal(lyrics.currentVersion().id, 'local');
|
||||
});
|
||||
|
||||
test('guest lyrics use only the share endpoint', async () => {
|
||||
const urls = [];
|
||||
const lyrics = storeFor(async endpoint => {
|
||||
|
||||
Reference in new issue
Block a user