4 lines
4.7 KiB
JavaScript
4 lines
4.7 KiB
JavaScript
const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path');const base=process.env.PD_BROWSER_BASE||'http://127.0.0.1:5238';
|
|
(async()=>{const b=await chromium.launch();try{const c=await b.newContext({viewport:{width:1366,height:1000}});await c.route('**/cdn.jsdelivr.net/**signalr*',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(path.join(__dirname,'node_modules/@microsoft/signalr/dist/browser/signalr.min.js'))}));await c.route('**/native-companion/status',r=>r.fulfill({json:[]}));await c.route('**/native-companion/connection-state',r=>r.fulfill({json:{known:false}}));let protectedSource=false;await c.route('**/Characters/Workspace/Operation/*',async r=>{if(r.request().method()==='POST'){await r.fulfill({json:{saved:true,message:'One canonical event saved.'}});return;}const u=new URL(r.request().url());u.searchParams.set('protected',String(protectedSource));await r.fulfill({response:await r.fetch({url:base+'/character-workspace-operation-fixture'+u.search})});});const 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());for(const count of [0,1,5]){await p.setViewportSize({width:1366,height:1000});await p.goto(base+'/relationship-evolution-fixture?count='+count);await p.locator('[data-relationship-evolution="9"]').waitFor();await p.evaluate(()=>{document.documentElement.dataset.appTheme='warm-dark';document.documentElement.dataset.theme='dark';document.documentElement.dataset.bsTheme='dark'});assert.equal(await p.locator('[data-evolution-event]').count(),count);assert.equal(await p.locator('.relationship-evolution-chart').count(),count>1?1:0);assert.equal(await p.locator('.dynamics-timeline').count(),0);if(count===0)assert.match(await p.locator('main').innerText(),/No recorded events/);if(count===1)assert.match(await p.locator('main').innerText(),/One recorded event/);if(count===5){assert.deepEqual(await p.locator('[data-evolution-event]').evaluateAll(ns=>ns.map(n=>Number(n.dataset.evolutionEvent))),[1,2,3,4,5]);assert.equal(await p.locator('.relationship-evolution-chart circle').count(),4);await p.locator('.relationship-evolution-chart a').first().click();assert.match(p.url(),/#event-1/);await p.screenshot({path:'/tmp/relationship-evolution-dark-desktop.png',fullPage:true});}for(const width of [1366,1024,768,390]){await p.setViewportSize({width,height:1000});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));}assert.match(await p.getByRole('link',{name:'Return to character Relationships'}).getAttribute('href'),/Characters\/Details\/5.*relationshipId=9/);}
|
|
await p.locator('[data-history-operation="event-edit"]').first().click();await p.locator('[data-workspace-operation-form]').waitFor();assert.match(await p.locator('[data-history-dialog]').innerText(),/one recorded development/);await p.locator('[name=Notes]').fill('Unsaved event draft');p.once('dialog',d=>d.dismiss());await p.keyboard.press('Escape');assert(await p.locator('[data-history-dialog]').evaluate(n=>n.open));p.once('dialog',d=>d.accept());await p.locator('[data-workspace-cancel]').click();let refreshes=0,navigations=0;p.on('request',r=>{if(r.url().includes('/relationship-evolution-fixture'))refreshes++;});p.on('load',()=>navigations++);await p.locator('[data-history-operation="event-edit"]').first().click();await p.locator('[name=Notes]').fill('Saved event draft');await p.locator('[data-workspace-operation-form] [type=submit]').click();await p.waitForFunction(()=>!document.querySelector('[data-history-dialog]').open);await p.locator('.pd-toast').filter({hasText:'One canonical event saved.'}).waitFor();await p.waitForTimeout(150);assert(refreshes>0);assert.equal(navigations,0);protectedSource=true;await p.locator('[data-history-operation="event-remove"]').first().click();await p.locator('[data-workspace-operation-form]').waitFor();assert.match(await p.locator('[data-history-dialog]').innerText(),/Direct modification\/removal is blocked/);assert.equal(await p.locator('[data-workspace-operation-form] [type=submit]').count(),0);await p.locator('[data-workspace-cancel]').click();await p.goto(base+'/relationship-evolution-fixture?count=1&viewer=true');assert.equal(await p.locator('[data-history-operation]').count(),0);assert.deepEqual(errors,[]);console.log('PASS relationship Evolution: empty/single/multiple canonical histories, dark theme bounded intensity chart without invented missing values, chronological source links, exact return identity, desktop/laptop/tablet/mobile, event modal draft/Escape/source protection and Viewer permissions.');}finally{await b.close();}})().catch(e=>{console.error(e);process.exitCode=1});
|