2026-09-24 16:10:08 +03:00
const assert = require ( 'node:assert/strict' );
( async ()=>{ const browser = await require ( './support/browser.cjs' ). launchBrowser (); try {
2026-09-24 14:35:05 +03:00
const page = await browser . newPage ({ viewport : { width : 1440 , height : 1000 }}), errors = []; page . on ( 'pageerror' , e => errors . push ( e . message ));
2026-10-07 13:28:43 +01:00
await page . goto ( 'http://127.0.0.1:3000/?view=configuration' ); await page . getByLabel ( 'Username' ,{ exact : true }). fill ( 'alice' ); await page . getByLabel ( 'Password' ,{ exact : true }). fill ( await require ( './support/browser.cjs' ). demoPassword ()); await page . getByRole ( 'button' ,{ name : 'Sign in' , exact : true }). click ();
2026-09-24 14:35:05 +03:00
await page . getByRole ( 'button' ,{ name : 'Edit rule Project owners during working hours' , exact : true }). click ();
const panel = page . locator ( '.rule-result' ); const ready = ()=> page . waitForFunction (()=>{ const a = Alpine . $data ( document . body ); return ! a . generationLoading && a . generationResult ;}); await ready ();
assert . equal ( await panel . locator ( '.rule-result-row' ). count (), 18 ); const text = await panel . innerText (); assert . match ( text , /Payments/ ); assert . match ( text , /Alice Morgan/ ); assert . match ( text , /Time off/ ); assert . match ( text , /Escalation/ ); assert . match ( text , /Routing/ ); await panel . screenshot ({ path : 'test-results/rule-result.png' });
// A rule with escalation outputs only remains visible and resolves a manual target.
await page . evaluate (()=>{ const a = Alpine . $data ( document . body ); a . form . blocks = a . form . blocks . filter ( b => b . kind === 'escalation' ); a . form . blocks [ 0 ]. steps [ 0 ]. recipient = a . literal ( a . doc . schedules . find ( s => s . name === 'Time off' ). id );}); await ready (); assert . equal ( await panel . locator ( '.rule-result-row' ). count (), 6 );
await page . evaluate (()=>{ Alpine . $data ( document . body ). form . enabled = false ;}); await ready (); assert . match ( await panel . innerText (), /Rule disabled/ ); assert . equal ( await panel . locator ( '.rule-result-row' ). count (), 0 );
await page . evaluate (()=>{ const a = Alpine . $data ( document . body ); a . form . enabled = true ; a . form . blocks [ 0 ]. steps [ 0 ]. delay = a . literal ( 'broken' );}); await ready (); assert . match ( await panel . innerText (), /Check the configuration errors/ ); assert . equal ( await panel . locator ( '.rule-result-row' ). count (), 0 );
await page . evaluate (()=>{ const a = Alpine . $data ( document . body ); a . form . blocks [ 0 ]. steps [ 0 ]. delay = a . literal ( 0 ); a . form . when = { left : a . literal ( 'a' ), operation : 'equals' , right : a . literal ( 'b' )};}); await ready (); assert . match ( await panel . innerText (), /No resources/ );
await page . setViewportSize ({ width : 390 , height : 844 }); await panel . screenshot ({ path : 'test-results/rule-result-mobile.png' }); assert . equal ( await page . evaluate (()=> document . documentElement . scrollWidth > innerWidth ), false ); assert . deepEqual ( errors ,[]); console . log ( 'PASS server-generated rule results: all types, resolved names, escalation-only, disabled, invalid, filtered and mobile' );
} finally { await browser . close ();}})(). catch ( e =>{ console . error ( e ); process . exitCode = 1 ;});