Use shared ribbon tab selection and expansion for Writer

This commit is contained in:
Nick Beckley 2026-11-20 16:25:58 +00:00
parent a209f35610
commit f6850d5f7a
7 changed files with 54 additions and 16 deletions

View File

@ -7,7 +7,7 @@ const style=async tab=>await p.locator('#ribbon-tab-'+tab).evaluate(n=>{const s=
await p.locator('#ribbon-tab-project').click();await p.mouse.move(1,1);assert.deepEqual(await style('writer'),await style('book'),'same inactive tab style '+theme);const active=await style('project');
await p.locator('#ribbon-tab-writer').hover();const hover=await style('writer');await p.locator('#ribbon-tab-book').hover();assert.deepEqual(await style('book'),hover,'same hover tab style '+theme);
await p.mouse.move(1,1);await p.locator('#ribbon-tab-writer').focus();const focused=await style('writer');await p.locator('#ribbon-tab-book').focus();assert.deepEqual(await style('book'),focused,'same focus tab style '+theme);
await p.locator('#ribbon-tab-writer').click();await p.waitForURL('**/Writer**');await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme(t),theme);await p.mouse.move(1,1);assert.deepEqual(await style('writer'),active,'same active tab style '+theme);await p.goto('https://dev.plotdirector.com/Maps?projectId='+s.project+'&bookId='+s.book);}
const currentURL=p.url();await p.locator('#ribbon-tab-writer').click();assert.equal(p.url(),currentURL,'Writer selects its ribbon without leaving Maps');await p.evaluate(t=>window.PlotDirectorApplyApplicationTheme(t),theme);await p.mouse.move(1,1);assert.deepEqual(await style('writer'),active,'same active tab style '+theme);await p.goto('https://dev.plotdirector.com/Maps?projectId='+s.project+'&bookId='+s.book);}
for(const width of[1666,1366,1024,800]){await p.setViewportSize({width,height:1050});for(const category of['project','book','writer','story','characters','world','tools']){await p.locator('#ribbon-tab-'+category).click();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),category+width);const rows=await p.locator('#ribbon-panel-'+category+' .pd-ribbon-command:visible').evaluateAll(ns=>ns.filter(n=>!n.closest('.pd-context-menu-content')).map(n=>{const span=n.querySelector(':scope>span');return{height:Math.round(n.getBoundingClientRect().height),label:n.textContent.trim(),lines:span?Math.round(span.scrollHeight/parseFloat(getComputedStyle(span).lineHeight)):0};}));for(const row of rows){assert.equal(row.height,68,category+' '+row.label);assert(row.lines<=2,category+' '+row.label+' wrapping');}if(out&&pwa&&(width===1666||width===800))await p.screenshot({path:out+'/'+category+'-'+width+'-deployed.png'});await p.keyboard.press('Tab');assert(await p.evaluate(()=>document.activeElement!==document.body),'keyboard focus retained');}}
assert.deepEqual(errors,[]);console.log('PASS deployed authenticated ribbons '+(pwa?'simulated PWA':'browser')+': all seven primary categories, four widths, four Maps themes, two-line labels, uniform heights, keyboard focus and no page overflow; no map command invoked');await c.close();}}finally{await b.close();}})().catch(e=>{console.error(String(e.stack).replaceAll(who.Password,'[redacted]'));process.exitCode=1});

View File

