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

20 lines
3.8 KiB
JavaScript

// Real auth, Razor, SQL and existing persisted enrichment snapshots. Disposable fixture only.
const {chromium}=require('playwright'),fs=require('node:fs'),assert=require('node:assert/strict');
const base=process.env.PD_SHARED_FOCUS_URL||'http://127.0.0.1:5258';
(async()=>{const who=JSON.parse(fs.readFileSync(process.env.PD_CONTEXT_IDENTITY)),scope=JSON.parse(fs.readFileSync('/tmp/shared-focus-browser-scope.json')),cases=JSON.parse(fs.readFileSync(process.env.PD_CHARACTER_OVERVIEW_CASES));assert.equal(who.Database,'PlotDirector_Development');assert.equal(who.UserID,scope.user);
const browser=await chromium.launch();let step='login';try{const c=await browser.newContext({viewport:{width:1450,height:1000}});const errors=[];c.on('page',p=>p.on('pageerror',e=>errors.push(e.message)));
await c.route('**/signalr.min.js',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(require.resolve('@microsoft/signalr/dist/browser/signalr.min.js'),'utf8')}));
const p=await c.newPage();await p.addLocatorHandler(p.locator('[data-desktop-continue]'),n=>n.click());await p.goto(base+'/Account/Login');await p.fill('[name=Email]',who.Email);await p.fill('[name=Password]',who.Password);await Promise.all([p.waitForURL(u=>u.pathname!='/Account/Login'),p.locator('button[type=submit]').click()]);
async function overview(id){await p.goto(`${base}/Characters/Details/${id}`);await p.waitForSelector('[data-character-tab-content="overview"]');}
for(const [name,id]of Object.entries(cases)){step=name;await overview(id);assert.equal(await p.locator('[data-character-generated-analysis]').count(),['distinctAnalysis','analysisOnly'].includes(name)?1:0);
assert.equal(await p.locator('[data-character-analysis-dob],[data-character-analysis-age],[data-character-analysis-height],[data-character-analysis-eye]').count(),0);
for(const title of ['Profile','Biography and description','Known names','At a glance','Recent recorded changes'])assert.equal(await p.getByRole('heading',{name:title,exact:true}).count(),1);
if(name==='duplicate'){assert((await p.locator('.character-long-text').first().innerText()).length>500,'actual recorded biography remains visible');}
for(const width of [1450,900,390]){await p.setViewportSize({width,height:1000});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));}await p.setViewportSize({width:1450,height:1000});
}
step='canonical biography editor preserves retained distinct analysis';await overview(cases.distinctAnalysis);const before=await p.locator('[data-character-analysis-summary]').innerText();await p.getByRole('link',{name:'Edit profile and background'}).click();await p.waitForSelector('[name=DefaultDescription]');await p.fill('[name=DefaultDescription]','Author edited disposable biography.');await Promise.all([p.waitForURL(u=>u.pathname.includes('/Characters/Details/')),p.locator('form[action="/Characters/Save"] button[type=submit]').click()]);await p.waitForSelector('[data-character-tab-content="overview"]');assert.equal(await p.locator('.character-long-text').first().innerText(),'Author edited disposable biography.');assert.equal(await p.locator('[data-character-analysis-summary]').innerText(),before);
step='other tabs remain usable';for(const tab of ['relationships','evolution','appearances','knowledge','overview']){await p.click(`[data-character-tab="${tab}"]`);await p.waitForSelector(`[data-character-tab-content="${tab}"]`);}assert.equal(await p.locator('[data-character-reanalyse-form]').count(),1);
assert.deepEqual(errors,[]);console.log('PASS real Development Character Overview: duplicate actual-data copy, distinct/biography-only/analysis-only/neither, Profile fields once, responsive layout, canonical biography edit preserves analysis, all tabs and reanalysis action retained; no AI queued.');
}catch(e){console.error('FAILED '+step+': '+e.stack);process.exitCode=1;}finally{await browser.close();}})();