PlotDirector/PlotLine.Tests/Browser/character-workspace-live.cjs

15 lines
8.7 KiB
JavaScript

// Explicit Development-only opt-in. Creates its own disposable character and relationship.
const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
(async()=>{assert(process.env.PD_CONTEXT_IDENTITY&&process.env.PD_CONTEXT_SCOPE);const who=JSON.parse(fs.readFileSync(process.env.PD_CONTEXT_IDENTITY)),s=JSON.parse(fs.readFileSync(process.env.PD_CONTEXT_SCOPE));assert.equal(who.Database,'PlotDirector_Development');assert.equal(who.UserID,s.user);assert(who.Email.startsWith('pwa-browser-'));const b=await chromium.launch();let step='login';try{const c=await b.newContext({viewport:{width:1366,height:1000}}),p=await c.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));await p.addLocatorHandler(p.locator('[data-desktop-continue]'),async l=>l.click());await p.goto('https://dev.plotdirector.com/Account/Login');await p.locator('[name=Email]').fill(who.Email);await p.locator('[name=Password]').fill(who.Password);await Promise.all([p.waitForURL(u=>u.pathname!='/Account/Login'),p.locator('button[type=submit]').click()]);
step='new isolated character and Supporting default';await p.goto('https://dev.plotdirector.com/Characters/Create?projectId='+s.project);assert.equal(await p.locator('[name=CharacterImportance]').inputValue(),'6');const fixtureName='Workspace qualification '+Date.now();await p.locator('[name=CharacterName]').fill(fixtureName);await Promise.all([p.waitForURL(/\/Characters\/Details\/\d+/),p.locator('button[type=submit]').filter({hasText:'Save character'}).click()]);const id=Number(new URL(p.url()).pathname.split('/').at(-1));assert(!s.characters.includes(id));fs.writeFileSync('/tmp/character-refinement-live-fixture.json',JSON.stringify({project:s.project,user:s.user,character:id}));await p.locator('[data-character-tab-content="overview"]').waitFor();
step='ribbon targets through character back/forward and refresh';await p.goto('https://dev.plotdirector.com/Characters/Details/'+s.characters[0]+'?tab=overview');await p.locator('[data-character-ribbon="'+s.characters[0]+'"]').waitFor();await p.goBack();await p.locator('[data-character-ribbon="'+id+'"]').waitFor();await p.goForward();await p.locator('[data-character-ribbon="'+s.characters[0]+'"]').waitFor();await p.goBack();await p.reload();await p.locator('[data-character-ribbon="'+id+'"]').waitFor();assert.match(await p.locator('[data-character-ribbon-edit]').getAttribute('href'),new RegExp('/Characters/Edit/'+id+'$'));
step='five live bounded tabs and empty states';for(const tab of ['relationships','evolution','appearances','knowledge','overview']){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));}await p.click('[data-character-tab="relationships"]');await p.locator('[data-character-node="'+id+'"]').waitFor({state:'attached'});
step='existing Context peer notifications';const peer=await c.newPage();await peer.goto(`https://dev.plotdirector.com/Writing/Context?projectId=${s.project}&bookId=${s.book}&sceneId=${s.scene}`);await peer.waitForFunction(()=>document.querySelector('[data-context-workspace]')?.contextController.connection?.state==='Connected');await peer.evaluate(project=>{window.workspaceHints=0;document.querySelector('[data-context-workspace]').contextController.connection.on('ContextInvalidated',hint=>{if(Number(hint.projectId)===project)workspaceHints++});},s.project);
step='initial parent via canonical save';await p.locator('[data-workspace-add]').click();// Resolve the known fixture name from its authenticated shell, without printing it.
const targetShell=await c.request.get('https://dev.plotdirector.com/Characters/Details/'+s.characters[0]);const html=await targetShell.text();const name=await p.evaluate(text=>new DOMParser().parseFromString(text,'text/html').querySelector('h1')?.childNodes[0]?.textContent.trim(),html);assert(name);await p.locator('[data-workspace-target-search]').fill(name.slice(0,50));await p.locator('[data-workspace-target] option[value="'+s.characters[0]+'"]').waitFor({state:'attached'});await p.locator('[data-workspace-target]').selectOption(String(s.characters[0]));const type=await p.locator('[name=RelationshipTypeID] option').evaluateAll(ns=>ns.find(n=>/Family · Parent$/.test(n.textContent))?.value);assert(type);await p.selectOption('[name=RelationshipTypeID]',type);await p.locator('[name=Notes]').fill('Disposable workspace qualification definition');await p.locator('[data-workspace-operation-form] button[type=submit], [data-workspace-operation-form] button:not([type])').first().click();await p.waitForFunction(()=>!document.querySelector('[data-workspace-dialog]').open);await p.locator('[data-relationship-group] > summary').first().click();let row=p.locator('[data-workspace-relationship]').filter({hasText:'Disposable workspace qualification definition'});await row.waitFor();const rid=Number(await row.getAttribute('data-workspace-relationship'));row=p.locator('[data-workspace-relationship="'+rid+'"]');fs.writeFileSync('/tmp/character-refinement-live-fixture.json',JSON.stringify({project:s.project,user:s.user,character:id,relationship:rid}));await p.locator('[data-character-connection="'+rid+'"]').waitFor({state:'attached'});
step='dedicated empty history and exact return';await row.getByRole('link',{name:'History',exact:true}).click();await p.waitForURL(u=>u.pathname==='/Dynamics/Relationship/'+rid);assert.match(await p.locator('main').innerText(),/No recorded events/);assert.equal(await p.locator('.relationship-evolution-chart').count(),0);await p.getByRole('link',{name:'Return to character Relationships'}).click();await p.locator('[data-workspace-relationship="'+rid+'"].is-selected').waitFor();assert.equal(await row.evaluate(n=>n.closest('[data-relationship-group]').open),true);
step='live edit, dirty main navigation guard and archive preview';await row.locator('[data-workspace-operation="definition"]').click();await p.locator('[name=TypeID]').waitFor();const childType=await p.locator('[name=TypeID] option').evaluateAll(ns=>ns.find(n=>/Family · Child$/.test(n.textContent))?.value);assert(childType);await p.locator('[name=TypeID]').selectOption(childType);await p.locator('[name=ReverseDirection][type=checkbox]').check();await p.locator('[name=Notes]').fill('Disposable definition edited');p.once('dialog',d=>d.dismiss());assert.equal(await p.evaluate(()=>window.PlotDirectorCharacterWorkspace.requestLeave(()=>{window.unexpectedLeave=true})),false);assert.equal(await p.evaluate(()=>!!window.unexpectedLeave),false);await p.locator('[data-workspace-operation-form] [type=submit]').click();await p.waitForFunction(()=>!document.querySelector('[data-workspace-dialog]').open);await row.locator('[data-workspace-operation="archive"]').click();await p.locator('[name=Confirmed][type=checkbox]').waitFor();assert.match(await p.locator('[data-workspace-dialog]').innerText(),/0 dependent scene events will be retained/);assert.match(await p.locator('[data-workspace-dialog]').innerText(),/underlying relationship definition/);await p.locator('[name=Confirmed][type=checkbox]').check();await p.locator('[data-workspace-operation-form] [type=submit]').click();await p.waitForFunction(r=>!document.querySelector('[data-workspace-relationship="'+r+'"]'),rid);await p.locator('[data-character-connection="'+rid+'"]').waitFor({state:'detached'});assert.equal(await p.locator('#plotlineConfirmModal').evaluate(n=>n.classList.contains('show')),false);await p.click('[data-character-lens="story"]');await p.waitForFunction(()=>document.querySelector('[data-character-graph-status]').textContent!=='Loading recorded relationships…');
await peer.waitForFunction(()=>workspaceHints===3);await peer.waitForTimeout(400);assert.equal(await peer.evaluate(()=>workspaceHints),3);assert.equal(await peer.locator('[data-context-scene]').inputValue(),String(s.scene));
step='archive only this newly created fixture character';await p.locator('[data-character-ribbon] .dropdown-toggle').click();await p.locator('[data-character-actions-for] form[action*="Archive"] button').click();await p.locator('#plotlineConfirmModal [data-confirm-submit]').click();await p.waitForURL(u=>!u.pathname.endsWith('/Details/'+id));assert.deepEqual(errors,[]);console.log('PASS Development live Character workspace: new isolated Supporting fixture; all five tabs and exact dedicated History/return; canonical initial Parent add and same-ID Child/direction edit; dirty navigation rejection; explicit dependency preview; direct soft archive and Family/Story refresh; exactly one existing Context peer hint per add/edit/archive; newly created fixture character archived. Existing manuscript and baseline fixture relationships untouched.');
}catch(e){console.error('FAILED '+step+': '+e.message);process.exitCode=1;}finally{await b.close();}})();