Cover direct character ribbon controls and stable native-drag acceptance

This commit is contained in:
Nick Beckley 2026-11-26 20:45:52 +00:00
parent cf28db10fe
commit 24d478c838
3 changed files with 19 additions and 7 deletions

View File

@ -22,9 +22,10 @@ const {chromium}=require('playwright');const os=require('node:os'),path=require(
const card=id=>page.locator(`.character-card[data-drag-id="${id}"]`),value=(a,v)=>page.locator(`[data-attribute="${a}"][data-value="${v}"]`);
assert.deepEqual(await card(1).locator('[data-attribute-indicators]>span').evaluateAll(nodes=>nodes.map(n=>n.title.split(':')[0])),['Story importance','Life status','Sex','Character Type','Quick Add Bar']);
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',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.top<top+8)host.scrollTop-=top-r.top+8});const from=await source.boundingBox(),to=await target.boundingBox();await page.mouse.move(from.x+from.width/2,from.y+from.height/2);await page.mouse.down();await page.mouse.move(from.x+from.width/2+8,from.y+from.height/2,{steps:3});await page.mouse.move(to.x+to.width/2,to.y+to.height/2,{steps:12});await page.mouse.move(to.x+to.width/2+1,to.y+to.height/2+1);await page.mouse.up();}
// Use native mouse drags with both endpoints visible; Bootstrap smooth scrolling
// otherwise moves a sticky sidebar endpoint after Playwright locates the source.
async function nativeAssignment(id,a,v,toCharacter){await page.evaluate(()=>document.querySelectorAll('[data-toast-host] button[aria-label^="Dismiss"]').forEach(b=>b.click()));await card(id).evaluate(n=>n.scrollIntoView({block:'start',inline:'nearest',behavior:'instant'}));await page.evaluate(()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve))));const row=value(a,v);await row.evaluate(n=>{const host=n.closest('[data-attribute-sidebar]'),r=n.getBoundingClientRect(),h=host.getBoundingClientRect(),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.top<top+8)host.scrollTop-=top-r.top+8});const source=toCharacter?row.locator('button').first():card(id).locator('[data-character-drag]'),target=toCharacter?card(id):row,from=await source.boundingBox(),to=await target.boundingBox(),x=to.x+to.width/2,y=Math.min(to.y+to.height/2,950);await page.mouse.move(from.x+from.width/2,from.y+from.height/2);await page.mouse.down();await page.mouse.move(from.x+from.width/2+8,from.y+from.height/2,{steps:3});await page.mouse.move(x,y,{steps:12});await page.mouse.move(x+1,y+1);await page.mouse.up();}
const reverse=(id,a,v)=>nativeAssignment(id,a,v,false),forward=(a,v,id)=>nativeAssignment(id,a,v,true);
if(widthCheck){
const measurements=[],directory='/tmp/pd-character-width';fs.mkdirSync(directory,{recursive:true});
for(const width of [1280,1920,2560,3840]){
@ -41,14 +42,14 @@ const {chromium}=require('playwright');const os=require('node:os'),path=require(
assert.deepEqual(errors,[]);fs.writeFileSync(`${directory}/${before?'before':'after'}-${installed?'pwa':'browser'}.json`,JSON.stringify(measurements,null,2));console.log('PASS workspace widths',measurements);await page.close();continue;
}
if(groups.some(g=>g.id==='type')){
await value('type','person').locator('button').first().dragTo(card(1));await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [title="Character Type: Person"]'));
await forward('type','person',1);await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [title="Character Type: Person"]'));
await reverse(2,'type','artificial');await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="2"] [title="Character Type: Artificial being"]'));
await card(1).locator('[data-character-select]').check();await card(2).locator('[data-character-select]').check();
await value('type','animal').getByRole('button',{name:/Assign/}).click();await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="2"] [title="Character Type: Animal"]'));
await page.locator('[data-undo]').click();await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="2"] [title="Character Type: Artificial being"]'));assert.equal(records[0].values.type,'person');
await value('type','unclassified').getByRole('button',{name:/Assign/}).click();await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="2"] [title="Character Type: Unclassified"]'));
await page.locator('[data-clear-selection]').click();
await value('type','animal').locator('button').first().dragTo(card(1));await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [title="Character Type: Animal"]'));assert.equal(await value('type','animal').locator('button').first().getAttribute('aria-pressed'),'false');
await forward('type','animal',1);await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [title="Character Type: Animal"]'));assert.equal(await value('type','animal').locator('button').first().getAttribute('aria-pressed'),'false');
if(count===100){fs.mkdirSync('/tmp/pd-character-types',{recursive:true});await page.screenshot({path:`/tmp/pd-character-types/${installed?'pwa':'browser'}-assigned.png`});}
await page.locator('[data-undo]').click();await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [title="Character Type: Unclassified"]'));
await reverse(2,'type','animal');await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="2"] [title="Character Type: Animal"]'));await page.locator('[data-undo]').click();await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="2"] [title="Character Type: Unclassified"]'));
@ -58,7 +59,7 @@ const {chromium}=require('playwright');const os=require('node:os'),path=require(
await page.locator('[data-attribute-groups] summary').filter({hasText:'Character Type'}).click();
}
assert.equal(await page.locator('.character-card').count(),count);const biography=await card(1).locator('.visual-card-heading p.muted').textContent();assert(biography.includes('Complete biography for character 1'));const heights=await page.locator('.character-card').evaluateAll(ns=>ns.slice(0,9).map(n=>n.getBoundingClientRect().height));assert(new Set(heights.map(Math.round)).size>1);
await value('importance','10').locator('button').first().dragTo(card(1));await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [data-attribute-indicators]').textContent===''&&document.querySelector('.character-card[data-drag-id="1"] [title="Story importance: Major"]'));assert.equal(records[0].values.importance,'10');
await forward('importance','10',1);await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [data-attribute-indicators]').textContent===''&&document.querySelector('.character-card[data-drag-id="1"] [title="Story importance: Major"]'));assert.equal(records[0].values.importance,'10');
await reverse(2,'importance','6');await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="2"] [title="Story importance: Supporting"]'));assert.equal(records[1].values.importance,'6');
await card(1).locator('[data-character-select]').check();await card(2).locator('[data-character-select]').check();await value('importance','2').getByRole('button',{name:/Assign/}).click();await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [title="Story importance: Minor"]'));assert.equal(requests.at(-1).changes.length,2);
await page.locator('[data-undo]').click();await page.waitForFunction(()=>document.querySelector('.character-card[data-drag-id="1"] [title="Story importance: Major"]'));assert.equal(records[1].values.importance,'6');

