Move Investigation into Writer ribbon without delayed visibility
This commit is contained in:
parent
288e2018af
commit
38c61546c0
62
PlotLine.Tests/Browser/investigation-ribbon.cjs
Normal file
62
PlotLine.Tests/Browser/investigation-ribbon.cjs
Normal file
@ -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; });
|
||||
@ -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');
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
@model ApplicationNavigationViewModel
|
||||
@inject PlotLine.Services.Investigations.InvestigationAccess InvestigationGate
|
||||
@{
|
||||
var project = Model.Project;
|
||||
var book = Model.Book;
|
||||
@ -127,7 +128,7 @@
|
||||
<button type="button" class="pd-ribbon-collapse" data-ribbon-collapse aria-expanded="@(!appearance.RibbonCollapsed ? "true" : "false")" aria-controls="ribbon-surface" title="Collapse or expand ribbon">@(appearance.RibbonCollapsed ? "Expand ribbon" : "Collapse ribbon") <span aria-hidden="true">⌃</span></button>
|
||||
</div>
|
||||
<div id="ribbon-surface" class="pd-ribbon-surface" hidden="@appearance.RibbonCollapsed">
|
||||
<div class="pd-ribbon-group pd-ribbon-history" role="group" aria-label="Navigation"><div class="pd-ribbon-commands"><button type="button" class="pd-ribbon-command pd-ribbon-back" data-app-back disabled aria-label="Back" title="Back to previous PlotDirector page"><svg class="pd-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="@ApplicationRibbon.Icon("back").IconPath" /></svg><span>Back</span></button><button type="button" class="pd-ribbon-command" data-guidance-open hidden><svg class="pd-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="@ApplicationRibbon.Icon("point").IconPath" /></svg><span>Investigation</span></button></div><span class="pd-ribbon-group-label">Navigation</span></div>
|
||||
<div class="pd-ribbon-group pd-ribbon-history" role="group" aria-label="Navigation"><div class="pd-ribbon-commands"><button type="button" class="pd-ribbon-command pd-ribbon-back" data-app-back disabled aria-label="Back" title="Back to previous PlotDirector page"><svg class="pd-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="@ApplicationRibbon.Icon("back").IconPath" /></svg><span>Back</span></button></div><span class="pd-ribbon-group-label">Navigation</span></div>
|
||||
@foreach (var category in ApplicationRibbon.Categories)
|
||||
{
|
||||
<div class="pd-ribbon-panel" id="ribbon-panel-@category.Key" role="tabpanel" aria-labelledby="ribbon-tab-@category.Key" hidden="@(category.Key != selectedCategory)">
|
||||
@ -159,6 +160,10 @@
|
||||
<svg viewBox="0 0 24 24" class="pd-icon" data-tone="@icon.Tone" aria-hidden="true" focusable="false"><path d="@icon.IconPath" /></svg><span>@command.Label @if (command.Controller == "FeatureRequests" && Model.FeatureRequestAttentionCount > 0) { <span class="badge text-bg-warning">@Model.FeatureRequestAttentionCount</span> }</span>
|
||||
</a>
|
||||
}
|
||||
@if (category.Key == "writer" && command.Action == "Reflect" && InvestigationGate.Enabled)
|
||||
{
|
||||
<a class="pd-ribbon-command" data-guidance-open href="@(book is not null ? Url.Action("Index", "WriterInvestigations", new { bookId = book.BookID }) : Url.Action("Index", "Writer", new { projectId = project?.ProjectID }))"><svg class="pd-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="@ApplicationRibbon.Icon("point").IconPath" /></svg><span>Investigation</span></a>
|
||||
}
|
||||
}
|
||||
@if(category.Key=="writer"&&group.Label=="Utilities"){
|
||||
<button type="button" class="pd-ribbon-command" data-writer-companion-toggle hidden aria-pressed="false"><svg class="pd-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="@ApplicationRibbon.Icon("threads").IconPath" /></svg><span>Companion</span></button><help-icon key="writer3.layout" />
|
||||
|
||||
@ -9,12 +9,11 @@
|
||||
const pendingKey=`plotdirector.guidance.open.${root.dataset.user}`;
|
||||
const readPanel=name=>{const v=read();if(name==='pinned')return String(v.pinned!==false);if(name==='width')return String(v.panelWidth||(typeof v.width==='number'?v.width/Math.max(1,layout.clientWidth)*100:25));if(name==='closed')return String(v.closed===true);return String(v[name]??false);};
|
||||
const panel=PlotDirectorContextPanels.create(root,{read:readPanel,write:(name,value)=>{const v=read();v[name==='width'?'panelWidth':name]=name==='width'?parseFloat(value):value==='true';try{localStorage.setItem(storageKey(),JSON.stringify(v));}catch{}preference=v;},changed:({state,pinned})=>{root.dataset.collapsed=String(state==='collapsed');document.querySelector('[data-guidance-open]')?.setAttribute('aria-expanded',String(state==='open'));}});
|
||||
document.querySelector('[data-guidance-open]')?.addEventListener('click',()=>{if(current)panel.open();});
|
||||
document.querySelector('[data-guidance-open]')?.addEventListener('click',event=>{if(current){event.preventDefault();panel.open();}});
|
||||
const save=()=>{try{localStorage.setItem(storageKey(),JSON.stringify(preference));}catch{}};
|
||||
const element=(tag,text,cls)=>{const n=document.createElement(tag);if(text!=null)n.textContent=text;if(cls)n.className=cls;return n;};
|
||||
const btn=(text,fn)=>{const n=element('button',text,'btn btn-outline-secondary btn-sm');n.type='button';n.addEventListener('click',fn);return n;};
|
||||
function restorePanel(restore=true){
|
||||
const opener=document.querySelector('[data-guidance-open]');if(opener)opener.hidden=!current;
|
||||
if(!current){panel.hide();return;}
|
||||
let pending;try{pending=sessionStorage.getItem(pendingKey);}catch{}
|
||||
if(pending===current.id){try{sessionStorage.removeItem(pendingKey);}catch{}panel.restore();panel.open();}else if(restore)panel.restore();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user