diff --git a/PlotLine.Tests/Browser/ai-allowances.cjs b/PlotLine.Tests/Browser/ai-allowances.cjs index 8db8183d..93199315 100644 --- a/PlotLine.Tests/Browser/ai-allowances.cjs +++ b/PlotLine.Tests/Browser/ai-allowances.cjs @@ -9,7 +9,7 @@ const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=r await page.route('**/Ai/Quote?*',r=>r.fulfill({json:{allowed,entitled:allowed,name:'Regenerate character biography',cost:10,remaining:100,renewal:'2026-12-01T00:00:00Z',message:allowed?'':'This operation requires an AI-enabled subscription.',upgradeUrl:'/ManageAccount/Subscription'}})); await page.route('**/Characters/Reanalyse**',r=>{posts.push(r.request().postData());return r.fulfill({json:{success:true,characterID:5,characterEnrichmentRunID:777,status:'Queued',bookID:12,currentMessage:'Synthetic analysis queued'}});}); await page.goto(base+'/character-workspace-fixture');await page.locator('[data-character-reanalyse-button]').waitFor({state:'attached'}); - async function open(){await page.locator('[data-character-ribbon] .dropdown-toggle').click();await page.locator('[data-character-reanalyse-button]').click();await page.locator('.pd-ai-confirm').waitFor();} + async function open(){await page.locator('[data-character-reanalyse-button]').click();await page.locator('.pd-ai-confirm').waitFor();} fs.mkdirSync('/tmp/pd-ai-allowances',{recursive:true});await open();assert((await page.locator('.pd-ai-confirm').innerText()).includes('requires an AI-enabled subscription'));assert.equal(await page.locator('.pd-ai-confirm a').getAttribute('href'),'/ManageAccount/Subscription');assert.equal(posts.length,0);await page.screenshot({path:`/tmp/pd-ai-allowances/${installed?'pwa':'browser'}-restriction.png`});await page.keyboard.press('Escape');await page.locator('.pd-ai-confirm').waitFor({state:'detached'}); allowed=true;await open();assert((await page.locator('.pd-ai-confirm').innerText()).includes('10 AI credits'));await page.getByRole('button',{name:'Cancel',exact:true}).click();assert.equal(posts.length,0);await open();await page.getByRole('button',{name:'Continue · 10 credits',exact:true}).click();await page.waitForFunction(()=>document.querySelector('[data-character-analysis-status]')?.textContent==='Queued');assert.equal(posts.length,1);assert.match(posts[0],/name="expectedCredits"\r\n\r\n10/);assert.match(posts[0],/name="requestID"\r\n\r\n[a-f0-9-]{36}/i);assert(posts[0].includes('__RequestVerificationToken')); await page.goto(base+'/ai-policy-fixture/admin');assert.equal(await page.locator('form input[name=Action][value=Operation]').count(),1);assert((await page.locator('body').innerText()).includes('Unrecorded'));assert.equal(await page.locator('form').filter({has:page.locator('input[name=SubscriptionLevelID][value="1"]')}).locator('[name=Enabled] option[value=true]').count(),0); diff --git a/PlotLine.Tests/Browser/character-workspace.cjs b/PlotLine.Tests/Browser/character-workspace.cjs index 01380adf..133e0d21 100644 --- a/PlotLine.Tests/Browser/character-workspace.cjs +++ b/PlotLine.Tests/Browser/character-workspace.cjs @@ -9,8 +9,8 @@ const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=r step='Story network uses selected point and filters';await p.click('[data-character-tab="relationships"]');await p.waitForSelector('[data-character-node]');await p.click('[data-character-lens="story"]');await p.locator('[data-character-connection="12"]').waitFor({state:'attached'});assert.match(await p.locator('[data-character-graph-selection]').innerText(),/Recorded identity|Current character/); step='responsive and touch-size geometry';for(const width of [1366,1024,768,390]){await p.setViewportSize({width,height:1000});for(const tab of ['overview','relationships','evolution','appearances','knowledge']){await p.click('[data-character-tab="'+tab+'"]');await p.locator('[data-character-tab-content="'+tab+'"]').waitFor();assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2),width+'/'+tab);}}await p.screenshot({path:'/tmp/character-workspace-mobile.png',fullPage:true});assert.equal(native,1);assert(si<=2,'existing global/detail SI connections do not grow per tab'); step='direct legacy fragment, remembered character tab and keyboard';await p.goto(base+'/Characters/Details/5#character-gallery');await p.locator('[data-workspace-gallery][open]').waitFor();await p.click('[data-character-tab="knowledge"]');await p.waitForSelector('[data-character-tab-content="knowledge"]');await p.locator('[data-character-switch]').fill('another');await p.locator('[data-character-matches] a').click();await p.waitForURL(/\/Characters\/Details\/6\?tab=knowledge/);await p.locator('[data-character-tab-content="knowledge"]').waitFor();await p.locator('[data-character-tab="knowledge"]').focus();await p.keyboard.press('Home');await p.waitForSelector('[data-character-tab-content="overview"]'); - step='one exact history destination and ribbon targets';await p.setViewportSize({width:1024,height:1000});await p.click('[data-character-tab="relationships"]');assert.equal(await p.locator('[data-workspace-history]').count(),0);assert.equal(await p.locator('[data-character-history]').count(),0);assert.match(await p.locator('[data-workspace-relationship="12"] a').filter({hasText:'History'}).getAttribute('href'),/Dynamics\/Relationship\/12.*returnCharacterId=6/);assert.equal(await p.locator('.character-workspace-header .button-row,.character-workspace-header .dropdown,.character-workspace-header a.btn').count(),0);assert.match(await p.locator('[data-character-ribbon-edit]').getAttribute('href'),/Characters\/Edit\/6/);assert.equal(await p.locator('[data-character-ribbon] form[action*="Archive"] [name=id]').inputValue(),'6');await p.locator('[data-character-ribbon] [data-bs-toggle="dropdown"]').click();const menu=p.locator('[data-character-actions-for="6"]');await menu.waitFor({state:'visible'});assert.match(await menu.getByRole('link',{name:'Markdown',exact:true}).getAttribute('href'),/Exports\/Character\/6.*format=markdown/);assert(await menu.locator('form[action*="Archive"] button').evaluate(n=>{const r=n.getBoundingClientRect();return n.contains(document.elementFromPoint(r.x+r.width/2,r.y+r.height/2));}));await p.keyboard.press('Escape'); + step='one exact history destination and ribbon targets';await p.setViewportSize({width:1024,height:1000});await p.click('[data-character-tab="relationships"]');assert.equal(await p.locator('[data-workspace-history]').count(),0);assert.equal(await p.locator('[data-character-history]').count(),0);assert.match(await p.locator('[data-workspace-relationship="12"] a').filter({hasText:'History'}).getAttribute('href'),/Dynamics\/Relationship\/12.*returnCharacterId=6/);assert.equal(await p.locator('.character-workspace-header .button-row,.character-workspace-header .dropdown,.character-workspace-header a.btn').count(),0);assert.match(await p.locator('[data-character-ribbon-edit]').getAttribute('href'),/Characters\/Edit\/6/);assert.equal(await p.locator('[data-character-ribbon] form[action*="Archive"] [name=id]').inputValue(),'6');await p.locator('[data-character-export] [data-bs-toggle="dropdown"]').click();const menu=p.locator('[data-character-actions-for="6"]');await menu.waitFor({state:'visible'});assert.match(await menu.getByRole('link',{name:'Markdown',exact:true}).getAttribute('href'),/Exports\/Character\/6.*format=markdown/);assert(await p.locator('[data-character-ribbon] form[action*="Archive"] button').evaluate(n=>{const r=n.getBoundingClientRect();return n.contains(document.elementFromPoint(r.x+r.width/2,r.y+r.height/2));}));await p.keyboard.press('Escape'); step='tablet touch pan and pinch';await p.setViewportSize({width:768,height:1000});await p.locator('[data-character-lens="family"]').click();await p.locator('[data-character-node]').first().waitFor({state:'attached'});await p.locator('[data-character-graph-reset]').click();const host=p.locator('[data-character-graph]');await host.scrollIntoViewIfNeeded();const box=await host.boundingBox(),x=box.x+box.width*.5,y=box.y+box.height*.5,cdp=await c.newCDPSession(p);await cdp.send('Emulation.setTouchEmulationEnabled',{enabled:true,maxTouchPoints:2});const world=p.locator('[data-character-graph] svg > g'),beforePan=await world.getAttribute('transform');await cdp.send('Input.dispatchTouchEvent',{type:'touchStart',touchPoints:[{x,y,id:1}]});await cdp.send('Input.dispatchTouchEvent',{type:'touchMove',touchPoints:[{x:x+70,y:y+30,id:1}]});await cdp.send('Input.dispatchTouchEvent',{type:'touchEnd',touchPoints:[]});assert.notEqual(await world.getAttribute('transform'),beforePan);const beforePinch=await world.getAttribute('transform');await cdp.send('Input.dispatchTouchEvent',{type:'touchStart',touchPoints:[{x:x-35,y,id:1},{x:x+35,y,id:2}]});await cdp.send('Input.dispatchTouchEvent',{type:'touchMove',touchPoints:[{x:x-70,y,id:1},{x:x+70,y,id:2}]});await cdp.send('Input.dispatchTouchEvent',{type:'touchEnd',touchPoints:[]});assert.notEqual(await world.getAttribute('transform'),beforePinch);await p.screenshot({path:'/tmp/character-workspace-tablet-family.png',fullPage:false});await cdp.send('Emulation.setTouchEmulationEnabled',{enabled:false}); - step='return to exact definition and retained group';removed=false;await p.goto(base+'/Characters/Details/5?tab=relationships&relationshipId=9');await p.waitForSelector('[data-workspace-relationship="9"].is-selected');assert.equal(await p.locator('[data-relationship-group="6"]').evaluate(n=>n.open),true);for(const width of [1366,1024,768,390]){await p.setViewportSize({width,height:1000});await p.locator('[data-character-ribbon] [data-bs-toggle="dropdown"]').click();const menu=p.locator('[data-character-actions-for="5"]');await menu.waitFor({state:'visible'});const archive=menu.locator('form[action*="Archive"] button');assert(await archive.evaluate(n=>{const r=n.getBoundingClientRect();return n.contains(document.elementFromPoint(r.x+r.width/2,r.y+r.height/2));}));assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await p.keyboard.press('Escape');}await p.setViewportSize({width:1366,height:1000});await p.evaluate(()=>{document.documentElement.dataset.appTheme='warm-dark';document.documentElement.dataset.theme='dark';document.documentElement.dataset.bsTheme='dark'});await p.screenshot({path:'/tmp/character-refinement-grouped-dark.png',fullPage:true}); + step='return to exact definition and retained group';removed=false;await p.goto(base+'/Characters/Details/5?tab=relationships&relationshipId=9');await p.waitForSelector('[data-workspace-relationship="9"].is-selected');assert.equal(await p.locator('[data-relationship-group="6"]').evaluate(n=>n.open),true);for(const width of [1366,1024,768,390]){await p.setViewportSize({width,height:1000});await p.locator('[data-character-export] [data-bs-toggle="dropdown"]').click();const menu=p.locator('[data-character-actions-for="5"]');await menu.waitFor({state:'visible'});const archive=p.locator('[data-character-ribbon] form[action*="Archive"] button');assert(await archive.evaluate(n=>{const r=n.getBoundingClientRect();return n.contains(document.elementFromPoint(r.x+r.width/2,r.y+r.height/2));}));assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await p.keyboard.press('Escape');}await p.setViewportSize({width:1366,height:1000});await p.evaluate(()=>{document.documentElement.dataset.appTheme='warm-dark';document.documentElement.dataset.theme='dark';document.documentElement.dataset.bsTheme='dark'});await p.screenshot({path:'/tmp/character-refinement-grouped-dark.png',fullPage:true}); step='read-only workspace';viewer=true;await p.goto(base+'/character-workspace-fixture?viewer=true&tab=relationships');await p.waitForSelector('[data-character-tab-content="relationships"]');assert.equal(await p.locator('[data-workspace-operation]').count(),0);assert.equal(await p.locator('[data-workspace-add]').count(),0);assert.deepEqual(errors,[]);console.log('PASS main Character browser: compact header, five lazy tabs, dossier/aliases/gallery, bounded explorers and pages, Family branches, Story and selected point, diagram/record selection, modal widths/inline error/Escape/unsaved protection, explicit archive consequences, refresh, cache, back/forward, character links, legacy hash, keyboard, desktop/laptop/tablet/mobile, touch pan/pinch, grouped/filterable records, exact History return, current-character ribbon targets and read-only; connection counts stable across tabs.'); }catch(e){console.error('FAILED '+step+': '+e.stack);process.exitCode=1;}finally{await b.close();}})(); diff --git a/PlotLine.Tests/Program.cs b/PlotLine.Tests/Program.cs index eefbb470..3207da40 100644 --- a/PlotLine.Tests/Program.cs +++ b/PlotLine.Tests/Program.cs @@ -1589,7 +1589,7 @@ static void CharacterDetailCanQueueSingleCharacterEnrichment() var enrichmentService = File.ReadAllText(Path.Combine(root, "Services/CharacterEnrichmentService.cs")); var view = File.ReadAllText(Path.Combine(root, "Views/Characters/Details.cshtml")) + File.ReadAllText(Path.Combine(root, "Views/Shared/_CharacterRibbonCommands.cshtml")); - Assert(view.Contains("Reanalyse character", StringComparison.Ordinal), "Character detail should expose a discreet reanalyse action."); + Assert(view.Contains("Reanalyse Biography", StringComparison.Ordinal), "Character detail exposes its existing biography operation on the ribbon."); Assert(view.Contains("data-character-reanalyse-form", StringComparison.Ordinal), "Character reanalyse action should be script-addressable."); Assert(controller.Contains("Reanalyse(int id,Guid? requestID,int? expectedCredits)", StringComparison.Ordinal) && controller.Contains("QueueCharacterReanalysisAsync(id,requestID,expectedCredits)", StringComparison.Ordinal), "Character controller should queue manual reanalysis through the character service."); diff --git a/PlotLine/Views/Shared/_CharacterRibbonCommands.cshtml b/PlotLine/Views/Shared/_CharacterRibbonCommands.cshtml index 450272f1..58f00eb7 100644 --- a/PlotLine/Views/Shared/_CharacterRibbonCommands.cshtml +++ b/PlotLine/Views/Shared/_CharacterRibbonCommands.cshtml @@ -1,10 +1,13 @@ @model CharacterDetailViewModel @{var c=Model.Character;var analysis=Model.CharacterAnalysis;} +@if(Model.WorkspaceCanEdit){