@ -8,14 +8,16 @@ const base='http://127.0.0.1:5238';
if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
const page=await context.newPage();
await page.goto(base+'/fixture?page=writer&layout=full&bookId=12');
const nav=page.locator('.pd-ribbon-navigation').filter({hasText:/^Writer$/});
const nav=page.locator('#ribbon-tab-writer');
assert.equal(await nav.count(),1);
assert.equal(await nav.getAttribute('aria-current'),'page');
assert.equal(new URL(await nav.getAttribute('href'),base).searchParams.get('projectId'),'7');
assert.equal(new URL(await nav.getAttribute('href'),base).searchParams.get('bookId'),'12');
assert.equal(await nav.getAttribute('aria-selected'),'true');
assert.equal(await nav.getAttribute('data-ribbon-tab'),'writer');
const home=page.locator('#ribbon-panel-writer a[data-command-operation="writer.index"]');
assert.equal(new URL(await home.getAttribute('href'),base).searchParams.get('projectId'),'7');
assert.equal(new URL(await home.getAttribute('href'),base).searchParams.get('bookId'),'12');
assert.equal(await page.locator('#ribbon-panel-story a').filter({hasText:/^Writer$/}).count(),0);
assert.equal(await page.locator('#appStoryMenu + ul a').filter({hasText:/Writer/}).count(),0);
assert(await nav.evaluate(a=>a.matches('.pd-ribbon-navigation')?a.nextElementSibling?.dataset.ribbonTab==='story':a.parentElement.nextElementSibling?.querySelector('#appStoryMenu')!==null));
assert(await nav.evaluate(a=>a.nextElementSibling?.dataset.ribbonTab==='story'));
for(const embedded of [false,true])for(const role of ['Context','Intent']){
await page.goto(base+`/Writing/${role}?bookId=12${embedded?'&embedded=true':''}`);
// Exercise real populated cards and controls without a database or native session.
@ -48,5 +50,5 @@ const base='http://127.0.0.1:5238';
}
await context.close();
}
console.log('PASS Writer direct navigation/order/context/active state, Story removal; Context and Intent shared palettes and live cross-window changes in all four themes, browser/PWA, full/embedded and 390/1440 layouts.');
console.log('PASS Writer shared section selection/order/context/active state, Story removal; Context and Intent shared palettes and live cross-window changes in all four themes, browser/PWA, full/embedded and 390/1440 layouts.');
}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});

View File

@ -13,7 +13,7 @@ const assert=require('node:assert/strict');
await page.evaluate(theme=>window.PlotDirectorApplyApplicationTheme(theme),theme);
await page.waitForFunction(theme=>document.documentElement.dataset.appTheme===theme,theme);
const writer=page.locator('#ribbon-tab-writer'),project=page.locator('#ribbon-tab-project'),book=page.locator('#ribbon-tab-book');
const href=await writer.getAttribute('href');
assert.equal(await writer.getAttribute('data-ribbon-tab'),'writer');
await page.mouse.move(0,0);const activeWriter=await style(writer);
await project.click();await page.mouse.move(0,0);await project.evaluate(el=>el.blur());
assert.equal(await writer.getAttribute('aria-selected'),'false');
@ -25,7 +25,7 @@ const assert=require('node:assert/strict');
assert(await writer.evaluate(el=>el.matches(':focus-visible')));
const focusWriter=await style(writer);await book.focus();
assert.deepEqual(focusWriter,await style(book),`${theme} focus`);
assert.equal(await writer.getAttribute('href'),href,'Writer navigation remains unchanged');
assert.equal(await writer.evaluate(n=>n.tagName),'BUTTON','Writer shares the section selector control');
}
await context.close();
}

View File

