PlotDirector/PlotLine.Tests/Browser/writer-ribbon-style.cjs

35 lines
2.4 KiB
JavaScript

// Compare real rendered chrome, including legacy dark link rules and keyboard focus.
const {chromium}=require('playwright');
const assert=require('node:assert/strict');
(async()=>{
const browser=await chromium.launch();
const style=locator=>locator.evaluate(el=>{const s=getComputedStyle(el);return Object.fromEntries(['color','backgroundColor','fontWeight','borderRadius','outlineColor','outlineStyle','outlineWidth','outlineOffset','textDecorationLine'].map(key=>[key,s[key]]));});
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();
for(const theme of ['modern-light','modern-dark','warm-light','warm-dark']){
await page.goto('http://127.0.0.1:5238/fixture?page=writer&layout=full&bookId=12');
await page.evaluate(theme=>window.PlotDirectorApplyApplicationTheme(theme),theme);
await page.waitForFunction(theme=>document.documentElement.dataset.appTheme===theme,theme);
const writer=page.locator('#ribbon-tab-writer'),project=page.locator('#ribbon-tab-project'),book=page.locator('#ribbon-tab-book');
assert.equal(await writer.getAttribute('data-ribbon-tab'),'writer');
await page.mouse.move(0,0);const activeWriter=await style(writer);
await project.click();await page.mouse.move(0,0);await project.evaluate(el=>el.blur());
assert.equal(await writer.getAttribute('aria-selected'),'false');
assert.deepEqual(await style(writer),await style(book),`${theme} inactive`);
assert.deepEqual(activeWriter,await style(project),`${theme} active`);
await writer.hover();const hoverWriter=await style(writer);await book.hover();
assert.deepEqual(hoverWriter,await style(book),`${theme} hover`);
await page.mouse.move(0,0);await page.keyboard.press('Tab');await writer.focus();
assert(await writer.evaluate(el=>el.matches(':focus-visible')));
const focusWriter=await style(writer);await book.focus();
assert.deepEqual(focusWriter,await style(book),`${theme} focus`);
assert.equal(await writer.evaluate(n=>n.tagName),'BUTTON','Writer shares the section selector control');
}
await context.close();
}
console.log('PASS Writer ribbon styles: inactive, active, hover and keyboard focus match standard tabs in all four themes, browser and simulated PWA');
}finally{await browser.close();}
})().catch(error=>{console.error(error);process.exitCode=1;});