From 38c61546c09710718e0ca3dc9fa094147f05685b Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Thu, 19 Nov 2026 22:04:13 +0000 Subject: [PATCH] Move Investigation into Writer ribbon without delayed visibility --- .../Browser/investigation-ribbon.cjs | 62 +++++++++++++++++++ PlotLine.Tests/Browser/writer3-navigation.cjs | 2 +- .../Views/Shared/_ApplicationShell.cshtml | 7 ++- .../wwwroot/js/investigation-companion.js | 3 +- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 PlotLine.Tests/Browser/investigation-ribbon.cjs diff --git a/PlotLine.Tests/Browser/investigation-ribbon.cjs b/PlotLine.Tests/Browser/investigation-ribbon.cjs new file mode 100644 index 00000000..fc4e5c42 --- /dev/null +++ b/PlotLine.Tests/Browser/investigation-ribbon.cjs @@ -0,0 +1,62 @@ +// Real Razor shell; hold the companion response to verify stable initial ribbon geometry. +const { chromium } = require('playwright'); +const assert = require('node:assert/strict'); +const base = process.env.PD_RIBBON_BASE || 'http://127.0.0.1:5238'; +(async () => { + const browser = await chromium.launch(); + try { + for (const pwa of [false, true]) { + const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } }); + if (pwa) await context.addInitScript(() => Object.defineProperty(navigator, 'standalone', { value: true })); + let release, arrived; + const pending = new Promise(resolve => { release = resolve; }); + const requested = new Promise(resolve => { arrived = resolve; }); + await context.route('**/InvestigationCompanion/Summary?*', async route => { + arrived(); await pending; + await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ active: false }) }); + }); + const page = await context.newPage(); + const url = `${base}/Writer?projectId=7&bookId=12`; + await page.goto(url, { waitUntil: 'domcontentloaded' }); + await requested; + const opener = page.locator('[data-guidance-open]'); + assert.equal(await opener.count(), 1); + assert(await opener.isVisible()); + assert.equal(await opener.evaluate(n => n.previousElementSibling.textContent.trim()), 'Reflect'); + assert.equal(await opener.evaluate(n => n.closest('[role=tabpanel]').id), 'ribbon-panel-writer'); + const geometry = () => page.locator('#ribbon-panel-writer .pd-ribbon-command').evaluateAll(ns => ns.map(n => { + const r = n.getBoundingClientRect(); return [r.x, r.y, r.width, r.height]; + })); + const before = await geometry(); + release(); + await page.waitForFunction(() => window.PlotDirectorGuidanceSummary); + assert.deepEqual(await geometry(), before, 'Summary response must not move ribbon commands'); + await page.reload({ waitUntil: 'networkidle' }); + assert(await opener.isVisible()); + for (const section of ['book', 'story', 'project', 'characters', 'world', 'tools']) { + await page.locator(`#ribbon-tab-${section}`).click(); + assert.equal(await opener.isVisible(), false, section); + assert.equal(await page.locator(`#ribbon-panel-${section} [data-guidance-open]`).count(), 0); + } + await page.locator('#ribbon-tab-writer').click(); + await page.waitForLoadState('networkidle'); + assert(await opener.isVisible()); + const target = await opener.getAttribute('href'); + assert(target.includes('/Writer/Explore/Investigate'), 'No active companion retains saved-investigation navigation'); + await context.unroute('**/InvestigationCompanion/Summary?*'); + await context.route('**/InvestigationCompanion/Summary?*', route => route.fulfill({ + contentType: 'application/json', body: JSON.stringify({ active: true, resultsUrl: target, + summary: { id: 'ribbon-fixture', bookID: 12, bookTitle: 'Test book', concern: 'Test concern', message: '', findings: [] } }) + })); + await page.evaluate(() => window.dispatchEvent(new Event('investigation-guidance-updated'))); + await page.waitForFunction(() => window.PlotDirectorGuidanceSummary?.summary?.id === 'ribbon-fixture'); + await page.locator('[data-guidance-close]').click(); + const priorUrl = page.url(); + await opener.click(); + assert.equal(page.url(), priorUrl, 'Active companion opens without navigation'); + assert.equal(await page.locator('[data-investigation-companion]').getAttribute('data-state'), 'open'); + console.log(`PASS Investigation initial render, delayed summary geometry, refresh and section switching (${pwa ? 'standalone PWA emulation' : 'browser'})`); + await context.close(); + } + } finally { await browser.close(); } +})().catch(e => { console.error(e); process.exitCode = 1; }); diff --git a/PlotLine.Tests/Browser/writer3-navigation.cjs b/PlotLine.Tests/Browser/writer3-navigation.cjs index a48d2f6a..47f4f953 100644 --- a/PlotLine.Tests/Browser/writer3-navigation.cjs +++ b/PlotLine.Tests/Browser/writer3-navigation.cjs @@ -19,7 +19,7 @@ const base='http://127.0.0.1:5238'; const kind=destination==='Index'?'Home':destination; assert.equal(await page.locator('[data-writer-destination]').getAttribute('data-writer-destination'),kind); const commands=page.locator('#ribbon-panel-writer [role=group]').first().locator('a'); - assert.deepEqual((await commands.locator('span:not([aria-hidden])').allTextContents()).map(x=>x.trim()),['Home','Write','Explore','Plan','Review','Reflect']); + assert.deepEqual((await commands.locator('span:not([aria-hidden])').allTextContents()).map(x=>x.trim()),['Home','Write','Explore','Plan','Review','Reflect','Investigation']); assert((await page.locator('#ribbon-panel-writer a[aria-current=page]').allTextContents()).some(t=>t.trim()===(destination==='Index'?'Home':destination==='Dashboard'?'Writing Dashboard':destination))); assert.equal(await page.locator('.writer3 nav:not(.reader-controls)').count(),0,'No duplicate destination navigation bar; canonical Reader chapter navigation is independent'); const contrasts=await page.locator('a.writer3-cta').evaluateAll(nodes=>{const lum=s=>{const rgb=s.match(/[\d.]+/g).slice(0,3).map(Number).map(x=>{x/=255;return x<=.04045?x/12.92:((x+.055)/1.055)**2.4});return rgb[0]*.2126+rgb[1]*.7152+rgb[2]*.0722};return nodes.map(n=>{const c=getComputedStyle(n),a=lum(c.color),b=lum(c.backgroundColor);return (Math.max(a,b)+.05)/(Math.min(a,b)+.05)})});assert(contrasts.every(x=>x>=4.5),'Primary action labels must have readable contrast'); diff --git a/PlotLine/Views/Shared/_ApplicationShell.cshtml b/PlotLine/Views/Shared/_ApplicationShell.cshtml index 0fccb66c..6970e3f0 100644 --- a/PlotLine/Views/Shared/_ApplicationShell.cshtml +++ b/PlotLine/Views/Shared/_ApplicationShell.cshtml @@ -1,4 +1,5 @@ @model ApplicationNavigationViewModel +@inject PlotLine.Services.Investigations.InvestigationAccess InvestigationGate @{ var project = Model.Project; var book = Model.Book; @@ -127,7 +128,7 @@