View File

@ -0,0 +1,11 @@
const {chromium}=require('playwright'),assert=require('assert/strict'),fs=require('fs'),os=require('os'),path=require('path');
(async()=>{const installed=process.argv.includes('--installed'),base='http://127.0.0.1:5238',profile=installed?fs.mkdtempSync(path.join(os.tmpdir(),'pd-ribbon-pwa-')):null,b=installed?null:await chromium.launch(),c=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1920,height:1080}}):await b.newContext({viewport:{width:1920,height:1080}});let p=installed?c.pages()[0]:await c.newPage(),cdp;try{
await c.route('https://cdn.jsdelivr.net/**',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(path.join(__dirname,'node_modules',r.request().url().includes('chart.umd')?'chart.js/dist/chart.umd.js':'@microsoft/signalr/dist/browser/signalr.min.js'))}));
if(installed){await p.goto(base+'/fixture?page=calendar-test');cdp=await c.browser().newBrowserCDPSession();await cdp.send('PWA.install',{manifestId:base+'/Projects',installUrlOrBundleUrl:p.url()});await cdp.send('PWA.changeAppUserSettings',{manifestId:base+'/Projects',displayMode:'standalone'});const opened=c.waitForEvent('page');await cdp.send('PWA.launch',{manifestId:base+'/Projects',url:p.url()});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}
const errors=[];p.on('pageerror',e=>errors.push(e.message));let archivePosts=0;await p.route('**/Characters/Archive',r=>{archivePosts++;return r.fulfill({contentType:'text/html',body:'<p>Disposable archive endpoint</p>'})});
for(const tab of ['overview','relationships','evolution','appearances','knowledge']){await p.goto(base+'/character-workspace-fixture?tab='+tab);await p.setViewportSize({width:1920,height:1080});const group=p.locator('[data-character-ribbon]');assert.deepEqual((await group.locator('.pd-ribbon-command span').allTextContents()).filter(text=>text!=='More'),['Edit Character','Merge Character','Reanalyse Biography','Archive Character']);assert.match(await group.getByRole('link',{name:'Merge Character',exact:true}).getAttribute('href'),/Characters\/Merge\/5/);assert.match(await group.locator('[data-character-reanalyse-form]').getAttribute('action'),/Characters\/Reanalyse/);assert.equal(await group.locator('[data-character-reanalyse-button] svg').count(),1);await p.getByRole('button',{name:'Export',exact:true}).click();const menu=p.locator('[data-character-actions-for="5"]');await menu.waitFor({state:'visible'});assert.deepEqual(await menu.locator('.dropdown-item').allTextContents(),['Export character','Markdown']);assert.equal(await menu.locator('form').count(),0);await p.keyboard.press('Escape');}
await p.locator('[data-character-ribbon] form[action*=Archive] button').click();await p.locator('#plotlineConfirmModal.show').waitFor();assert((await p.locator('[data-character-ribbon] form[action*=Archive]').getAttribute('data-confirm-message')).includes('data will be retained for restoration'));assert((await p.locator('#plotlineConfirmModal').innerText()).toLowerCase().includes('archiv'));assert.equal(archivePosts,0);await p.locator('#plotlineConfirmModal').getByRole('button',{name:'Cancel',exact:true}).last().click();await p.locator('#plotlineConfirmModal').waitFor({state:'hidden'});assert.equal(archivePosts,0);
const out='/tmp/pd-ui-refinements';fs.mkdirSync(out,{recursive:true});for(const theme of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue']){await p.evaluate(theme=>{document.documentElement.dataset.appTheme=theme;document.documentElement.dataset.bsTheme=theme.endsWith('dark')?'dark':'light';document.documentElement.dataset.theme=theme.endsWith('dark')?'dark':'light';},theme);await p.screenshot({path:`${out}/ribbon-${installed?'pwa':'browser'}-${theme}.png`});}
for(const width of [1280,1920,2560,3840,768,390]){await p.setViewportSize({width,height:1080});await p.getByRole('button',{name:'Export',exact:true}).click();await p.locator('[data-character-actions-for="5"]').waitFor({state:'visible'});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await p.keyboard.press('Escape');}
await p.goto(base+'/character-workspace-fixture?viewer=true');assert.equal(await p.locator('[data-character-ribbon]').count(),0);await p.getByRole('button',{name:'Export',exact:true}).click();assert.equal(await p.locator('[data-character-actions-for] .dropdown-item').count(),2);assert.deepEqual(errors,[]);console.log('PASS Character Details ribbon across all five tabs, direct merge/AI/archive, retained archive confirmation, export-only Output, read-only permissions, all themes, responsive widths and '+(installed?'installed PWA':'browser'));
}finally{if(cdp)await cdp.send('PWA.uninstall',{manifestId:base+'/Projects'}).catch(()=>{});await c.close();if(b)await b.close();if(profile)fs.rmSync(profile,{recursive:true,force:true});}})().catch(e=>{console.error(e.name+': '+e.message.split('Call log:')[0]);process.exitCode=1});

