26 lines
3.9 KiB
JavaScript
26 lines
3.9 KiB
JavaScript
// Actual Settings, controller, per-user preference store and toast assets; no live DB.
|
|
const {chromium}=require('playwright'),assert=require('node:assert/strict');
|
|
const base=process.env.PD_BROWSER_FIXTURE_URL||'http://127.0.0.1:5238';
|
|
(async()=>{const browser=await chromium.launch();try{for(const standalone of [false,true]){
|
|
const context=await browser.newContext({viewport:{width:1440,height:1000}});if(standalone)await context.addInitScript(()=>Object.defineProperty(navigator,'standalone',{value:true}));
|
|
const page=await context.newPage();await page.goto(base+'/fixture?layout=full');await page.waitForFunction(()=>window.PlotDirector?.toast);
|
|
const choose=page.locator('[data-toast-position-choice]'),host=page.locator('[data-toast-host]');
|
|
assert.deepEqual(await choose.locator('option').allTextContents(),['Bottom left','Bottom right']);
|
|
await page.evaluate(()=>document.querySelector('[data-toolbar-dialog]').classList.add('show'));
|
|
// Bootstrap modal open through its normal API; avoids depending on toolbar visibility.
|
|
await page.evaluate(()=>bootstrap.Modal.getOrCreateInstance(document.querySelector('[data-toolbar-dialog]')).show());
|
|
if(await choose.inputValue()!=='bottom-left'){await choose.selectOption('bottom-left');await page.locator('[data-toast-position-status]').filter({hasText:'saved'}).waitFor();}
|
|
await page.evaluate(()=>{for(const type of ['success','error','info','warning'])PlotDirector.toast[type]('Position '+type,{duration:0});});
|
|
let rect=await host.boundingBox();assert(rect.x<30&&rect.y>400&&rect.y+rect.height<=984);
|
|
const ys=await page.locator('.pd-toast').evaluateAll(nodes=>nodes.sort((a,b)=>Number(a.style.order)-Number(b.style.order)).map(n=>n.getBoundingClientRect().y));assert(ys[0]>ys[1]&&ys[1]>ys[2]&&ys[2]>ys[3],'mixed categories stack upwards in arrival order');
|
|
const sibling=await context.newPage();await sibling.goto(base+'/fixture?layout=full');await sibling.waitForFunction(()=>window.PlotDirector?.toast);
|
|
let release;await page.route('**/Appearance/ToastPosition',async route=>{await new Promise(resolve=>release=resolve);await route.continue();});
|
|
await choose.selectOption('bottom-right');assert.equal(await host.getAttribute('data-toast-position'),'bottom-right','active host moves before network save');while(!release)await page.waitForTimeout(10);release();await page.locator('[data-toast-position-status]').filter({hasText:'saved'}).waitFor();await page.unroute('**/Appearance/ToastPosition');
|
|
await sibling.waitForFunction(()=>document.querySelector('[data-toast-host]').dataset.toastPosition==='bottom-right');
|
|
const fresh=await browser.newContext(),freshPage=await fresh.newPage();await freshPage.goto(base+'/fixture?layout=full');assert.equal(await freshPage.locator('[data-toast-host]').getAttribute('data-toast-position'),'bottom-right','server preference survives a new browser session');await fresh.close();
|
|
await page.setViewportSize({width:390,height:844});rect=await host.boundingBox();assert(rect.x>=15&&rect.x+rect.width<=375&&rect.y+rect.height<=772,'narrow viewport reserves bottom controls/margins: '+JSON.stringify(rect));
|
|
await page.route('**/Appearance/ToastPosition',r=>r.fulfill({status:500,body:'Synthetic failure'}));await choose.selectOption('bottom-left');await page.locator('[data-toast-position-status]').filter({hasText:'Could not save'}).waitFor();assert.equal(await host.getAttribute('data-toast-position'),'bottom-right','failed save restores previous choice');
|
|
await page.unroute('**/Appearance/ToastPosition');await choose.selectOption('bottom-left');await page.locator('[data-toast-position-status]').filter({hasText:'saved'}).waitFor();
|
|
console.log('PASS toast Settings: exactly two choices, bottom-left default, immediate move, upward mixed stack, server/new-session and cross-window persistence, failure rollback, mobile bounds; standalone='+standalone);await context.close();
|
|
}}finally{await browser.close();}})().catch(e=>{console.error(e.stack);process.exitCode=1});
|