@ -0,0 +1,42 @@
const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs');
const base=process.env.PD_NARRATIVE_TEST_URL||'http://127.0.0.1:5238';
(async()=>{
const installed=process.argv.includes('--installed'),profile=fs.mkdtempSync('/tmp/pd-narrative-pwa-');
const c=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1666,height:1050}}):await(await chromium.launch()).newContext({viewport:{width:1666,height:1050}}),b=c.browser();
try{
await c.route('**/Writer/Work/State?*',r=>r.fulfill({json:{session:null,defaultPauseOnEdit:true}}));
await c.route('**/native-companion/connection-state',r=>r.fulfill({json:{known:false,state:'Disconnected',wordConnected:false}}));
await c.route('**/native-companion/status*',r=>r.fulfill({json:{leases:[]}}));
await c.route('**/signalr.min.js',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(require.resolve('@microsoft/signalr/dist/browser/signalr.min.js'),'utf8')}));
await c.route('**/hubs/**',r=>r.abort());
await c.addInitScript(()=>localStorage.setItem('plotdirector.desktop.v1.4',JSON.stringify({dismissedAt:Date.now()})));
let p;
if(installed){const tab=c.pages()[0];await tab.goto(base+'/fixture');const d=await b.newBrowserCDPSession(),manifestId=base+'/Projects';await d.send('PWA.install',{manifestId,installUrlOrBundleUrl:base+'/fixture'});await d.send('PWA.changeAppUserSettings',{manifestId,displayMode:'standalone'});const opened=c.waitForEvent('page');await d.send('PWA.launch',{manifestId,url:base+'/fixture'});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}else p=await c.newPage();
await c.route('**/WriterActivities/**',r=>r.fulfill({contentType:'text/html',body:'<div data-planner-view>Fixture planner content</div>'}));
const toggle=p.locator('[data-ribbon-collapse]'),writer=p.locator('#ribbon-tab-writer');
let documents=0,preferenceWrites=0;const errors=[];p.on('pageerror',e=>errors.push(e.message));
p.on('request',r=>{if(r.isNavigationRequest()&&r.resourceType()==='document')documents++;if(r.method()==='POST'&&new URL(r.url()).pathname==='/Appearance/Ribbon')preferenceWrites++;});
async function collapsed(value){if((await toggle.getAttribute('aria-expanded')==='false')!==value)await toggle.click();await p.waitForFunction(()=>!document.querySelector('[data-ribbon-collapse]').disabled);}
for(const path of ['/Writer?projectId=7&bookId=12','/Writer/Review?projectId=7&bookId=12','/Writer/Explore?projectId=7&bookId=12','/Writer/Plan?projectId=7&bookId=12','/Writer/Reflect?projectId=7&bookId=12','/Timeline/Index?projectId=7&bookId=12']){
const response=await p.goto(base+path);assert.equal(response.status(),200,path);await p.waitForFunction(()=>window.PlotDirectorNarrativeFocus);
await collapsed(true);const url=p.url(),requests=documents,writes=preferenceWrites;
const focus=await p.evaluate(()=>JSON.stringify(window.PlotDirectorNarrativeFocus.state));await p.locator('main').first().evaluate(n=>window.__writerTabMain=n);
await writer.click();assert.equal(p.url(),url);assert.equal(documents,requests);assert.equal(preferenceWrites,writes,'selecting a tab does not overwrite the collapsed preference');
assert.equal(await writer.getAttribute('aria-selected'),'true');assert(await p.locator('#ribbon-panel-writer').isVisible());assert(await p.locator('#ribbon-surface').isVisible());assert.equal(await p.locator('#ribbon-tab-writer').count(),1);
assert(await p.locator('main').first().evaluate(n=>n===window.__writerTabMain),'current workspace remains mounted');assert.equal(await p.evaluate(()=>JSON.stringify(window.PlotDirectorNarrativeFocus.state)),focus);
await p.reload();assert.equal(await toggle.getAttribute('aria-expanded'),'false','temporary opening retains saved collapsed preference on refresh');
await collapsed(false);const expandedURL=p.url(),expandedRequests=documents;
for(const category of ['book','story','characters','world','tools','writer']){await p.locator('#ribbon-tab-'+category).click();assert.equal(p.url(),expandedURL);assert.equal(documents,expandedRequests);assert(await p.locator('#ribbon-panel-'+category).isVisible());}
await p.locator('#ribbon-tab-book').focus();await p.keyboard.press('ArrowRight');assert.equal(await writer.getAttribute('aria-selected'),'true');assert(await writer.evaluate(n=>n===document.activeElement));await p.keyboard.press('ArrowRight');assert.equal(await p.locator('#ribbon-tab-story').getAttribute('aria-selected'),'true');assert.equal(p.url(),expandedURL);
}
await writer.click();const home=p.locator('#ribbon-panel-writer a[data-command-operation="writer.index"]');const homeURL=await home.getAttribute('href');assert(new URL(homeURL,base).pathname==='/Writer');
const target=p.waitForURL(url=>url.pathname==='/Writer');await home.click();await target;for(const title of ['Continue Writing','Explore Your Story','Writing Dashboard'])assert(await p.getByRole('heading',{name:title,exact:true}).isVisible());
assert.equal(await toggle.getAttribute('aria-expanded'),'true','explicit expanded preference survives Home navigation');
for(const width of [1666,800]){await p.setViewportSize({width,height:1050});await collapsed(true);await writer.click();assert(await p.locator('#ribbon-panel-writer').isVisible());await p.screenshot({path:`/tmp/pd-writer-tab-${installed?'pwa':'browser'}-${width}.png`});}
await collapsed(true);await collapsed(false); // Restore the isolated host's default for other suites.
assert.deepEqual(errors,[]);console.log(`PASS ${installed?'installed PWA':'Chromium'} Writer tab: Home/Review/Explore/Plan/Reflect/Timeline remain mounted; collapsed and expanded shared selection; no document navigation or preference writes on selection; refresh persistence; keyboard order; other categories; explicit Home and all three choices; desktop/narrow layouts.`);
}finally{await c.close();await b?.close();fs.rmSync(profile,{recursive:true,force:true});}
})().catch(e=>{console.error(e.stack);process.exitCode=1;});

