diff --git a/PlotLine.Tests/Browser/sticky-shell.cjs b/PlotLine.Tests/Browser/sticky-shell.cjs new file mode 100644 index 00000000..636df61c --- /dev/null +++ b/PlotLine.Tests/Browser/sticky-shell.cjs @@ -0,0 +1,70 @@ +// Start the toolbar browser fixture, then: xvfb-run -a node sticky-shell.cjs +const { chromium } = require('playwright'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +async function checkScroll(page, installed) { + await page.evaluate(() => { + const main = document.querySelector('main'); + const spacer = document.createElement('div'); spacer.style.height = '1800px'; + const target = document.createElement('button'); target.id = 'scroll-test-target'; target.textContent = 'Focus target'; + main.append(spacer, target, spacer.cloneNode()); + }); + await page.evaluate(() => window.scrollTo(0, 650)); + await page.waitForFunction(() => scrollY > 600); + const header = page.locator('.pd-application-header'); + if (!installed) { assert((await header.boundingBox()).y < -400); return; } + assert(Math.abs((await header.boundingBox()).y) < 1); + const expanded = (await header.boundingBox()).height; + await page.locator('[data-ribbon-collapse]').click(); + await page.waitForFunction(() => !document.querySelector('[data-ribbon-collapse]').disabled); + const compact = (await header.boundingBox()).height; + assert(compact < expanded - 50); + assert(Math.abs((await header.boundingBox()).y) < 1); + await page.locator('[data-ribbon-tab=story]').click(); + assert((await header.boundingBox()).height > compact + 50); + await page.evaluate(() => document.getElementById('scroll-test-target').scrollIntoView()); + await page.waitForFunction(() => document.querySelector('#scroll-test-target').getBoundingClientRect().top >= document.querySelector('.pd-application-header').getBoundingClientRect().bottom); + for (const id of ['appProjectMenu', 'appBookMenu', 'accountMenuButton']) { + await page.locator('#' + id).click(); + const menu = page.locator(`[aria-labelledby="${id}"]`); + assert(await menu.isVisible()); + assert(await menu.evaluate(el => { const r = el.getBoundingClientRect(); return el.contains(document.elementFromPoint(r.x + 15, r.y + 15)); })); + await page.keyboard.press('Escape'); + } + await page.locator('.app-toolbar-customise').click(); + await page.waitForFunction(() => document.activeElement.closest('#customiseToolbar')); + assert.equal(await page.locator('#customiseToolbar').evaluate(el => el.parentElement.tagName), 'BODY'); + assert(await page.locator('#customiseToolbar .modal-content').evaluate(el => { const r=el.getBoundingClientRect(); return el.contains(document.elementFromPoint(r.x+25,r.y+25)); })); + await page.locator('#customiseToolbar .modal-footer').getByRole('button',{name:'Cancel',exact:true}).click(); + await page.locator('#customiseToolbar').waitFor({state:'hidden'}); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true); +} +module.exports = { checkScroll }; +if (require.main === module) (async () => { + const profile = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-sticky-')); + const context = await chromium.launchPersistentContext(profile, { headless: false, viewport: {width:1440,height:900} }); + const base = 'http://127.0.0.1:5238', manifestId = base + '/Projects'; + const cdp = await context.browser().newBrowserCDPSession(); + try { + const tab = context.pages()[0]; await tab.goto(base + '/fixture?dashboard=true'); + await checkScroll(tab, false); + await cdp.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/fixture'}); + await cdp.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'}); + const opened = context.waitForEvent('page'); + await cdp.send('PWA.launch',{manifestId,url:base+'/fixture?dashboard=true'}); + const app = await opened; await app.waitForLoadState(); + assert(await app.evaluate(()=>matchMedia('(display-mode: standalone)').matches)); + for (const theme of ['modern-light','modern-dark','warm-light','warm-dark']) { + await app.goto(base + '/fixture?dashboard=true'); + await app.evaluate(theme => document.documentElement.dataset.appTheme=theme,theme); + if (await app.locator('#ribbon-surface').isHidden()) { + await app.locator('[data-ribbon-collapse]').click(); + await app.waitForFunction(()=>!document.querySelector('[data-ribbon-collapse]').disabled); + } + await checkScroll(app,true); + } + console.log('PASS sticky shell: real installed mode vs browser tab; all themes, expanded/collapsed height, scrolled categories, anchor offset, dropdown hit testing and modal/backdrop stacking.'); + } finally { await cdp.send('PWA.uninstall',{manifestId}).catch(()=>{}); await context.close(); fs.rmSync(profile,{recursive:true,force:true}); } +})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine.Tests/ToolbarBrowserHost.cs b/PlotLine.Tests/ToolbarBrowserHost.cs index 4914b8d6..b35d6066 100644 --- a/PlotLine.Tests/ToolbarBrowserHost.cs +++ b/PlotLine.Tests/ToolbarBrowserHost.cs @@ -41,6 +41,7 @@ internal static class ToolbarBrowserHost app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); + app.MapGet("/Projects", () => Results.Redirect("/fixture")); app.MapGet("/fixture", async context => { var model = new ApplicationNavigationViewModel { ActiveSection = "Calendar", ShowCompanionPresence = true }; @@ -92,7 +93,7 @@ internal static class ToolbarBrowserHost var initialTheme = appearance.ThemeKey ?? "warm-light"; var appearanceScript = ""; context.Response.ContentType = "text/html; charset=utf-8"; - await context.Response.WriteAsync("