const assert=require('node:assert/strict'); const fs=require('node:fs'); const {launchBrowser}=require('./support/browser.cjs'); const base=process.env.MEGURI_BROWSER_URL||'http://127.0.0.1:3000'; assert(['localhost','127.0.0.1'].includes(new URL(base).hostname)); (async()=>{ const browser=await launchBrowser(); try { const page=await browser.newPage({locale:'en-US',viewport:{width:1280,height:900}}); const errors=[];page.on('pageerror',e=>errors.push(e.message)); await page.goto(base); await page.getByRole('button',{name:'New here? Create an account'}).click(); await page.getByLabel('Username',{exact:true}).fill('generation-team-'+Date.now()); await page.getByLabel('Display name',{exact:true}).fill('Path tester'); await page.getByLabel('Password',{exact:true}).fill('local-browser-test-password'); await page.getByLabel('Email address',{exact:true}).fill('browser-'+Date.now()+'-'+Math.random().toString(16).slice(2)+'@example.com');await page.getByRole('button',{name:'Create account',exact:true}).click(); await page.getByRole('button',{name:'New workspace',exact:true}).click(); const dialog=page.getByRole('dialog'); await dialog.getByLabel('Name',{exact:true}).fill('Team escalation regression'); await dialog.getByRole('button',{name:'Save changes',exact:true}).click(); await dialog.waitFor({state:'hidden'}); await page.evaluate(()=>{const a=Alpine.$data(document.body);a.editGenerationRule();a.form.name='Team escalation';a.form.blocks=[a.newBlock('escalation')];}); await dialog.getByLabel('Recipient type',{exact:true}).selectOption('team_all'); await dialog.getByLabel('Delay in minutes',{exact:true}).fill('30'); await page.waitForFunction(()=>{const a=Alpine.$data(document.body);return !a.generationLoading && a.generationResult?.result?.escalations.some(e=>e.steps.some(s=>s.recipient.type==='team_all' && s.delay_minutes===30));}); assert.equal(await dialog.locator('.generation-step .binding-button.grow:visible').count(),0); await dialog.getByLabel('Recipient type',{exact:true}).selectOption('team_random'); await page.waitForFunction(()=>{const a=Alpine.$data(document.body);return !a.generationLoading && a.generationResult?.result?.escalations.some(e=>e.steps.some(s=>s.recipient.type==='team_random' && s.delay_minutes===30));}); assert.equal(await dialog.locator('.generation-step .binding-button.grow:visible').count(),0); await dialog.getByRole('button',{name:'Use in draft',exact:true}).click(); await dialog.waitFor({state:'hidden'}); await page.waitForFunction(()=>{const a=Alpine.$data(document.body);return !a.generationSaving && !a.generationUnsaved();}); await page.reload(); await page.waitForFunction(()=>Alpine.$data(document.body).generationDraft?.rules.length); await page.evaluate(()=>{const a=Alpine.$data(document.body);a.editGenerationRule(a.generationDraft.rules[0]);}); assert.equal(await dialog.getByLabel('Recipient type',{exact:true}).inputValue(),'team_random'); assert.equal(await dialog.getByLabel('Delay in minutes',{exact:true}).inputValue(),'30'); await page.setViewportSize({width:390,height:844}); await dialog.getByLabel('Recipient type',{exact:true}).scrollIntoViewIfNeeded(); fs.mkdirSync('test-results',{recursive:true});await page.screenshot({path:'test-results/generation-team-mobile.png'}); assert(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)); assert.deepEqual(errors,[]); console.log('PASS: generated team recipient, 30-minute delay, server expansion, shared persistence and mobile'); }finally{await browser.close();} })().catch(e=>{console.error(e);process.exitCode=1;});