fix portrait PWA nav dead while playing by making body the scroll container

This commit is contained in:
Jonathan Sykes
2026-07-10 13:55:31 +08:00
parent b72c079fb4
commit 88c89d66af
3 changed files with 137 additions and 27 deletions

View File

@@ -29,6 +29,7 @@ async function enablePortraitPwaMode(page) {
content: `
/* Mirror (display-mode:standalone) and (orientation:portrait) rules for testing */
[data-portrait-pwa-test] .app { grid-template-columns: 1fr; }
[data-portrait-pwa-test] .bottom-nav { display: flex; }
[data-portrait-pwa-test] .sidebar-toggle { display: inline-flex; }
[data-portrait-pwa-test] .sidebar {
position: fixed; top:0; left:0; bottom:0;
@@ -39,16 +40,20 @@ async function enablePortraitPwaMode(page) {
[data-portrait-pwa-test] .app.sidebar-open .sidebar { transform:translateX(0); }
[data-portrait-pwa-test] .app.sidebar-open .sidebar-backdrop { display:block; opacity:1; }
[data-portrait-pwa-test] .topbar { position:sticky; top:0; z-index:50; }
[data-portrait-pwa-test] .body { flex-direction:column; overflow:hidden; }
[data-portrait-pwa-test] .body {
flex-direction:column;
overflow-y:auto; overflow-x:hidden;
overscroll-behavior:contain;
}
[data-portrait-pwa-test] .player-pane { flex:none; width:100%; overflow-y:visible; }
[data-portrait-pwa-test] .player-stage { width:100%; aspect-ratio:16/9; }
[data-portrait-pwa-test] .btn-row { flex-wrap:wrap; gap:7px; }
[data-portrait-pwa-test] .now-meta { flex-direction:column; gap:12px; margin-top:14px; }
[data-portrait-pwa-test] .np-actions { flex-wrap:wrap; gap:6px; }
[data-portrait-pwa-test] .list-pane {
flex:1; min-height:0; width:100%;
flex:none; min-height:100%; width:100%;
border-left:none; border-top:1px solid var(--line-soft);
overflow-y:auto; overflow-x:hidden;
overflow-y:visible; overflow-x:hidden;
padding-bottom: 60px;
}
[data-portrait-pwa-test] .cards { max-height:none; overflow-y:visible; padding-bottom:0; }
@@ -63,9 +68,33 @@ async function enablePortraitPwaMode(page) {
});
}
/**
* Playwright cannot set display-mode:standalone, so isPortraitPWA() in app.js
* would return false and the JS scroll behaviors (scrollListIntoViewPortrait,
* scrollPlayerIntoViewPortrait) would no-op. Stub matchMedia for that one
* query BEFORE app.js loads so the JS layer behaves as in the installed PWA.
*/
async function stubStandalonePortraitMediaQuery(page) {
await page.addInitScript(() => {
const orig = window.matchMedia.bind(window);
window.matchMedia = (q) => {
if (q.includes('display-mode: standalone') && q.includes('portrait')) {
return {
matches: true, media: q, onchange: null,
addEventListener: () => {}, removeEventListener: () => {},
addListener: () => {}, removeListener: () => {},
dispatchEvent: () => false,
};
}
return orig(q);
};
});
}
test.describe('Portrait PWA layout', () => {
test.beforeEach(async ({ page }) => {
await page.setViewportSize({ width: PORTRAIT_WIDTH, height: PORTRAIT_HEIGHT });
await stubStandalonePortraitMediaQuery(page);
await page.goto('/');
// Wait for app JS to initialise
await page.waitForSelector('.app', { state: 'attached' });
@@ -119,6 +148,53 @@ test.describe('Portrait PWA layout', () => {
await expect(lastGroup).toBeVisible();
});
test('navigation works while a track is playing (player pane taller than viewport)', async ({ page }) => {
// Simulate the DOM state afterLoad() creates for a playing track: player
// pane populated with controls, meta, up-next and related — together
// taller than the viewport. This used to leave the list-pane below the
// fold with .body overflow:hidden, so every nav tap looked dead.
await page.evaluate(() => {
document.getElementById('playerPane').classList.remove('empty');
document.getElementById('playerPlaceholder').classList.add('hidden');
document.getElementById('controls').classList.remove('hidden');
document.getElementById('nowPlayingMeta').classList.remove('hidden');
document.getElementById('npTitle').textContent = 'Test track';
document.getElementById('upnext').classList.remove('hidden');
document.getElementById('upnextList').innerHTML =
'<div class="upnext-item">queued</div>'.repeat(4);
document.getElementById('relatedPanel').classList.remove('hidden');
document.getElementById('relatedList').innerHTML =
'<div class="related-item">related</div>'.repeat(6);
document.getElementById('miniBar').classList.remove('hidden');
});
// Sanity: the populated player pane really is taller than the viewport.
const paneHeight = await page.evaluate(
() => document.getElementById('playerPane').getBoundingClientRect().height
);
expect(paneHeight).toBeGreaterThan(PORTRAIT_HEIGHT);
// Navigate via the bottom nav.
await page.click('.bottom-nav-btn[data-view="history"]');
await page.waitForTimeout(700); // smooth scroll settle
// The view switched AND its pane is actually on-screen.
await expect(page.locator('#listTitle')).toHaveText('History');
const box = await page.locator('.list-pane').boundingBox();
expect(box).not.toBeNull();
expect(box.y).toBeLessThan(PORTRAIT_HEIGHT / 2); // top of the page is visible
expect(box.y + box.height).toBeGreaterThan(200); // and it has visible extent
// Sidebar navigation must work the same way.
await page.click('#sidebarToggle');
await page.waitForTimeout(350);
await page.click('.nav-item[data-view="saved"]');
await page.waitForTimeout(700);
await expect(page.locator('#listTitle')).toHaveText('Saved videos');
const box2 = await page.locator('.list-pane').boundingBox();
expect(box2.y).toBeLessThan(PORTRAIT_HEIGHT / 2);
});
test('switching landscape to portrait restores layout', async ({ page }) => {
// Start in landscape
await page.setViewportSize({ width: LANDSCAPE_WIDTH, height: LANDSCAPE_HEIGHT });