View File

@ -19,7 +19,7 @@ const fs=require('node:fs');
assert.equal(await page.locator('[data-objective-scene] option[value="32"]').evaluate(option=>option.disabled),true);
await page.locator('[data-objective-chapter]').selectOption('22');
assert.equal(await page.locator('[data-objective-scene]').inputValue(),'');
assert.equal(await page.locator('.pd-ribbon-navigation').filter({hasText:/^Writer$/}).count(),1);
assert.equal(await page.locator('#ribbon-tab-writer').count(),1);
assert.equal(await page.locator('#ribbon-panel-writer').isVisible(),true);
assert.equal(await page.locator('.writer-tabs a').count(),5);
assert.equal(await page.locator('.writer-heading select').count(),0,'Book/project selection belongs to common shell');

View File

@ -118,11 +118,6 @@
<div class="pd-ribbon-tabs" role="tablist" aria-label="Command categories">
@foreach (var category in ApplicationRibbon.Categories)
{
@if (category.Key == "writer")
{
<a class="pd-ribbon-navigation" role="tab" aria-controls="ribbon-panel-writer" aria-selected="@(category.Key == selectedCategory ? "true" : "false")" aria-current="@(Model.ActiveSection == "Writer" ? "page" : null)" asp-controller="Writer" asp-action="Index" asp-route-projectId="@project?.ProjectID" asp-route-bookId="@book?.BookID" id="ribbon-tab-writer">Writer</a>
continue;
}
<button type="button" role="tab" id="ribbon-tab-@category.Key" aria-controls="ribbon-panel-@category.Key" aria-selected="@(category.Key == selectedCategory ? "true" : "false")" tabindex="@(category.Key == selectedCategory ? "0" : "-1")" data-ribbon-tab="@category.Key">@category.Label</button>
}
</div>

View File

@ -52,7 +52,6 @@
collapse.innerHTML = value ? 'Expand ribbon <span aria-hidden="true">⌄</span>' : 'Collapse ribbon <span aria-hidden="true">⌃</span>';
}
function select(tab) {
shell.querySelector(".pd-ribbon-navigation")?.setAttribute("aria-selected", "false");
tabs.forEach(item => { const selected = item === tab; item.setAttribute('aria-selected', String(selected)); item.tabIndex = selected ? 0 : -1; });
shell.querySelectorAll('[role="tabpanel"]').forEach(panel => panel.hidden = panel.id !== tab.getAttribute('aria-controls'));
// A collapsed preference stays collapsed on the next page; selecting a category opens it temporarily.