// All APIs are mocked. This check creates no real invites or emails. const assert = require('node:assert/strict') const { chromium } = require(process.env.REVIEW_PLAYWRIGHT || 'playwright') const base = process.env.REVIEW_BASE || 'http://127.0.0.1:3101' ;(async () => { const browser = await chromium.launch({ headless: true }) try { const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } }) await context.addCookies([{ name: 'magent_logged_in', value: '1', url: base }]) await context.route('**/api/**', route => { const path = new URL(route.request().url()).pathname const user = { username: 'member', role: 'user', invite_management_enabled: true } let json = { items: [], requests: [], services: [] } if (path.endsWith('/auth/me')) json = user if (path.endsWith('/auth/profile')) json = { user } if (path.endsWith('/auth/profile/invites')) json = { invites: [], invite_access: { enabled: true } } return route.fulfill({ status: 200, json }) }) const page = await context.newPage() const errors = [] page.on('pageerror', e => errors.push(e.message)) await page.goto(base + '/profile/invites') await page.getByLabel('Invite name', { exact: true }).fill('Family') await page.getByRole('button', { name: 'Continue to description' }).click() await page.getByRole('button', { name: 'Skip', exact: true }).click() await page.getByRole('button', { name: 'Continue to delivery' }).click() const email = page.getByRole('button', { name: /Send an email/ }) const manual = page.getByRole('button', { name: /Copy a link/ }) await email.click() assert.equal(await email.getAttribute('aria-pressed'), 'true') assert.equal(await manual.getAttribute('aria-pressed'), 'false') assert.equal(await page.locator('.delivery-choice-icon svg').count(), 2) const recipient = page.getByLabel('Recipient email', { exact: true }) const note = page.getByLabel('Email note (optional)', { exact: true }) const a = await recipient.boundingBox(), b = await note.boundingBox() assert.ok(Math.abs(a.y - b.y) < 2, 'Email fields must align at the top') await recipient.fill('friend@example.com') assert.equal(await page.getByRole('button', { name: 'Create and email invite' }).isEnabled(), true) if (process.env.REVIEW_DIR) await page.screenshot({ path: process.env.REVIEW_DIR + '/invite-delivery-desktop.png', fullPage: true }) await manual.click() assert.equal(await recipient.count(), 0) assert.equal(await page.getByRole('button', { name: 'Create invite link' }).isEnabled(), true) await page.setViewportSize({ width: 390, height: 844 }) await email.click() const m = await manual.boundingBox(), e = await email.boundingBox() assert.ok(e.y >= m.y + m.height, 'Mobile choices should stack') assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), 'No horizontal overflow') if (process.env.REVIEW_DIR) await page.screenshot({ path: process.env.REVIEW_DIR + '/invite-delivery-mobile.png', fullPage: true }) assert.deepEqual(errors, []) console.log('Invite delivery: desktop alignment, icons, selection, manual/email visibility and mobile layout passed.') } finally { await browser.close() } })().catch(e => { console.error(e); process.exitCode = 1 })