From 5a0eba4570f68c8c8acced931a9afacdd8981e22 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Fri, 20 Nov 2026 09:57:01 +0000 Subject: [PATCH] Separate Explore landing widths from investigation preferences --- PlotLine.Tests/Browser/explore-divider.cjs | 78 +++++++++++++++++-- .../WriterInvestigations/_Journey.cshtml | 2 +- PlotLine/wwwroot/js/writer-explore-layout.js | 28 ++++--- PlotLine/wwwroot/js/writer-explore.js | 6 +- 4 files changed, 95 insertions(+), 19 deletions(-) diff --git a/PlotLine.Tests/Browser/explore-divider.cjs b/PlotLine.Tests/Browser/explore-divider.cjs index f98ab20c..69c6843b 100644 --- a/PlotLine.Tests/Browser/explore-divider.cjs +++ b/PlotLine.Tests/Browser/explore-divider.cjs @@ -1,4 +1,5 @@ // Real compiled Explore/Journey Razor and investigation engine; isolated memory repositories. +// Start the fixture host with PD_INV_CATALOGUE=Docs/Writer/Investigations/production-catalogue-v0.1.json. // Run with --installed under xvfb-run for a real installed Chromium PWA. const {chromium} = require('playwright'); const assert = require('node:assert/strict'); @@ -10,7 +11,15 @@ const base='http://127.0.0.1:5238', url=base+'/Writer/Explore?projectId=7&bookId const context=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1666,height:1050}}):await(await chromium.launch()).newContext({viewport:{width:1666,height:1050}}); const browser=context.browser(), evidence='/tmp/pd-explore-divider-evidence/'+mode; fs.mkdirSync(evidence,{recursive:true}); - await context.addInitScript(()=>localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()}))); + await context.addInitScript(()=>{ + localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()})); + window.exploreInitialPaints=[]; + const set=CSSStyleDeclaration.prototype.setProperty; + CSSStyleDeclaration.prototype.setProperty=function(name,value,priority){ + if(name==='--explore-ratio')window.exploreInitialPaints.push(Number(value)); + return set.call(this,name,value,priority); + }; + }); await context.route('**/native-companion/status*',r=>r.fulfill({json:{leases:[]}})); await context.route('**/signalr.min.js',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(require.resolve('@microsoft/signalr/dist/browser/signalr.min.js'))})); try{ @@ -102,9 +111,59 @@ const base='http://127.0.0.1:5238', url=base+'/Writer/Explore?projectId=7&bookId await page.locator(`[data-explore-saved] a[href*="${id}"]`).click();await journey.locator('[data-inline-investigation]').waitFor();await page.waitForFunction(()=>!document.querySelector('[data-explore-investigation]').hasAttribute('aria-busy')); close(await ratio(),preferred); await page.reload();await journey.locator('[data-inline-investigation]').waitFor();close(await ratio(),preferred); - await journey.getByRole('link',{name:'Return to Explore',exact:true}).click();await journey.locator('[data-inline-investigation]').waitFor();close(await ratio(),preferred); - await journey.getByRole('link',{name:'Start another investigation',exact:true}).click();await ready();close(await ratio(),preferred); - await begin();await idle();close(await ratio(),preferred); + assert.equal(await layout.getAttribute('data-explore-state'),'investigation'); + assert((await page.evaluate(()=>window.exploreInitialPaints)).every(v=>Math.abs(v-.4)<.005),'Active refresh restores preference directly, without painting 50 percent'); + const storage=()=>page.evaluate(()=>JSON.parse(localStorage.getItem(Object.keys(localStorage).find(k=>k.startsWith('plotdirector.writerExploreLayout.')))).leftRatio); + const settled=()=>page.waitForFunction(()=>!document.querySelector('[data-explore-investigation]').hasAttribute('aria-busy')); + const scriptedBegin=()=>journey.getByRole('button',{name:'Begin',exact:true}).evaluate(n=>{n.form.querySelector('[name=concern]').checked=true;n.form.requestSubmit(n);}); + async function movement(name,from,to,action){ + await settled();close(await ratio(),from); + await page.evaluate(()=>{window.scrollTo({top:0,behavior:'instant'});return new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r)));}); + const mounted=await layout.elementHandle(),nav=navigations; + await page.screenshot({path:`${evidence}/${name}-initial.png`}); + await page.evaluate(()=>{ + window.stateFrames=[];window.stateSampling=true; + function tick(t){const w=document.querySelector('[data-explore-layout]'),b=w.querySelector('[data-explore-divider]').getBoundingClientRect(),r=document.querySelector('[data-ribbon-shell]').getBoundingClientRect(); + window.stateFrames.push({t,ratio:Number(w.style.getPropertyValue('--explore-ratio')),divider:b.x,ribbon:[r.x,r.y,r.width,r.height]}); + if(window.stateSampling)requestAnimationFrame(tick); + }requestAnimationFrame(tick); + }); + await action(); + await page.waitForFunction(()=>document.querySelector('[data-explore-layout]').hasAttribute('data-resize-animating')); + const shot=await screenshotSession.send('Page.captureScreenshot',{format:'png',captureBeyondViewport:false}); + fs.writeFileSync(`${evidence}/${name}-intermediate.png`,Buffer.from(shot.data,'base64')); + await idle();await settled();await page.evaluate(()=>new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r)))); + await page.evaluate(()=>window.stateSampling=false); + const samples=await page.evaluate(()=>window.stateFrames),lo=Math.min(from,to),hi=Math.max(from,to); + assert(samples.filter(f=>f.ratio>lo+.005&&f.ratio=4,`${name}: visible intermediate widths`); + assert(new Set(samples.map(f=>Math.round(f.divider))).size>=5,`${name}: divider actually moves`); + for(const f of samples)assert.deepEqual(f.ribbon,samples[0].ribbon,`${name}: stationary ribbon`); + close(await ratio(),to);close(await storage(),.4); + assert.equal(navigations,nav,`${name}: no document reload`); + assert(await mounted.evaluate(n=>n.isConnected),`${name}: workspace remains mounted`); + fs.writeFileSync(`${evidence}/${name}-frames.json`,JSON.stringify(samples,null,2)); + await page.screenshot({path:`${evidence}/${name}-final.png`}); + } + await movement('return-preferred',.4,.5,()=>journey.getByRole('link',{name:'Return to Explore',exact:true}).evaluate(n=>n.click())); + await ready();assert.equal(new URL(page.url()).searchParams.has('investigation'),false); + assert.equal(await layout.getAttribute('data-explore-state'),'landing'); + // A landing adjustment must not change the saved investigation width, including on keyboard adjustment. + await dragTo(.6);await divider.focus();await divider.press('ArrowLeft');close(await storage(),.4); + await page.evaluate(()=>window.dispatchEvent(new PageTransitionEvent('pageshow',{persisted:true})));close(await ratio(),.5);close(await storage(),.4); + await dragTo(.6);await page.reload();await ready();close(await ratio(),.5); + assert((await page.evaluate(()=>window.exploreInitialPaints)).every(v=>v===.5),'Saved 40:60 never paints on landing refresh'); + await movement('begin-preferred',.5,.4,scriptedBegin); + await journey.locator('[data-inline-investigation]').waitFor(); + // A full-document navigation to plain Explore must land at 50:50 even with an active session-storage entry. + await settled();await page.goto(`${base}/Writer/Explore/Investigate?bookId=12&id=${id}`); + assert.equal(await layout.count(),0,'Standalone investigation has no mounted Explore workspace'); + await page.getByRole('link',{name:'Return to Explore',exact:true}).click();await ready();close(await ratio(),.5); + assert((await page.evaluate(()=>window.exploreInitialPaints)).every(v=>v===.5),'Plain Explore does not resurrect the active session or its width'); + await page.getByRole('tab',{name:'Saved investigations',exact:true}).click(); + await page.locator(`[data-explore-saved] a[href*="${id}"]`).waitFor(); + await movement('resume-preferred',.5,.4,()=>page.locator(`[data-explore-saved] a[href*="${id}"]`).evaluate(n=>n.click())); + await movement('new-investigation-landing',.4,.5,()=>journey.getByRole('link',{name:'Start another investigation',exact:true}).evaluate(n=>n.click())); + await ready();await movement('begin-another',.5,.4,scriptedBegin); // Pointer cancellation and lost capture leave no stuck drag or selection suppression. let b=await divider.boundingBox();await page.mouse.move(b.x+b.width/2,b.y+60);await page.mouse.down(); await divider.evaluate(n=>n.dispatchEvent(new PointerEvent('pointercancel',{pointerId:1})));await page.mouse.up(); @@ -120,11 +179,20 @@ const base='http://127.0.0.1:5238', url=base+'/Writer/Explore?projectId=7&bookId } await page.setViewportSize({width:1666,height:1050}); await page.emulateMedia({reducedMotion:'reduce'}); + await journey.getByRole('link',{name:'Return to Explore',exact:true}).evaluate(n=>n.click());await ready();await settled();close(await ratio(),.5); + assert.equal(await layout.getAttribute('data-resize-animating'),null); + await scriptedBegin();await settled();close(await ratio(),.4); + assert.equal(await layout.getAttribute('data-resize-animating'),null); await page.evaluate(()=>{for(const key of Object.keys(localStorage))if(key.startsWith('plotdirector.writerExploreLayout.'))localStorage.removeItem(key);}); await page.goto(url+'#new-investigation');await ready();close(await ratio(),.5); await begin();await idle();close(await ratio(),.25); assert.equal(await layout.getAttribute('data-resize-animating'),null); + assert.equal(new URL(page.url()).hash,'','Begin clears the landing-only hash for reliable active refresh'); + await page.reload();await journey.locator('[data-inline-investigation]').waitFor();close(await ratio(),.25); + assert((await page.evaluate(()=>window.exploreInitialPaints)).every(v=>v===.25),'Unpreferred active refresh paints 25 directly'); + await journey.getByRole('link',{name:'Return to Explore',exact:true}).evaluate(n=>n.click());await ready();await settled();close(await ratio(),.5); + assert.equal(await layout.getAttribute('data-resize-animating'),null); assert.deepEqual(errors,[]); - console.log(`PASS ${mode}: real Begin/answer/revision/save/resume/return/new; stable panels and chrome, intermediate animation frames, no default preference writes, pointer/keyboard/minimums/persistence, six widths/two themes, reduced motion.`); + console.log(`PASS ${mode}: landing always 50:50; real forward/reverse/resume glides with saved 40:60, direct landing/active refresh, temporary landing drag, unchanged question widths, real save/revision lifecycle, pointer/keyboard/minimums, six widths/two themes, reduced motion.`); }finally{await context.close();await browser.close();if(profile)fs.rmSync(profile,{recursive:true,force:true});} })().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine/Views/WriterInvestigations/_Journey.cshtml b/PlotLine/Views/WriterInvestigations/_Journey.cshtml index 4f15662d..be4d7936 100644 --- a/PlotLine/Views/WriterInvestigations/_Journey.cshtml +++ b/PlotLine/Views/WriterInvestigations/_Journey.cshtml @@ -63,7 +63,7 @@ } @if(row!=null){
} -

Return to Explore · Start another investigation

+

Return to Explore · Start another investigation