PlotDirector/PlotLine.Tests/Browser/character-ribbon.cjs

12 lines
5.1 KiB
JavaScript

const {chromium}=require('playwright'),assert=require('assert/strict'),fs=require('fs'),os=require('os'),path=require('path');
(async()=>{const installed=process.argv.includes('--installed'),base='http://127.0.0.1:5238',profile=installed?fs.mkdtempSync(path.join(os.tmpdir(),'pd-ribbon-pwa-')):null,b=installed?null:await chromium.launch(),c=installed?await chromium.launchPersistentContext(profile,{headless:false,viewport:{width:1920,height:1080}}):await b.newContext({viewport:{width:1920,height:1080}});let p=installed?c.pages()[0]:await c.newPage(),cdp;try{
await c.route('https://cdn.jsdelivr.net/**',r=>r.fulfill({contentType:'application/javascript',body:fs.readFileSync(path.join(__dirname,'node_modules',r.request().url().includes('chart.umd')?'chart.js/dist/chart.umd.js':'@microsoft/signalr/dist/browser/signalr.min.js'))}));
if(installed){await p.goto(base+'/fixture?page=calendar-test');cdp=await c.browser().newBrowserCDPSession();await cdp.send('PWA.install',{manifestId:base+'/Projects',installUrlOrBundleUrl:p.url()});await cdp.send('PWA.changeAppUserSettings',{manifestId:base+'/Projects',displayMode:'standalone'});const opened=c.waitForEvent('page');await cdp.send('PWA.launch',{manifestId:base+'/Projects',url:p.url()});p=await opened;await p.waitForLoadState();assert(await p.evaluate(()=>matchMedia('(display-mode: standalone)').matches));}
const errors=[];p.on('pageerror',e=>errors.push(e.message));let archivePosts=0;await p.route('**/Characters/Archive',r=>{archivePosts++;return r.fulfill({contentType:'text/html',body:'<p>Disposable archive endpoint</p>'})});
for(const tab of ['overview','relationships','evolution','appearances','knowledge']){await p.goto(base+'/character-workspace-fixture?tab='+tab);await p.setViewportSize({width:1920,height:1080});const group=p.locator('[data-character-ribbon]');assert.deepEqual((await group.locator('.pd-ribbon-command span').allTextContents()).filter(text=>text!=='More'),['Edit Character','Merge Character','Reanalyse Biography','Archive Character']);assert.deepEqual(await p.locator('#ribbon-panel-characters > .pd-ribbon-group').evaluateAll(nodes=>nodes.map(n=>n.getAttribute('aria-label'))),['Cast','Connections','Selected character','Output','Focus']);assert.match(await group.getByRole('link',{name:'Merge Character',exact:true}).getAttribute('href'),/Characters\/Merge\/5/);assert.match(await group.locator('[data-character-reanalyse-form]').getAttribute('action'),/Characters\/Reanalyse/);assert.equal(await group.locator('[data-character-reanalyse-button] svg').count(),1);await p.getByRole('button',{name:'Export',exact:true}).click();const menu=p.locator('[data-character-actions-for="5"]');await menu.waitFor({state:'visible'});assert.deepEqual(await menu.locator('.dropdown-item').allTextContents(),['Export character','Markdown']);assert.equal(await menu.locator('form').count(),0);await p.keyboard.press('Escape');}
await p.locator('[data-character-ribbon] form[action*=Archive] button').click();await p.locator('#plotlineConfirmModal.show').waitFor();assert((await p.locator('[data-character-ribbon] form[action*=Archive]').getAttribute('data-confirm-message')).includes('data will be retained for restoration'));assert((await p.locator('#plotlineConfirmModal').innerText()).toLowerCase().includes('archiv'));assert.equal(archivePosts,0);await p.locator('#plotlineConfirmModal').getByRole('button',{name:'Cancel',exact:true}).last().click();await p.locator('#plotlineConfirmModal').waitFor({state:'hidden'});assert.equal(archivePosts,0);
const out='/tmp/pd-ui-refinements';fs.mkdirSync(out,{recursive:true});for(const theme of ['plotdirector','modern-light','modern-dark','warm-light','warm-dark','rose-pink','baby-blue']){await p.evaluate(theme=>{document.documentElement.dataset.appTheme=theme;document.documentElement.dataset.bsTheme=theme.endsWith('dark')?'dark':'light';document.documentElement.dataset.theme=theme.endsWith('dark')?'dark':'light';},theme);await p.screenshot({path:`${out}/ribbon-${installed?'pwa':'browser'}-${theme}.png`});}
for(const width of [1280,1920,2560,3840,768,390]){await p.setViewportSize({width,height:1080});await p.getByRole('button',{name:'Export',exact:true}).click();await p.locator('[data-character-actions-for="5"]').waitFor({state:'visible'});assert(await p.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+2));await p.keyboard.press('Escape');}
await p.goto(base+'/character-workspace-fixture?viewer=true');assert.equal(await p.locator('[data-character-ribbon]').count(),0);await p.getByRole('button',{name:'Export',exact:true}).click();assert.equal(await p.locator('[data-character-actions-for] .dropdown-item').count(),2);assert.deepEqual(errors,[]);console.log('PASS Character Details ribbon across all five tabs, direct merge/AI/archive, retained archive confirmation, export-only Output, read-only permissions, all themes, responsive widths and '+(installed?'installed PWA':'browser'));
}finally{if(cdp)await cdp.send('PWA.uninstall',{manifestId:base+'/Projects'}).catch(()=>{});await c.close();if(b)await b.close();if(profile)fs.rmSync(profile,{recursive:true,force:true});}})().catch(e=>{console.error(e.name+': '+e.message.split('Call log:')[0]);process.exitCode=1});