diff --git a/PlotLine.Tests/Browser/character-attributes.cjs b/PlotLine.Tests/Browser/character-attributes.cjs index 96a4bab0..bfc87e2a 100644 --- a/PlotLine.Tests/Browser/character-attributes.cjs +++ b/PlotLine.Tests/Browser/character-attributes.cjs @@ -24,7 +24,7 @@ const {chromium}=require('playwright');const os=require('node:os'),path=require( assert.equal(await card(1).locator('[title="Sex: Recorded custom sex"] path').getAttribute('d'),groups.find(g=>g.id==='sex').fallback.path); // Native mouse drag with both endpoints visible: scrolling a sticky target through // dragTo can scroll the page after locating the source and move its handle away. - async function reverse(id,a,v){await page.evaluate(()=>document.querySelectorAll('[data-toast-host] button[aria-label^="Dismiss"]').forEach(b=>b.click()));const source=card(id).locator('[data-character-drag]'),target=value(a,v);await source.evaluate(n=>n.scrollIntoView({block:'start',inline:'nearest'}));await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));await target.evaluate(n=>{const host=n.closest('[data-attribute-sidebar]'),r=n.getBoundingClientRect(),h=host.getBoundingClientRect();const bottom=Math.min(h.bottom,innerHeight),top=Math.max(h.top,0);if(r.bottom>bottom-8)host.scrollTop+=r.bottom-bottom+8;if(r.topdocument.querySelectorAll('[data-toast-host] button[aria-label^="Dismiss"]').forEach(b=>b.click()));const source=card(id).locator('[data-character-drag]'),target=value(a,v);await source.evaluate(n=>n.scrollIntoView({block:'start',inline:'nearest',behavior:'instant'}));await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));await target.evaluate(n=>{const host=n.closest('[data-attribute-sidebar]'),r=n.getBoundingClientRect(),h=host.getBoundingClientRect();const bottom=Math.min(h.bottom,innerHeight),top=Math.max(h.top,0);if(r.bottom>bottom-8)host.scrollTop+=r.bottom-bottom+8;if(r.topn.open=true);await page.locator('[name=PageSize]').selectOption('50');await page.locator('[name=BookID]').selectOption('13');await page.locator('[name=LocaleCode]').selectOption('fr-FR');await page.locator('[name=UsedOnly]').selectOption('false');await page.locator('[name=SortOrder]').selectOption('name-desc'); await page.waitForFunction(()=>JSON.parse(document.querySelector('[data-names-applied]').textContent).SortOrder==='name-desc');await page.locator('[data-name-page="2"]').click();await page.waitForFunction(()=>document.querySelector('[data-names-results]').dataset.page==='2');await page.locator('[data-name-select]').first().click();await page.waitForFunction(()=>document.querySelector('[data-name-details-fragment] h2')?.textContent==='George 51'); - const scroll=await page.evaluate(()=>{let node=document.querySelector('[data-names-workspace]').parentElement;for(;node;node=node.parentElement)if(/auto|scroll/.test(getComputedStyle(node).overflowY)&&node.scrollHeight>node.clientHeight){node.scrollTop=450;return node.scrollTop}document.scrollingElement.scrollTop=450;return document.scrollingElement.scrollTop});assert(scroll>100); + const scroll=await page.evaluate(()=>{let node=document.querySelector('[data-names-workspace]').parentElement;for(;node&&node!==document.body&&node!==document.documentElement;node=node.parentElement)if(/auto|scroll/.test(getComputedStyle(node).overflowY)&&node.scrollHeight>node.clientHeight){node.scrollTo({top:450,behavior:"instant"});return node.scrollTop}document.scrollingElement.scrollTo({top:450,behavior:"instant"});return document.scrollingElement.scrollTop});assert(scroll>100); const pages=page.context().pages().length;await page.route('**/Characters/Details/501',r=>r.fulfill({contentType:'text/html',body:'

Canonical Character Details

'}));await page.route('**/Characters/Edit/501',r=>r.fulfill({contentType:'text/html',body:'

Canonical Character Editor

'})); - for(const action of ['View Character','Edit Character']){await Promise.all([page.waitForURL(action==='View Character'?'**/Characters/Details/501':'**/Characters/Edit/501'),page.getByRole('link',{name:action,exact:true}).first().click()]);assert.equal(page.context().pages().length,pages);await page.goBack();await page.waitForFunction(()=>document.querySelector('[data-name-details-fragment] h2')?.textContent==='George 51');assert.equal(await page.locator('[name=SortOrder]').inputValue(),'name-desc');assert.equal(await page.locator('[name=Page]').inputValue(),'2');assert.equal(await page.locator('[name=PageSize]').inputValue(),'50');assert.equal(await page.locator('[name=BookID]').inputValue(),'13');assert.equal(await page.locator('[name=LocaleCode]').inputValue(),'fr-FR');await page.waitForFunction(expected=>{let n=document.querySelector('[data-names-workspace]').parentElement;for(;n;n=n.parentElement)if(/auto|scroll/.test(getComputedStyle(n).overflowY)&&n.scrollHeight>n.clientHeight)return Math.abs(n.scrollTop-expected)<3;return Math.abs(document.scrollingElement.scrollTop-expected)<3},scroll);} + for(const action of ['View Character','Edit Character']){await Promise.all([page.waitForURL(action==='View Character'?'**/Characters/Details/501':'**/Characters/Edit/501'),page.getByRole('link',{name:action,exact:true}).first().click()]);assert.equal(page.context().pages().length,pages);await page.goBack();await page.waitForFunction(()=>document.querySelector('[data-name-details-fragment] h2')?.textContent==='George 51');assert.equal(await page.locator('[name=SortOrder]').inputValue(),'name-desc');assert.equal(await page.locator('[name=Page]').inputValue(),'2');assert.equal(await page.locator('[name=PageSize]').inputValue(),'50');assert.equal(await page.locator('[name=BookID]').inputValue(),'13');assert.equal(await page.locator('[name=LocaleCode]').inputValue(),'fr-FR');await page.waitForFunction(expected=>{let n=document.querySelector('[data-names-workspace]').parentElement;for(;n&&n!==document.body&&n!==document.documentElement;n=n.parentElement)if(/auto|scroll/.test(getComputedStyle(n).overflowY)&&n.scrollHeight>n.clientHeight)return Math.abs(n.scrollTop-expected)<3;return Math.abs(document.scrollingElement.scrollTop-expected)<3},scroll);} for(const expanded of [false,true]){await page.locator('[data-names-filters]').evaluate((n,open)=>n.open=open,expanded);await page.locator('[name=Search]').fill('R');await page.locator('[data-names-clear]').click();await page.waitForFunction(()=>{const f=JSON.parse(document.querySelector('[data-names-applied]').textContent);return !f.Search&&f.Page===1});assert.equal(await page.locator('[name=Search]').inputValue(),'');assert.equal(await page.locator('[name=UsedOnly]').inputValue(),'');assert.equal(await page.locator('[name=LocaleCode]').inputValue(),'');assert.equal(await page.locator('[name=PageSize]').inputValue(),'50');assert.equal(await page.locator('[name=BookID]').inputValue(),'13');assert.equal(await page.locator('[name=SortOrder]').inputValue(),'name-desc');} fs.writeFileSync(`/tmp/pd-names-workspace/${installed?'pwa':'browser'}-measurements.json`,JSON.stringify({measurements,calls},null,2));console.log('PASS Names compact results, deferred canonical details, animal/alias associations, navigation, state, themes, wide/narrow layouts',calls); }finally{if(installed){await cdp.send('PWA.uninstall',{manifestId}).catch(()=>{});await persistent.close();fs.rmSync(profile,{recursive:true,force:true});}else await browser.close();} diff --git a/PlotLine/wwwroot/js/names-workspace.js b/PlotLine/wwwroot/js/names-workspace.js index 2f8bdea7..b6d8e156 100644 --- a/PlotLine/wwwroot/js/names-workspace.js +++ b/PlotLine/wwwroot/js/names-workspace.js @@ -3,7 +3,7 @@ window.PlotDirectorNames={mount(root,{state:prior,onState=()=>{}}={}){ const lifetime=new AbortController(),form=root.querySelector('[data-names-search]'),results=root.querySelector('[data-names-results-host]'),details=root.querySelector('[data-names-details]'),status=root.querySelector('[data-names-status]'); const paneHost=root.closest('[data-context-pane-content]');let sizeObserver;if(paneHost){root.classList.add('names-workspace--context');sizeObserver=new ResizeObserver(()=>root.style.setProperty('--names-available-height',paneHost.clientHeight+'px'));sizeObserver.observe(paneHost);} - function scrollHost(){for(let node=root.parentElement;node;node=node.parentElement)if(/auto|scroll/.test(getComputedStyle(node).overflowY)&&node.scrollHeight>node.clientHeight)return node;return document.scrollingElement;} + function scrollHost(){for(let node=root.parentElement;node&&node!==document.body&&node!==document.documentElement;node=node.parentElement)if(/auto|scroll/.test(getComputedStyle(node).overflowY)&&node.scrollHeight>node.clientHeight)return node;return document.scrollingElement;} let selected='',page=Number(form.elements.Page.value)||1,searchRequest,detailRequest,searchEpoch=0,detailEpoch=0,featureBusy=false; const listen=(node,event,fn)=>node.addEventListener(event,fn,{signal:lifetime.signal}); function snapshot(){return {fields:[...new FormData(form)],selected,page,expanded:root.querySelector('[data-names-filters]').open,scroll:scrollHost().scrollTop,detailsScroll:details.scrollTop,detailsOpen:root.hasAttribute('data-details-open')};}