29 lines
15 KiB
JavaScript
29 lines
15 KiB
JavaScript
// Development-only operational verification. Requires the dedicated empty project from --setup.
|
|
const {chromium}=require('playwright'),fs=require('fs'),assert=require('node:assert/strict');const base='https://dev.plotdirector.com',file=process.argv[2],out='/tmp/pd-refinements-evidence';
|
|
if(!file?.startsWith('/tmp/pd-dev-browser-'))throw Error('Dedicated private fixture identity required');const identity=JSON.parse(fs.readFileSync(file));assert.equal(identity.Database,'PlotDirector_Development');assert(identity.Email.startsWith('pwa-browser-')&&identity.Email.endsWith('@example.invalid'));assert(identity.ProjectID&&identity.BookID);
|
|
(async()=>{const browser=await chromium.launch(),context=await browser.newContext({viewport:{width:1440,height:1000}});await context.addInitScript(user=>localStorage.setItem(`plotdirector.desktop.v1.${user}`,JSON.stringify({dismissedAt:Date.now()})),identity.UserID);const page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));try{
|
|
await page.goto(base+'/Account/Login');await page.locator('[name=Email]').fill(identity.Email);await page.locator('[name=Password]').fill(identity.Password);await page.locator('form button[type=submit]').click();await page.waitForURL(base+'/Projects');const q=`projectId=${identity.ProjectID}`,directory=async()=>{const r=await page.request.get(base+`/LocationWorkspace/Directory?${q}`);assert.equal(r.status(),200);return r.json();};
|
|
await page.goto(base+`/Locations?${q}`);await page.locator('[data-location-records][aria-busy=false]').waitFor();let data=await directory();assert.equal(data.locations.length,0,'Only an empty dedicated fixture may be populated');assert.equal(data.taxonomy.length,105);assert.equal(data.types.length,97);assert(data.types.every(t=>t.value!==''));const type=key=>data.taxonomy.find(t=>t.key===key).value;
|
|
const api=async(action,body)=>page.evaluate(async({action,body})=>{const r=await fetch('/LocationWorkspace/'+action,{method:'POST',headers:{'Content-Type':'application/json','RequestVerificationToken':document.querySelector('[data-location-token] [name=__RequestVerificationToken]').value},body:JSON.stringify(body)});return{status:r.status,body:await r.json()};},{action,body});
|
|
const create=async(name,parentId)=>{const r=await api('Create',{projectId:identity.ProjectID,name,parentId});assert.equal(r.status,200);return r.body.id;};
|
|
const north=await create('Northland acceptance',null),harbour=await create('Harbour acceptance',north),south=await create('Southland acceptance',null),home=await create('Ledger house acceptance',harbour);
|
|
const load=async()=>{await page.goto(base+`/Locations?${q}`);await page.locator('[data-location-records][aria-busy=false]').waitFor();await page.getByRole('button',{name:'Expand all',exact:true}).click();};const row=id=>page.locator(`[data-location-id="${id}"]`);
|
|
const selectType=async(id,key)=>{await row(id).locator('[data-location-name]').click();await page.locator('[data-details]').getByRole('button',{name:'Location type',exact:true}).click();const dialog=page.locator('dialog.pd-location-picker-dialog');await dialog.getByRole('searchbox',{name:'Search location types'}).fill(data.taxonomy.find(t=>t.key===key).label);await dialog.locator(`[data-picker-id="${key}"] .pd-location-picker-name`).click();const saved=page.waitForResponse(r=>r.url().endsWith('/LocationWorkspace/Assign'));await dialog.getByRole('button',{name:'Choose type',exact:true}).click();const result=await saved;assert.equal(result.status(),200,await result.text());await dialog.waitFor({state:'hidden'});await page.waitForFunction(label=>document.querySelector('[data-details] [aria-label="Location type"]')?.textContent===label,data.taxonomy.find(t=>t.key===key).label);data=await directory();assert.equal(data.locations.find(r=>r.id===id).type,type(key));};
|
|
await load();await selectType(north,'city');await selectType(harbour,'residential');await selectType(home,'house');
|
|
const expand=async locator=>{if(await locator.locator('.pd-attribute-expand').getAttribute('aria-expanded')==='false')await locator.locator('.pd-attribute-expand').click();};const attr=key=>page.locator(`[data-attribute=type][data-value="${type(key)}"]`);await expand(page.locator('[data-value="@premises"]'));await expand(attr('residential'));assert.equal(await attr('residential').locator('[data-count]').textContent(),'2');
|
|
await row(harbour).locator('[data-select-location]').check();await row(home).locator('[data-select-location]').check();await expand(attr('commercial'));await attr('pub').locator('[data-assign]').click();await page.waitForTimeout(200);data=await directory();assert(data.locations.filter(r=>[home,harbour].includes(r.id)).every(r=>r.type===type('pub')));await page.locator('[data-undo]').click();await page.waitForTimeout(200);data=await directory();assert.equal(data.locations.find(r=>r.id===home).type,type('house'));assert.equal(data.locations.find(r=>r.id===harbour).type,type('residential'));
|
|
await attr('residential').locator('[data-attribute-filter]').click();assert.match(await page.locator('[data-result-count]').textContent(),/^2 of 4/);await page.getByRole('button',{name:'Cards',exact:true}).click();assert.equal(await page.locator('[data-location-id]').count(),2);await page.locator('[data-clear-filters]').click();await page.getByRole('button',{name:'Hierarchy',exact:true}).click();await page.locator('[data-clear-selection]').click();
|
|
await page.goto(base+`/Locations/Edit/${home}`);await page.locator('[data-alias-input]').fill('Old ledger lodging');await page.locator('[data-add-alias]').click();await page.getByRole('button',{name:'Choose parent location',exact:true}).click();let dialog=page.locator('dialog.pd-location-picker-dialog');await dialog.getByRole('searchbox',{name:'Search locations'}).fill('Southland');await dialog.locator(`[data-picker-id="${south}"] .pd-location-picker-name`).click();await dialog.getByRole('button',{name:'Choose location',exact:true}).click();assert.equal(await page.locator('[name=ParentLocationID]').inputValue(),String(south));await page.getByRole('button',{name:'Save location',exact:true}).click();await page.waitForURL(/\/Locations\/Details\/\d+/);data=await directory();assert.equal(data.locations.find(r=>r.id===home).parent,south);assert(data.locations.find(r=>r.id===home).aliases.includes('Old ledger lodging'));
|
|
await page.goto(base+`/Locations/Create?${q}`);await page.locator('[name=LocationName]').fill('Archive room acceptance');await page.getByRole('button',{name:'Choose parent location',exact:true}).click();dialog=page.locator('dialog.pd-location-picker-dialog');await dialog.getByRole('searchbox',{name:'Search locations'}).fill('Southland');await dialog.locator(`[data-picker-id="${south}"] .pd-location-picker-name`).click();await dialog.getByRole('button',{name:'Choose location',exact:true}).click();await page.getByRole('button',{name:'Location type',exact:true}).click();dialog=page.locator('dialog.pd-location-picker-dialog');await dialog.getByRole('searchbox',{name:'Search location types'}).fill('Kitchen');await dialog.locator('[data-picker-id=kitchen] .pd-location-picker-name').click();await dialog.getByRole('button',{name:'Choose type',exact:true}).click();await page.getByRole('button',{name:'Save location',exact:true}).click();await page.waitForURL(/\/Locations\/Details\/\d+/);const kitchen=Number(page.url().split('/').pop());data=await directory();assert.equal(data.locations.find(r=>r.id===kitchen).type,type('kitchen'));assert.equal(data.locations.find(r=>r.id===kitchen).parent,south);
|
|
await page.goto(base+`/Locations/Details/${home}`);await page.getByRole('button',{name:'Choose related location',exact:true}).click();dialog=page.locator('dialog.pd-location-picker-dialog');assert.equal(await dialog.locator(`[data-picker-id="${home}"]`).getAttribute('aria-disabled'),'true');await dialog.getByRole('searchbox',{name:'Search locations'}).fill('Archive room');await dialog.locator(`[data-picker-id="${kitchen}"] .pd-location-picker-name`).click();await dialog.getByRole('button',{name:'Choose location',exact:true}).click();await page.locator('[name=Notes]').fill('Disposable picker relationship');await page.getByRole('button',{name:'Add relationship',exact:true}).click();await page.waitForLoadState();assert(await page.getByText('Disposable picker relationship',{exact:true}).count());
|
|
await load();await row(home).locator('[data-location-name]').click();await page.getByRole('button',{name:'Change parent',exact:true}).click();dialog=page.locator('[data-location-dialog]');await dialog.getByRole('searchbox',{name:'Search locations'}).fill('Harbour');await dialog.locator(`[data-picker-id="${harbour}"] .pd-location-picker-name`).click();await dialog.locator('[data-dialog-save]').click();await dialog.waitFor({state:'hidden'});data=await directory();assert.equal(data.locations.find(r=>r.id===home).parent,harbour);await page.getByRole('button',{name:'Reveal selected',exact:true}).click();
|
|
await row(home).locator('[data-location-name]').click();await page.getByRole('button',{name:'Change parent',exact:true}).click();dialog=page.locator('[data-location-dialog]');await dialog.getByRole('searchbox',{name:'Search locations'}).fill('Old ledger lodging');assert.equal(await dialog.locator(`[data-picker-id="${home}"]`).getAttribute('aria-disabled'),'true');await page.screenshot({path:out+'/development-picker.png'});await dialog.locator('[data-dialog-cancel]').click();
|
|
await page.locator('[data-clear-selection]').click();await expand(page.locator('[data-value="@premises"]'));await expand(attr('residential'));await attr('house').locator('[data-attribute-filter]').dragTo(row(kitchen));await page.waitForTimeout(200);data=await directory();assert.equal(data.locations.find(r=>r.id===kitchen).type,type('house'));await page.locator('[data-undo]').click();await page.waitForTimeout(200);data=await directory();assert.equal(data.locations.find(r=>r.id===kitchen).type,type('kitchen'));await row(kitchen).locator('[data-drag-location]').dragTo(attr('house'));await page.waitForTimeout(200);data=await directory();assert.equal(data.locations.find(r=>r.id===kitchen).type,type('house'));await page.locator('[data-undo]').click();await page.waitForTimeout(200);
|
|
data=await directory();let r=data.locations.find(r=>r.id===north);assert.equal((await api('Assign',{projectId:identity.ProjectID,attribute:'parent',changes:[{id:north,value:String(home),version:r.version}]})).status,409);r=data.locations.find(r=>r.id===home);assert.equal((await api('Assign',{projectId:identity.ProjectID,attribute:'type',changes:[{id:home,value:'@premises',version:r.version}]})).status,409);
|
|
const duplicate=await create('Ledger alternate acceptance',null);await load();await row(duplicate).getByRole('button',{name:/Actions for/}).click();await page.getByRole('menuitem',{name:'Merge with another location…',exact:true}).click();dialog=page.locator('[data-location-dialog]');await dialog.getByRole('searchbox',{name:'Search locations'}).fill('Old ledger lodging');await dialog.locator(`[data-picker-id="${home}"] .pd-location-picker-name`).click();await dialog.locator('input[type=checkbox]').check();const merged=page.waitForResponse(r=>r.url().endsWith('/LocationWorkspace/Merge'));await dialog.locator('[data-dialog-save]').click();assert.equal((await merged).status(),200);await dialog.waitFor({state:'hidden'});data=await directory();assert.equal(data.locations.length,5);assert.equal(data.locations.find(r=>r.id===home).type,type('house'));assert.equal(data.locations.find(r=>r.id===home).parent,harbour);await page.evaluate(()=>document.querySelectorAll('[data-toast-host] button[aria-label^=Dismiss]').forEach(b=>b.click()));await page.screenshot({path:out+'/development-taxonomy.png'});
|
|
const traditionalDuplicate=await create('Traditional merge acceptance',null);await page.goto(base+`/Locations/Merge/${traditionalDuplicate}`);await page.getByRole('button',{name:'Choose surviving location',exact:true}).click();dialog=page.locator('dialog.pd-location-picker-dialog');await dialog.getByRole('searchbox',{name:'Search locations'}).fill('Old ledger lodging');await dialog.locator(`[data-picker-id="${home}"] .pd-location-picker-name`).click();await page.screenshot({path:out+'/development-merge-picker.png'});await dialog.getByRole('button',{name:'Choose location',exact:true}).click();await page.locator('input[type=checkbox][name="Form.Confirm"]').check();await page.getByRole('button',{name:'Merge location',exact:true}).click();await page.waitForURL(new RegExp(`/Locations/Details/${home}$`));data=await directory();assert.equal(data.locations.length,5);assert.equal(data.locations.find(r=>r.id===home).type,type('house'));
|
|
for(const [name,bio]of [['Acceptance cast one','A complete synthetic biography.'],['Acceptance cast two','A complete synthetic biography. '.repeat(16)]]){await page.goto(base+`/Characters/Create?${q}`);await page.locator('[name=CharacterName]').fill(name);await page.locator('[name=DefaultDescription]').fill(bio);await page.getByRole('button',{name:'Save character',exact:true}).click();await page.waitForURL(/\/Characters\/Details\/\d+/);}
|
|
await page.goto(base+`/Characters?${q}`);await page.locator('[data-attribute=importance]').first().waitFor();const characters=async()=>{const r=await page.request.get(base+`/CharacterAttributes/Directory?${q}`);assert.equal(r.status(),200);return r.json();};const before=(await characters()).characters;assert.equal(before.length,2);await page.locator('[data-select-visible]').click();await page.locator('[data-attribute=importance][data-value="10"] [data-assign]').click();await page.waitForTimeout(200);assert((await characters()).characters.every(r=>r.values.importance==='10'));await page.locator('[data-attribute=importance][data-value="10"] [data-attribute-filter]').click();assert.equal(await page.locator('.character-card:not([hidden])').count(),2);await page.locator('[data-clear-filter]').click();await page.locator('[data-undo]').click();await page.waitForTimeout(200);assert.deepEqual((await characters()).characters.map(r=>r.values),before.map(r=>r.values));assert((await page.locator('.character-card').first().textContent()).includes('A complete synthetic biography.'));const heights=await page.locator('.character-card').evaluateAll(ns=>ns.map(n=>Math.round(n.getBoundingClientRect().height)));assert(new Set(heights).size>1);await page.evaluate(()=>document.querySelectorAll('[data-toast-host] button[aria-label^=Dismiss]').forEach(b=>b.click()));await page.screenshot({path:out+'/development-characters.png'});
|
|
assert.deepEqual(errors,[]);identity.RefinementFixture={north,harbour,south,home,kitchen};fs.writeFileSync(file,JSON.stringify(identity),{mode:0o600});fs.writeFileSync(out+'/development-refinements.json',JSON.stringify({status:'passed',target:'Development',checks:['real canonical 105-entry API','generic and specialised type selection','parent counts include descendants','actual bulk type assignment and exact Undo','type filtering and cards','Edit parent picker and aliases','Create parent/type pickers','Details relationship target picker','workspace parent and alias search','native bidirectional attribute drag and Undo','server cycle and heading rejection','alias-based reviewed merge','traditional merge picker and confirmation','real Characters bulk attributes/filter/Undo','unchanged variable character biographies']},null,2));console.log('PASS authenticated Development picker/taxonomy/shared Attributes forms, mutations and safeguards; dedicated fixture only.');
|
|
}finally{await context.close();await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});
|