9 lines
6.1 KiB
JavaScript
9 lines
6.1 KiB
JavaScript
// Opt-in Development acceptance; only the explicitly disposable qualification characters may be edited.
|
|
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)),scope=JSON.parse(fs.readFileSync(process.env.PD_CONTEXT_SCOPE));assert.equal(who.Database,'PlotDirector_Development');assert.equal(who.UserID,scope.user);assert(who.Email.startsWith('pwa-browser-'));assert.equal(scope.characters.length,2);const b=await chromium.launch();let step='login';try{const pages=[],counts=[];for(let i=0;i<2;i++){const c=await b.newContext({viewport:{width:1366,height:1000}}),p=await c.newPage();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()]);if(i===0&&process.env.PD_CONTEXT_PREPARE_FAMILY==='1'){step='prepare isolated physical-presence fixture';await p.goto('https://dev.plotdirector.com/Scenes/SceneCharactersEditor?sceneId='+scope.scene);const ids=await p.locator('input[name$=".CharacterID"]').evaluateAll(ns=>ns.map(n=>Number(n.value)));assert.deepEqual([...ids].sort((a,b)=>a-b),[...scope.characters].sort((a,b)=>a-b));assert.equal(Number(await p.locator('[name=SceneID]').inputValue()),scope.scene);for(let row=0;row<ids.length;row++){const presence=p.locator(`[name="Characters[${row}].PresenceTypeID"]`),present=await presence.locator('option').evaluateAll(ns=>ns.find(n=>n.textContent.trim()==='Present')?.value);assert(present);await presence.selectOption(present);const role=p.locator(`[name="Characters[${row}].RoleInSceneTypeID"]`);if((await role.locator('option:checked').innerText()).trim()==='Mentioned Only'){const physicalRole=await role.locator('option').evaluateAll(ns=>ns.find(n=>n.value&&n.textContent.trim()!=='Mentioned Only')?.value);assert(physicalRole);await role.selectOption(physicalRole);}}await p.locator(`[name=POVCharacterID][value="${scope.characters[0]}"]`).check();await Promise.all([p.waitForURL(u=>u.pathname==='/Scenes/SaveSceneCharacters'),p.locator('[data-scene-editor-save]').click()]);assert.equal(JSON.parse(await p.locator('body').innerText()).success,true);step='login';}const counter={hubs:0,word:0};counts.push(counter);p.on('request',r=>{if(r.url().includes('/hubs/native-companion/negotiate'))counter.hubs++;if(/\/(Writing\/Context|WriterWord)\/Navigate/.test(new URL(r.url()).pathname))counter.word++;});await p.goto('https://dev.plotdirector.com/Writing/Context?'+new URLSearchParams({projectId:scope.project,bookId:scope.book,sceneId:scope.scene}));await p.selectOption('[data-context-tab]','relationships');await p.locator('[data-family-key]').first().waitFor();await p.locator('[data-graph-node]').first().waitFor();await p.waitForFunction(()=>document.querySelector('[data-context-workspace]').contextController.connection?.state==='Connected');await p.evaluate(()=>{window.successes=0;const before=PlotDirector.toast.success;PlotDirector.toast.success=(...a)=>{successes++;before(...a);};});pages.push(p);}
|
|
const [p,remote]=pages;async function index(page){return page.evaluate(async args=>{const response=await fetch('/Writing/Context/Relationships/FamilyIndex?'+new URLSearchParams(args));if(!response.ok)throw Error('Index read failed');return response.json();},{bookId:scope.book,sceneId:scope.scene});}let current=await index(p);assert(scope.characters.every(id=>current.groups.some(g=>g.sceneMembers.includes(id))),'both qualification characters must be explicitly eligible scene participants');const merged=()=>current.groups.some(g=>scope.characters.every(id=>g.sceneMembers.includes(id)));
|
|
async function save(){await p.locator('[data-context-edit-form] [type=submit]').click();await p.waitForFunction(()=>!document.querySelector('[data-context-edit-dialog]').open);}
|
|
if(!merged()){step='focused family connection groups two scene entries';await p.locator('[data-relationship-add]').click();await p.waitForSelector('[data-context-edit-form]');await p.selectOption('[name=SourceID]',String(scope.characters[0]));await p.selectOption('[name=TargetID]',String(scope.characters[1]));const type=await p.locator('[name=TypeID] option').evaluateAll(ns=>ns.find(n=>n.value&&/Parent/.test(n.textContent))?.value);assert(type);await p.selectOption('[name=TypeID]',type);const state=await p.locator('[name=StateID] option').evaluateAll(ns=>ns.find(n=>n.value)?.value);if(state)await p.selectOption('[name=StateID]',state);await p.locator('[name=Notes]').fill('Synthetic family grouping qualification');await save();await remote.waitForFunction(()=>document.querySelectorAll('[data-family-key]').length===1);current=await index(p);assert(merged());}
|
|
step='focused family correction persists and refreshes quiet peer';for(const page of pages){await page.locator(`[data-graph-node="${scope.characters[0]}"]`).click();await page.locator('[data-relationship-details] details summary').click();await page.locator('[data-inspect-connection]').first().click();}await p.locator('[data-relationship-details] [data-context-relationship-edit]').click();await p.waitForSelector('[data-context-edit-form]');const note='Synthetic family source correction '+Date.now();await p.locator('[name=Notes]').fill(note);await save();await remote.waitForFunction(note=>document.querySelector('[data-relationship-details]').textContent.includes(note),note);assert.equal(await remote.evaluate(()=>successes),0);assert(await p.evaluate(()=>successes)>=1);assert(counts.every(c=>c.hubs===1&&c.word===0));assert.equal(await p.locator('[data-context-scene]').inputValue(),String(scope.scene));console.log('PASS Development Family editing: authorised scene index and one tree; focused canonical family add/inspection/correction, membership regrouping, persisted notes, quiet receiving window, one SignalR connection per Context, no Word navigation. Disposable qualification characters only.');
|
|
}catch(e){console.error('FAILED '+step+': '+e.message);process.exitCode=1;}finally{await b.close();}})();
|