From ff6369e9766b37fba38b9c327c0c170076236870 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Wed, 25 Nov 2026 20:45:27 +0000 Subject: [PATCH] Fix manuscript import surfaces and continuation banner across themes --- .../Browser/manuscript-import-theme.cjs | 84 +++++ PlotLine/Views/Shared/_Layout.cshtml | 2 +- PlotLine/wwwroot/css/onboarding.css | 300 +++++++++--------- .../story-intelligence-global-progress.css | 11 +- 4 files changed, 242 insertions(+), 155 deletions(-) create mode 100644 PlotLine.Tests/Browser/manuscript-import-theme.cjs diff --git a/PlotLine.Tests/Browser/manuscript-import-theme.cjs b/PlotLine.Tests/Browser/manuscript-import-theme.cjs new file mode 100644 index 00000000..de73434a --- /dev/null +++ b/PlotLine.Tests/Browser/manuscript-import-theme.cjs @@ -0,0 +1,84 @@ +// Render real component markup with synthetic model values; never starts an import. +// node PlotLine.Tests/Browser/manuscript-import-theme.cjs +// PD_THEME_RAZOR=http://127.0.0.1:5238 uses the compiled Razor fixture host. +// PD_THEME_BEFORE=/absolute/original-css captures and compares the pre-change styles. +const {chromium}=require('playwright'); +const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict'); +const root=path.resolve(__dirname,'../../PlotLine'); +const read=p=>fs.readFileSync(path.join(root, /^(css|js|lib)\//.test(p)?'wwwroot':'',p),'utf8'); +const output=process.env.PD_THEME_SCREENSHOTS || '/tmp/pd-manuscript-import-theme'; +fs.mkdirSync(output,{recursive:true}); +const view=read('Views/Onboarding/Index.cshtml'); +const details=view.match(/
[\s\S]*?<\/dl>/)[0] + .replace(/@\(Model.CompanionPresence.CompanionVersion[^\n]+/,'Waiting') + .replace(/@\(Model.CompanionPresence.CurrentDocumentName[^\n]+/,'No document reported yet'); +const counts=view.match(/
[\s\S]*?<\/section>/)[0].replace(/<\/section>$/,'') + .replace(/@Model.ScanState.TotalWordCount.ToString\("N0"\)/g,'0').replace(/@Model.ScanState.\w+/g,'0'); +const layout=read('Views/Shared/_Layout.cshtml'); +let banner=layout.slice(layout.indexOf(''; +const html=`${banner}

Scan Manuscript

Open your manuscript in Word and start the Companion.

Word Companion

Waiting for Word Companion...

Open your manuscript in Word.

${details}
Ready to scan
${counts}
`; +const baseStyles=['lib/bootstrap/dist/css/bootstrap.min.css','css/site.css','css/plotline-theme.css']; +const components=['onboarding.css','story-intelligence-global-progress.css']; +(async()=>{const browser=await chromium.launch();try{ + const page=await browser.newPage({viewport:{width:1440,height:1000}}); + let renderedHtml=html; + if(process.env.PD_THEME_RAZOR){ + const response=await page.goto(process.env.PD_THEME_RAZOR+'/fixture?desktop=ManuscriptImport'); + assert.equal(response.status(),200); + renderedHtml=banner+await page.locator('.onboarding-shell').evaluate(el=>el.outerHTML); + } + const errors=[];page.on('pageerror',e=>errors.push(e.message)); + async function render(before,theme){ + await page.goto('about:blank');await page.setContent(`${before?renderedHtml.replace('btn-outline-primary btn-sm" data-story-intelligence-global-action','btn-outline-secondary btn-sm" data-story-intelligence-global-action'):renderedHtml}`); + for(const p of baseStyles)await page.addStyleTag({content:read(p)}); + for(const p of components)await page.addStyleTag({content:before?fs.readFileSync(path.join(process.env.PD_THEME_BEFORE,p),'utf8'):read('css/'+p)}); + await page.addStyleTag({content:read('css/application-shell.css')}); + await page.waitForTimeout(300); + } + async function capture(name){await page.locator('.story-intelligence-global-strip').screenshot({path:path.join(output,name+'-banner.png')});await page.locator('.onboarding-panel').screenshot({path:path.join(output,name+'-scan.png')});} + async function inspect(){return page.evaluate(()=>{ + const canvas=document.createElement('canvas');canvas.width=canvas.height=1;const ctx=canvas.getContext('2d'); + function pixel(color){ctx.clearRect(0,0,1,1);ctx.fillStyle=color;ctx.fillRect(0,0,1,1);return [...ctx.getImageData(0,0,1,1).data];} + function background(el){if(!el)return [255,255,255];const b=background(el.parentElement),c=pixel(getComputedStyle(el).backgroundColor),a=c[3]/255;return c.slice(0,3).map((v,i)=>v*a+b[i]*(1-a));} + function lum(c){return c.map(v=>v/255).map(v=>v<=.04045?v/12.92:((v+.055)/1.055)**2.4).reduce((s,v,i)=>s+v*[.2126,.7152,.0722][i],0);} + return [...document.querySelectorAll('.onboarding-companion-details dt,.onboarding-companion-details dd,.onboarding-scan-counts span,.onboarding-scan-counts strong,.story-intelligence-global-strip__copy strong,[data-story-intelligence-global-detail],[data-story-intelligence-global-action]')].map(el=>{const fg=lum(pixel(getComputedStyle(el).color).slice(0,3)),bg=lum(background(el));return {text:el.textContent.trim(),ratio:(Math.max(fg,bg)+.05)/(Math.min(fg,bg)+.05)};}); + });} + let originalMobileWidth,originalGeometry; + async function geometry(){return Promise.all(['.story-intelligence-global-strip','.onboarding-panel','.onboarding-companion-details','.onboarding-scan-counts'].map(selector=>page.locator(selector).boundingBox()));} + if(process.env.PD_THEME_BEFORE){ + await render(true,'warm-dark');await capture('before-dark');originalGeometry=await geometry(); + await page.setViewportSize({width:390,height:1000});originalMobileWidth=await page.evaluate(()=>document.documentElement.scrollWidth); + await page.setViewportSize({width:1440,height:1000}); + } + for(const theme of ['plotdirector','warm-light','warm-dark','modern-light','modern-dark','rose-light','blue-light']){ + await render(false,theme); + if(theme==='warm-dark'||theme==='warm-light')await capture('after-'+theme); + if(theme==='warm-dark'&&originalGeometry)assert.deepEqual(await geometry(),originalGeometry,'Colour changes preserve original component geometry'); + await page.evaluate(()=>{window.handlers={};window.signalR={HubConnectionBuilder:class{withUrl(){return this}withAutomaticReconnect(){return this}build(){return{state:'Connected',on(n,f){handlers[n]=f},onreconnected(){},onreconnecting(){},onclose(){},start:async()=>{},invoke:async()=>({status:'NotStarted',isConnected:false})}}}};}); + await page.addScriptTag({content:read('js/word-companion-presence.js')}); + await page.waitForFunction(()=>!!handlers.WordCompanionPresenceChanged); + for(const state of ['waiting','disconnected','connected','populated','failed']){ + await page.evaluate(state=>{ + if(state!=='waiting')handlers.WordCompanionPresenceChanged({isConnected:state==='connected'||state==='populated',documentOpen:true,companionVersion:'1.0.0.18',currentDocumentName:'Theme verification.docx'}); + if(state==='populated'||state==='failed')handlers.OnboardingScanStateChanged({status:state==='failed'?'Failed':'Complete',chapterCount:12,sceneCount:48,characterCandidateCount:17,totalWordCount:82500,percentComplete:100}); + },state); + for(const c of await inspect())assert(c.ratio>=4.5,`${theme}/${state}: ${c.text} contrast ${c.ratio.toFixed(2)}`); + if(state==='populated'&&(theme==='warm-dark'||theme==='warm-light'))await capture('populated-'+theme); + } + const dimensions=await page.locator('.onboarding-scan-counts').boundingBox(); + await page.evaluate(()=>{const h=document.documentElement;h.dataset.appTheme='warm-dark';h.dataset.theme=h.dataset.bsTheme='dark';}); + await page.waitForTimeout(300); + for(const c of await inspect())assert(c.ratio>=4.5,`switched theme: ${c.text} ${c.ratio}`); + assert.deepEqual(await page.locator('.onboarding-scan-counts').boundingBox(),dimensions,'Theme switch preserves metric geometry'); + await page.setViewportSize({width:390,height:1000}); + if(originalMobileWidth)assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth),originalMobileWidth,'Preserve original mobile geometry'); + await page.setViewportSize({width:1440,height:1000}); + } + assert.deepEqual(errors,[]);console.log('PASS import components: seven themes, waiting/disconnected/connected/populated/failed states, real presence updates, contrast >=4.5, live theme switching, unchanged desktop/mobile geometry. Screenshots: '+output); +}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine/Views/Shared/_Layout.cshtml b/PlotLine/Views/Shared/_Layout.cshtml index fce28734..d174a8db 100644 --- a/PlotLine/Views/Shared/_Layout.cshtml +++ b/PlotLine/Views/Shared/_Layout.cshtml @@ -237,7 +237,7 @@ - Book + Book