View File

@ -6263,7 +6263,7 @@ static void CharacterMergeIsReusableStoredProcedureWorkflow()
Assert(services.Contains("Task<CharacterMergeViewModel?> GetMergeAsync", StringComparison.Ordinal), "Character service should expose merge UI data.");
Assert(controller.Contains("public async Task<IActionResult> Merge(int id)", StringComparison.Ordinal), "Normal Character UI should expose merge GET.");
Assert(controller.Contains("public async Task<IActionResult> Merge(CharacterMergeForm form)", StringComparison.Ordinal), "Normal Character UI should expose merge POST.");
Assert(details.Contains("Merge with another character", StringComparison.Ordinal), "Character details should link to merge.");
Assert(details.Contains("Merge Character", StringComparison.Ordinal), "Character details should link to merge.");
Assert(merge.Contains("References, aliases, scene appearances, POV links, relationship events and knowledge are moved", StringComparison.Ordinal), "Merge UI should explain reference propagation.");
Assert(siCharacters.Contains("characters.MergeAsync(candidate.ExistingCharacterID.Value, targetCharacterId.Value", StringComparison.Ordinal), "Story Intelligence aliasing should reuse canonical merge when an existing duplicate is known.");
Assert(migration.Contains("CREATE OR ALTER PROCEDURE dbo.Character_Merge", StringComparison.Ordinal), "Character merge should be database-backed.");