From 350b2aa500a91b988e7fdaa0ae3644ed4dcf7cf4 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Mon, 2 Nov 2026 23:55:20 +0000 Subject: [PATCH] Dispose replaced Floor Plans help controls and verify repeated help lifecycles --- .../Browser/floor-plans-help-lifecycle.cjs | 25 +++++++++++++++++++ PlotLine/Views/FloorPlans/Edit.cshtml | 1 + PlotLine/wwwroot/js/site.js | 11 +++++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 PlotLine.Tests/Browser/floor-plans-help-lifecycle.cjs diff --git a/PlotLine.Tests/Browser/floor-plans-help-lifecycle.cjs b/PlotLine.Tests/Browser/floor-plans-help-lifecycle.cjs new file mode 100644 index 00000000..de73ba6d --- /dev/null +++ b/PlotLine.Tests/Browser/floor-plans-help-lifecycle.cjs @@ -0,0 +1,25 @@ +// Verifies real Bootstrap resources across repeated live Development workspace replacement. +const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'); +const [identityPath,fixturePath]=process.argv.slice(2); +if(![identityPath,fixturePath].every(p=>p?.startsWith('/tmp/pd-dev-browser-')))throw Error('Dedicated Development identity and fixture required.'); +const identity=JSON.parse(fs.readFileSync(identityPath)),fixture=JSON.parse(fs.readFileSync(fixturePath)),base='https://dev.plotdirector.com'; +if(identity.Database!=='PlotDirector_Development'||!identity.Email.startsWith('pwa-browser-'))throw Error('Development identity required.'); +(async()=>{const browser=await chromium.launch();try{ + const login=await browser.newContext(),page=await login.newPage();await page.goto(base+'/Account/Login');await page.locator('#Email').fill(identity.Email);await page.locator('#Password').fill(identity.Password);await Promise.all([page.waitForURL('**/Projects'),page.locator('form[action="/Account/Login"] button[type=submit]').click()]); + for(const pwa of [false,true]){ + const context=await browser.newContext({storageState:await login.storageState(),viewport:{width:1600,height:1000}});if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true})); + const p=await context.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));await p.goto(`${base}/FloorPlans/Edit/${fixture.FloorPlanID}`); + for(let i=0;i<3;i++){ + await p.locator('[data-toolbox-tab=floors]').click(); + const old=await p.locator('[data-floor-plan-workspace]').elementHandle(),oldHelp=await p.locator('[data-floor-plan-workspace] [data-help-icon]').first().elementHandle(); + await p.locator('[name=Name][form=floor-plan-add-floor-form]').fill(`Help lifecycle ${pwa?'PWA':'web'} ${i}`); + await p.locator('[form=floor-plan-add-floor-form][type=submit]').click();await p.waitForFunction(n=>!n.isConnected,old); + await p.waitForFunction(()=>document.querySelector('[data-floor-plan-editor]')?.dataset.floorPlanInitialized==='true'); + assert(await oldHelp.evaluate(n=>!bootstrap.Popover.getInstance(n)&&!bootstrap.Tooltip.getInstance(n.querySelector('[data-help-tooltip]'))),'removed controls release Bootstrap instances'); + assert(await p.locator('[data-floor-plan-workspace] [data-help-icon]').evaluateAll(ns=>ns.every(n=>!!bootstrap.Popover.getInstance(n)))); + await p.locator('[data-toolbox-tab=add]').click();await p.locator('[data-toolbox-panel=add] [data-help-icon] button').first().click();await p.locator('.popover.show').waitFor();await p.locator('.popover.show .plotline-help-more').click();await p.locator('[data-help-content] .help-drawer-article').waitFor();await p.locator('[data-help-close]').click(); + } + assert.deepEqual(errors,[]);console.log(`PASS Development Help lifecycle ${pwa?'PWA':'web'}: three replacements release old Bootstrap instances; new Help and More/drawer work without refresh.`);await context.close(); + } + await login.close(); +}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine/Views/FloorPlans/Edit.cshtml b/PlotLine/Views/FloorPlans/Edit.cshtml index 816803ac..2faa1944 100644 --- a/PlotLine/Views/FloorPlans/Edit.cshtml +++ b/PlotLine/Views/FloorPlans/Edit.cshtml @@ -2572,6 +2572,7 @@ const onStoryPosition = event => applyStoryPosition(event.detail); document.addEventListener(storyPositionEvent, onStoryPosition); workspace.addEventListener("floor-plan-dispose", () => { + window.PlotLineHelpIcons?.dispose(workspace); document.removeEventListener(storyPositionEvent, onStoryPosition); window.clearTimeout(saveTimer); backgroundTimers.forEach(timer => window.clearTimeout(timer)); diff --git a/PlotLine/wwwroot/js/site.js b/PlotLine/wwwroot/js/site.js index 043f5f95..f9bcbdb5 100644 --- a/PlotLine/wwwroot/js/site.js +++ b/PlotLine/wwwroot/js/site.js @@ -377,7 +377,16 @@ } }; window.PlotLineHelpIcons = { - init: initHelpIcons + init: initHelpIcons, + dispose(scope) { + helpIconsIn(scope).forEach((icon) => { + bootstrap.Tooltip.getInstance(tooltipElement(icon))?.dispose(); + bootstrap.Popover.getInstance(icon)?.dispose(); + popovers.delete(icon); + initializedIcons.delete(icon); + if (activeIcon === icon) activeIcon = null; + }); + } }; initHelpIcons(); })();