PlotDirector/PlotLine.Tests/Browser/writer-navigation-themes.cjs

55 lines
4.1 KiB
JavaScript

// Production Razor layouts and shared theme tokens; isolated fixture repositories.
const {chromium}=require('playwright');
const assert=require('node:assert/strict');
const base='http://127.0.0.1:5238';
(async()=>{const browser=await chromium.launch();try{
for(const pwa of [false,true]){
const context=await browser.newContext();
if(pwa)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
const page=await context.newPage();
await page.goto(base+'/fixture?page=writer&layout=full&bookId=12');
const nav=page.locator('#ribbon-tab-writer');
assert.equal(await nav.count(),1);
assert.equal(await nav.getAttribute('aria-selected'),'true');
assert.equal(await nav.getAttribute('data-ribbon-tab'),'writer');
const home=page.locator('#ribbon-panel-writer a[data-command-operation="writer.index"]');
assert.equal(new URL(await home.getAttribute('href'),base).searchParams.get('projectId'),'7');
assert.equal(new URL(await home.getAttribute('href'),base).searchParams.get('bookId'),'12');
assert.equal(await page.locator('#ribbon-panel-story a').filter({hasText:/^Writer$/}).count(),0);
assert.equal(await page.locator('#appStoryMenu + ul a').filter({hasText:/Writer/}).count(),0);
assert(await nav.evaluate(a=>a.nextElementSibling?.dataset.ribbonTab==='story'));
for(const embedded of [false,true])for(const role of ['Context','Intent']){
await page.goto(base+`/Writing/${role}?bookId=12${embedded?'&embedded=true':''}`);
// Exercise real populated cards and controls without a database or native session.
const fragment=await (await page.request.get(base+`/writing-desk-fixture/${role.toLowerCase()}?fragment=true`)).text();
await page.locator(`[data-writing-${role.toLowerCase()}-content]`).evaluate((el,html)=>el.innerHTML=html,fragment);
if(role==='Intent')await page.locator('.writing-workspace-role-indicator span').evaluate(el=>el.textContent='Saved PlotDirector snapshot · manual navigation · no automatic save');
const sender=await context.newPage();await sender.goto(base+'/fixture');
for(const theme of ['modern-light','modern-dark','warm-light','warm-dark']){
await sender.evaluate(theme=>localStorage.setItem('plotdirector.applicationTheme',theme),theme);
await page.waitForFunction(theme=>document.documentElement.dataset.appTheme===theme,theme);
for(const width of [390,1440]){
await page.setViewportSize({width,height:1000});
const result=await page.evaluate(()=>{
const main=document.querySelector('.writing-context-page'),card=main.querySelector('.writing-context-card');
const probe=document.createElement('span');main.append(probe);
const resolve=token=>{probe.style.color=`var(${token})`;return getComputedStyle(probe).color;};
const result={body:getComputedStyle(document.body).backgroundColor,workspace:resolve('--pd-workspace'),text:getComputedStyle(main).color,expectedText:resolve('--pd-text'),card:getComputedStyle(card).backgroundColor,surface:resolve('--pd-surface'),overflow:document.documentElement.scrollWidth>innerWidth+2};probe.remove();return result;
});
assert.equal(result.body,result.workspace,`${role} ${theme} background`);
assert.equal(result.text,result.expectedText,`${role} ${theme} text`);
assert.equal(result.card,result.surface,`${role} ${theme} card`);
assert.equal(result.overflow,false,`${role} ${theme} ${width} overflow`);
const active=page.locator('.writing-context-tabs button.active');
if(await active.count())assert(await active.evaluate(el=>{
const probe=document.createElement('span');el.append(probe);probe.style.color='var(--pd-on-accent)';const expected=getComputedStyle(probe).color;probe.remove();return getComputedStyle(el).color===expected;
}),`${role} ${theme} selected text`);
}
}
await sender.close();
}
await context.close();
}
console.log('PASS Writer shared section selection/order/context/active state, Story removal; Context and Intent shared palettes and live cross-window changes in all four themes, browser/PWA, full/embedded and 390/1440 layouts.');
}finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;});