feat: add similar tracks and artwork preview to now playing
This commit is contained in:
1 parent
50926cc7bb
commit
ce8f5700ef
6 files changed
+272
-52
No files matched your search
@@ -0,0 +1,107 @@
|
||||
// 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 artwork = '<svg xmlns="http://www.w3.org/2000/svg" width="640" height="640"><rect width="640" height="640" fill="green"/></svg>';
|
||||
const localCover = '/api/player/cover/10/medium';
|
||||
|
||||
async function setTrack(page, id, cover) {
|
||||
await page.evaluate(([id, cover]) => {
|
||||
Alpine.store('player').currentTrack = {
|
||||
id, title: 'Track ' + id, artists: [], featured_artists: [], cover_url: cover,
|
||||
};
|
||||
}, [id, cover]);
|
||||
}
|
||||
|
||||
async function setup(browser, options) {
|
||||
const page = await browser.newPage({ ...options, reducedMotion: 'reduce' });
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await page.route('**/*', route => {
|
||||
const { pathname, hostname } = new URL(route.request().url());
|
||||
if (hostname === 'artwork.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 (route.request().resourceType() === 'image') return route.fulfill({ contentType: 'image/svg+xml', body: artwork });
|
||||
if (pathname === '/api/player/artists') return route.fulfill({ json: { items: [], total: 0, has_more: false } });
|
||||
return route.fulfill({ json: [] });
|
||||
});
|
||||
await page.goto('http://artwork.test/');
|
||||
await page.waitForFunction(() => window.Alpine?.store('player'));
|
||||
await setTrack(page, 1, localCover);
|
||||
return { page, errors, cover: page.locator('button.player-cover'), preview: page.locator('.player-cover-preview') };
|
||||
}
|
||||
|
||||
async function desktop(browser) {
|
||||
const { page, errors, cover, preview } = await setup(browser, { viewport: { width: 1366, height: 850 } });
|
||||
await preview.waitFor({ state: 'hidden' });
|
||||
await cover.hover();
|
||||
const enlarged = preview.locator('img[src="/api/player/cover/10/large"]');
|
||||
await enlarged.waitFor();
|
||||
const small = await cover.boundingBox(), large = await enlarged.boundingBox();
|
||||
assert.ok(large.width > small.width * 2 && large.height > small.height * 2);
|
||||
assert.ok(large.x >= 0 && large.y >= 0 && large.x + large.width <= 1366 && large.y + large.height <= 850);
|
||||
const outside = { x: 1350, y: 10 };
|
||||
await page.mouse.move(outside.x, outside.y);
|
||||
await preview.waitFor({ state: 'hidden' });
|
||||
|
||||
await cover.hover();
|
||||
await cover.click();
|
||||
await page.mouse.move(outside.x, outside.y);
|
||||
await enlarged.click();
|
||||
await page.mouse.move(outside.x, outside.y);
|
||||
// An unpinned preview closes after the pointer has crossed the gap between the images.
|
||||
await page.waitForTimeout(300);
|
||||
assert.ok(await enlarged.isVisible(), 'pinned artwork survives pointer exit and clicks inside');
|
||||
|
||||
const sharedCover = '/api/player/shares/test-token/cover/2';
|
||||
await setTrack(page, 2, sharedCover);
|
||||
await preview.locator('img[src="' + sharedCover + '"]').waitFor();
|
||||
await page.mouse.click(outside.x, outside.y);
|
||||
await preview.waitFor({ state: 'hidden' });
|
||||
await cover.focus();
|
||||
await page.keyboard.press('Enter');
|
||||
await preview.waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await preview.waitFor({ state: 'hidden' });
|
||||
await cover.click();
|
||||
await preview.waitFor();
|
||||
await setTrack(page, 3, null);
|
||||
await preview.waitFor({ state: 'hidden' });
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
}
|
||||
|
||||
async function mobile(browser) {
|
||||
const { page, errors, cover, preview } = await setup(browser, {
|
||||
viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true,
|
||||
});
|
||||
await cover.tap();
|
||||
await page.locator('.player-bar.mobile-expanded').waitFor();
|
||||
await preview.waitFor({ state: 'hidden' });
|
||||
await cover.tap();
|
||||
await preview.locator('img[src="/api/player/cover/10/large"]').waitFor();
|
||||
const bounds = await preview.boundingBox();
|
||||
assert.ok(bounds.x >= 0 && bounds.y >= 0 && bounds.x + bounds.width <= 390 && bounds.y + bounds.height <= 844);
|
||||
const outsideY = bounds.y > 2 ? 1 : Math.ceil(bounds.y + bounds.height) + 1;
|
||||
await page.touchscreen.tap(1, outsideY);
|
||||
await preview.waitFor({ state: 'hidden' });
|
||||
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 desktop(browser);
|
||||
await mobile(browser);
|
||||
console.log('Player artwork hover, pin, dismissal, track changes and touch checks passed.');
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
})().catch(error => { console.error(error); process.exitCode = 1; });
|
||||
@@ -14,6 +14,12 @@ const near=(a,b,message)=>assert.ok(Math.abs(a-b)<1,`${message}: ${a} vs ${b}`);
|
||||
if(url.hostname==='layout.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});
|
||||
if(url.pathname==='/api/player/artists')return route.fulfill({json:{items:[],total:0,has_more:false}});
|
||||
if(/^\/api\/player\/similarity\/[12]$/.test(url.pathname)){
|
||||
const seedId=Number(url.pathname.split('/').at(-1));
|
||||
return route.fulfill({json:url.searchParams.has('local_only')
|
||||
? {label:tracks[seedId-1].title,tracks:[tracks[2]]}
|
||||
: {federation_tracks:[],queried_peers:0}});
|
||||
}
|
||||
return route.fulfill({json:[]});
|
||||
});
|
||||
await page.goto('http://layout.test/');await page.waitForFunction(()=>window.Alpine?.store('library')&&Alpine.store('player'));
|
||||
@@ -30,6 +36,14 @@ const near=(a,b,message)=>assert.ok(Math.abs(a-b)<1,`${message}: ${a} vs ${b}`);
|
||||
near((await pop.boundingBox()).x,initial.x,'popularity must not move');near((await heart.boundingBox()).x,heartBefore.x,'other actions must not move');
|
||||
await page.evaluate(()=>Alpine.store('library').currentPlaylist.tracks[0].has_lyrics=true);await row.locator('.lyrics-presence').waitFor({state:'visible'});
|
||||
assert.equal(await page.locator('.lyrics-toggle:visible').count(),1,'only one player lyrics button');
|
||||
const current=page.locator('.player-current-track');
|
||||
const similar=current.getByRole('button',{name:'Find similar tracks',exact:true});
|
||||
const bounds=await current.boundingBox(),button=await similar.boundingBox();
|
||||
assert.ok(button&&button.x>=bounds.x && button.x+button.width<=bounds.x+bounds.width+1,'similarity button fits the now-playing area');
|
||||
for(const selector of ['.player-track-title','.player-current-like','.player-current-share']){
|
||||
const neighbor=await current.locator(selector).boundingBox();
|
||||
assert.ok(neighbor.x+neighbor.width<=button.x+1 || button.x+button.width<=neighbor.x+1,'similarity button does not overlap '+selector);
|
||||
}
|
||||
const actions=await row.locator('.track-actions').boundingBox(),info=await row.locator('.playlist-track-info').boundingBox(),rowBox=await row.boundingBox();
|
||||
assert.ok(actions.y>=rowBox.y&&actions.y+actions.height<=rowBox.y+rowBox.height+1,'actions stay inside row');
|
||||
near(actions.y+actions.height/2,info.y+info.height/2,'playlist actions share title row');
|
||||
@@ -56,6 +70,16 @@ const near=(a,b,message)=>assert.ok(Math.abs(a-b)<1,`${message}: ${a} vs ${b}`);
|
||||
const expandedButtons=await page.locator('.player-buttons').boundingBox();assert.ok(expandedButtons.x>=-1&&expandedButtons.x+expandedButtons.width<=viewport.width+1,`expanded transport buttons fit viewport: ${JSON.stringify({viewport,expandedButtons})}`);
|
||||
await page.screenshot({path:`target/player-layout-expanded-${viewport.width}.png`});
|
||||
}
|
||||
for(const seed of tracks.slice(0,2)){
|
||||
await page.evaluate(track=>{Alpine.store('player').currentTrack=track;},seed);
|
||||
await similar.click();
|
||||
await page.waitForURL('**/#similar/'+seed.id);
|
||||
await page.locator('.search-standard-entry').getByText(tracks[2].title,{exact:true}).first().waitFor();
|
||||
assert.equal(await page.evaluate(()=>Alpine.store('mobile').playerExpanded),false);
|
||||
assert.equal(await page.evaluate(()=>Alpine.store('player').currentTrack.id),seed.id);
|
||||
}
|
||||
await page.evaluate(()=>{Alpine.store('player').currentTrack={...Alpine.store('player').currentTrack,podcast:true};});
|
||||
await similar.waitFor({state:'hidden'});
|
||||
assert.deepEqual(errors,[]);await page.close();
|
||||
}
|
||||
console.log('Player layout checks passed at 1440, 900, 820, 575, 390 and 320 px.');
|
||||
|
||||
Reference in new issue
Block a user