// fixtures/engines/i2.mjs — the I2 editor layout (spec 2026-11-11), in
// Chromium and WebKit, through the real server.
//
// Run by internal/docs/i2_engines_browser_test.go with the same
// DOCS_ENGINES_CONFIG as first-reveal.mjs: "simple" documents owned by
// the signed-in person, a fresh one per leg.
//
// 1. 1280px: the stacked header, 56px, its stack starting at 56px; the
// header's controls 28px; the inspector a 248px panel 12px under the
// header and 12px from the end, its sections a column; the lead's
// undo/redo drawn and the strip's not.
// 2. Format toggles the inspector in place (no navigation), says so in
// aria-expanded and the cookie, and the next page is rendered closed;
// closed, Tab from the header goes past the hidden controls into the
// document, and Escape in the document stays there (C2).
// 3. The header's undo/redo stay current through keyboard undo and redo,
// and the strip's pair says the same.
// 4. The sheet: centred at 1800 and 1440, moved only as far as the
// inspector needs at 1280, and centred again with it closed.
// 5. 1000px: the strip under the header, open or closed (C3), Format not
// drawn, the lead's pair drawn.
// 6. 390px: the phone (design/phone-web, P1): estilo's compact bar, one
// 52px row with the lead's undo/redo, Aa and •••, and no menu row;
// Aa opens the Format sheet, half the screen at its foot (P2).
// 6b. 720px, the 704-799px band: the 56px header with the menus in it
// and the lead's undo/redo, the strip under it, not the strip's pair.
// 7. 320px: no page-level horizontal overflow.
// 8. A short window: the inspector scrolls inside it, and a picker's list
// is not clipped by it.
//
// I2_SHOTS=
also saves a screenshot of each leg there.
const { chromium, webkit } = await import('playwright')
const config = JSON.parse(process.env.DOCS_ENGINES_CONFIG)
const shots = process.env.I2_SHOTS || ''
const pause = (ms) => new Promise((r) => setTimeout(r, ms))
const near = (a, b, tol = 1) => Math.abs(a - b) <= tol
const failures = []
for (const engine of [chromium, webkit]) {
const name = engine.name()
const fail = (msg) => failures.push(`${name}: ${msg}`)
const browser = await engine.launch({ headless: true })
const until = async (fn, ms = 4000) => {
const end = Date.now() + ms
while (Date.now() < end) { if (await fn()) return true; await pause(50) }
return fn()
}
// A fresh context at a width, signed in, with the inspector cookie as
// given, on a fresh document whose editor has mounted.
async function open (width, height, { inspector = '' } = {}) {
const context = await browser.newContext({ viewport: { width, height }, deviceScaleFactor: 1 })
const cookies = config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' }))
if (inspector) cookies.push({ name: 'docs-inspector', value: inspector, url: config.origin, sameSite: 'Lax' })
await context.addCookies(cookies)
const page = await context.newPage()
const url = config.origin + '/d/' + config.docs.simple.shift()
await page.goto(url)
await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 })
await page.waitForFunction(() => !document.querySelector('[docs-toolbar] [data-docs-command="strong"]').disabled, null, { timeout: 15000 })
await pause(300)
return { context, page, url }
}
const shot = async (page, leg) => { if (shots) await page.screenshot({ path: `${shots}/${name}-${leg}.png` }) }
// Geometry of everything the checks read, in one round trip.
const measure = (page) => page.evaluate(() => {
const box = (sel) => {
const el = document.querySelector(sel)
if (!el) return null
const r = el.getBoundingClientRect()
const drawn = typeof el.checkVisibility === 'function' ? el.checkVisibility() : r.width > 0
return { x: r.left, y: r.top, w: r.width, h: r.height, r: r.right, b: r.bottom, drawn }
}
return {
// The page's own width: 's, which is the viewport less any
// scrollbar or its reserved gutter (Chromium reserves one, and
// documentElement.clientWidth still says the whole viewport).
vw: document.querySelector('main').getBoundingClientRect().width,
cw: document.documentElement.clientWidth,
scrollWidth: document.documentElement.scrollWidth,
header: box('[estilo-bar]'),
stack: box('[estilo-bar-stack]'),
menubar: box('[estilo-menubar]'),
lead: box('[estilo-bar-lead] [docs-history]'),
leadUndo: box('[estilo-bar-lead] [data-docs-command="undo"]'),
stripHistory: box('[docs-bar] > [docs-history]'),
format: box('[data-estilo-toggle][aria-controls="docs-inspector"]'),
share: box('[estilo-bar-actions] a[href$="/share"]'),
avatar: box('[estilo-account] [estilo-avatar], [estilo-account] > summary'),
inspector: box('[docs-inspector]'),
inspectorPosition: getComputedStyle(document.querySelector('[docs-inspector]')).position,
toolbar: box('[docs-toolbar]'),
styleGroup: box('[docs-toolbar-group="style"]'),
textGroup: box('[docs-toolbar-group="text"]'),
label: box('[docs-toolbar-label]'),
bold: box('[docs-toolbar] [data-docs-command="strong"]'),
chrome: box('[docs-chrome]'),
sheet: box('[docs-page]'),
state: document.querySelector('[docs-inspector]').getAttribute('data-state'),
expanded: document.querySelector('[data-estilo-toggle]').getAttribute('aria-expanded'),
formatDisabled: document.querySelector('[data-estilo-toggle]').disabled,
}
})
// 1. The header and the inspector at 1280.
{
const { context, page, url } = await open(1280, 900)
const m = await measure(page)
await shot(page, '1280-open')
if (!near(m.header.h, 56)) fail(`1280: the header is ${m.header.h}px tall, want 56`)
if (!near(m.stack.x, 56)) fail(`1280: the title and menus start at ${m.stack.x}px, want 56`)
for (const [what, b] of [['the undo/redo pill', m.lead], ['Format', m.format], ['Share', m.share], ['the avatar', m.avatar]]) {
if (!b || !b.drawn || !near(b.h, 28)) fail(`1280: ${what} is ${b && b.h}px tall (drawn ${b && b.drawn}), want 28`)
}
if (m.stripHistory.drawn) fail('1280: the strip\'s undo/redo is drawn beside the header\'s')
if (m.formatDisabled) fail('1280: Format is still disabled with the script loaded')
if (m.inspectorPosition !== 'fixed' || !m.inspector.drawn) fail(`1280: the inspector is ${m.inspectorPosition}, drawn ${m.inspector.drawn}`)
if (!near(m.inspector.w, 248)) fail(`1280: the inspector is ${m.inspector.w}px wide, want 248`)
if (!near(m.inspector.y, m.header.b + 12)) fail(`1280: the inspector starts at ${m.inspector.y}, want 12px under the header at ${m.header.b}`)
if (!near(m.inspector.r, m.vw - 12)) fail(`1280: the inspector ends at ${m.inspector.r}, want ${m.vw - 12}`)
if (!(m.textGroup.y >= m.styleGroup.b + 13)) fail(`1280: the sections are not a column 14px apart: Style ends ${m.styleGroup.b}, Text starts ${m.textGroup.y}`)
if (!m.label.drawn) fail('1280: the inspector\'s section labels are not drawn')
if (!near(m.bold.h, 28)) fail(`1280: the inspector's buttons are ${m.bold.h}px, want 28`)
// 3. The header's undo/redo through keyboard undo and redo.
const disabled = (where, cmd) => page.evaluate(([w, c]) => document.querySelector(`${w} [data-docs-command="${c}"]`).disabled, [where, cmd])
const pair = async (where) => [await disabled(where, 'undo'), await disabled(where, 'redo')].join(',')
await page.click('[docs-text] p')
await page.keyboard.press('End')
await page.keyboard.type('xyz')
if (!(await until(async () => (await pair('[estilo-bar-lead]')) === 'false,true'))) fail(`1280: after typing the header's undo/redo are ${await pair('[estilo-bar-lead]')}, want enabled, disabled`)
await pause(700)
await page.keyboard.press('ControlOrMeta+z')
if (!(await until(async () => (await pair('[estilo-bar-lead]')) === 'true,false'))) fail(`1280: after a keyboard undo the header's undo/redo are ${await pair('[estilo-bar-lead]')}, want disabled, enabled`)
await page.keyboard.press('ControlOrMeta+Shift+z')
if (!(await until(async () => (await pair('[estilo-bar-lead]')) === 'false,true'))) fail(`1280: after a keyboard redo the header's undo/redo are ${await pair('[estilo-bar-lead]')}, want enabled, disabled`)
if ((await pair('[docs-bar]')) !== (await pair('[estilo-bar-lead]'))) fail(`1280: the strip's pair (${await pair('[docs-bar]')}) disagrees with the header's (${await pair('[estilo-bar-lead]')})`)
// And the header's undo button does undo.
await page.click('[estilo-bar-lead] [data-docs-command="undo"]', { timeout: 3000 }).catch(() => fail('1280: the header\'s Undo could not be clicked'))
if (!(await until(async () => !(await page.locator('[docs-text]').innerText()).includes('xyz')))) fail('1280: the header\'s Undo did not undo')
// 2. Format: closed in place, then the tab path and Escape.
await page.evaluate(() => { window.__same = true })
await page.click('[data-estilo-toggle]')
await pause(200)
const c = await measure(page)
await shot(page, '1280-closed')
if (page.url() !== url || !(await page.evaluate(() => window.__same === true))) fail('1280: Format navigated')
if (c.state !== 'closed' || c.expanded !== 'false' || c.inspector.drawn) fail(`1280: after Format the inspector is ${c.state}, aria-expanded ${c.expanded}, drawn ${c.inspector.drawn}`)
const cookie = (await context.cookies()).find((k) => k.name === 'docs-inspector')
if (!cookie || cookie.value !== 'closed' || cookie.path !== '/' || cookie.sameSite !== 'Lax' || cookie.expires < Date.now() / 1000 + 300 * 86400) fail(`1280: the cookie is ${JSON.stringify(cookie)}, want closed, path /, Lax, a year`)
// Closed, Tab from the account goes into the document, past every
// hidden control of the inspector.
const tabFromAccount = async () => {
await page.focus('[estilo-account] > summary')
await page.keyboard.press('Tab')
await pause(100)
return page.evaluate(() => {
const a = document.activeElement
return a.closest('[docs-text]') ? 'document' : a.closest('[docs-toolbar]') ? 'toolbar' : (a.outerHTML || '').slice(0, 80)
})
}
const closedTab = await tabFromAccount()
if (closedTab !== 'document') fail(`1280: closed, Tab from the account reached ${closedTab}, want the document`)
// Escape in the document has no drawn toolbar control to go to, so
// it goes to Format, the way back to the inspector (review on #106),
// and never to a hidden control.
await page.click('[docs-text] p')
await page.keyboard.press('Escape')
await pause(100)
const escaped = await page.evaluate(() => {
const a = document.activeElement
return a.matches('[data-estilo-toggle]') ? 'Format' : a.closest('[docs-toolbar]') ? 'a hidden toolbar control' : a.closest('[docs-text]') ? 'the document' : (a.outerHTML || '').slice(0, 60)
})
if (escaped !== 'Format') fail(`1280: closed, Escape in the document went to ${escaped}, want Format`)
// The sheet with the inspector closed is plainly centred.
if (!near(c.sheet.x + c.sheet.w / 2, c.vw / 2, 1.5)) fail(`1280 closed: the sheet's centre is ${c.sheet.x + c.sheet.w / 2}, want ${c.vw / 2}`)
// The next page is rendered closed, from the first byte.
const raw = await (await page.request.get(url)).text()
if (!raw.includes('data-state="closed"') || !raw.includes('aria-expanded="false" aria-controls="docs-inspector"')) fail('1280: the next page was not rendered closed')
// Open again: the inspector is back and Tab reaches it.
await page.click('[data-estilo-toggle]')
await pause(200)
const o = await measure(page)
if (o.state !== 'open' || o.expanded !== 'true' || !o.inspector.drawn) fail(`1280: Format again left the inspector ${o.state}, aria-expanded ${o.expanded}, drawn ${o.inspector.drawn}`)
const openTab = await tabFromAccount()
if (openTab !== 'toolbar') fail(`1280: open, Tab from the account reached ${openTab}, want the toolbar`)
// Forced colours (review on #106), where the engine can emulate them:
// a pressed control keeps an outline, and the Share popover's filled
// controls an edge.
await page.emulateMedia({ forcedColors: 'active' })
if (await page.evaluate(() => matchMedia('(forced-colors: active)').matches)) {
const pressed = await page.evaluate(() => {
const b = document.querySelector('[docs-inspector] [aria-pressed="true"]')
return b ? getComputedStyle(b).outlineStyle : 'no pressed control'
})
if (pressed !== 'solid') fail(`forced colours: the pressed control's outline is ${pressed}, want solid`)
await page.click('[estilo-bar-actions] a[href$="/share"]')
await until(async () => (await page.locator('[docs-share-pop] [docs-share-panel]').count()) === 1)
const edges = await page.evaluate(() => ['[docs-share-submit]', '[docs-share-invite] select'].map((sel) => {
const el = document.querySelector(sel)
return el ? `${sel} ${getComputedStyle(el).borderTopStyle} ${getComputedStyle(el).borderTopWidth}` : `${sel} missing`
}))
for (const e of edges) if (!e.endsWith('solid 1px')) fail(`forced colours: ${e}, want a 1px border`)
}
await context.close()
}
// 4. The sheet at three widths, the inspector open.
for (const [w, centred] of [[1800, true], [1440, true], [1280, false]]) {
const { context, page } = await open(w, 900)
const m = await measure(page)
const centre = m.sheet.x + m.sheet.w / 2
if (centred && !near(centre, m.vw / 2, 1.5)) fail(`${w}: the sheet's centre is ${centre}, want ${m.vw / 2} (centred)`)
if (!centred && (!near(m.sheet.r, m.vw - (248 + 12 + 16), 1.5) || !near(m.sheet.w, 816))) fail(`${w}: the sheet is ${m.sheet.w}px wide ending at ${m.sheet.r}, want 816 ending at ${m.vw - 276}`)
if (m.sheet.r > m.inspector.x - 16 + 0.5) fail(`${w}: the sheet (ends ${m.sheet.r}) runs under the inspector (starts ${m.inspector.x})`)
await context.close()
}
// 5. 1000px: the strip, open or closed.
for (const inspector of ['', 'closed']) {
const { context, page } = await open(1000, 800, { inspector })
const m = await measure(page)
await shot(page, '1000' + (inspector ? '-closed' : ''))
const leg = `1000${inspector ? ' closed' : ''}`
if (!near(m.header.h, 56)) fail(`${leg}: the header is ${m.header.h}px, want 56`)
if (m.inspectorPosition === 'fixed' || !m.toolbar.drawn || !m.bold.drawn) fail(`${leg}: the strip is not drawn (inspector ${m.inspectorPosition}, toolbar drawn ${m.toolbar.drawn})`)
if (!(m.toolbar.y >= m.header.b - 0.5 && m.toolbar.h < 60)) fail(`${leg}: the strip is not one row under the header: ${JSON.stringify(m.toolbar)}`)
if (m.format.drawn) fail(`${leg}: Format is drawn with no inspector to toggle`)
if (m.label.drawn) fail(`${leg}: the inspector's labels are drawn in the strip`)
if (!m.lead.drawn || m.stripHistory.drawn) fail(`${leg}: want the header's undo/redo (drawn ${m.lead.drawn}) and not the strip's (drawn ${m.stripHistory.drawn})`)
await context.close()
}
// 6. 390px: the phone: the compact bar (design/phone-web, P1).
{
const { context, page } = await open(390, 844)
const m = await measure(page)
await shot(page, '390')
const extra = await page.evaluate(() => {
const drawn = (s) => { const e = document.querySelector(s); return !!e && (typeof e.checkVisibility === 'function' ? e.checkVisibility() : e.getClientRects().length > 0) }
return { aa: drawn('[docs-aa]'), more: drawn('[docs-more] > summary'), title: drawn('[docs-title-block]') }
})
if (!near(m.header.h, 52)) fail(`390: the compact bar is ${m.header.h}px tall, want one 52px row`)
if (m.menubar.drawn) fail(`390: the menus are drawn in the compact bar: ${JSON.stringify(m.menubar)}`)
if (!m.lead.drawn || m.stripHistory.drawn) fail(`390: want the header's undo/redo (drawn ${m.lead.drawn}) and not the strip's (drawn ${m.stripHistory.drawn})`)
if (!extra.aa || !extra.more || !extra.title) fail(`390: Aa ${extra.aa}, ••• ${extra.more}, the large title ${extra.title}; want all three`)
if (m.bold.drawn) fail('390: the formatting controls are drawn before Aa asks for them')
await page.click('[docs-aa]', { timeout: 3000 }).catch(() => fail('390: Aa could not be pressed'))
await page.waitForTimeout(300)
const a = await measure(page)
await shot(page, '390-aa')
// P2: Aa opens the Format sheet, the inspector as a bottom sheet.
const vh = await page.evaluate(() => innerHeight)
if (!a.bold.drawn || a.inspectorPosition !== 'fixed') fail(`390: Aa did not open the Format sheet (inspector ${a.inspectorPosition}, bold drawn ${a.bold.drawn})`)
if (!near(a.inspector.b, vh, 1) || !(a.inspector.h > vh * 0.4 && a.inspector.h < vh * 0.6)) fail(`390: the sheet is not half the screen at its foot: ${JSON.stringify(a.inspector)} in ${vh}`)
if (await page.evaluate(() => document.querySelectorAll('[estilo-menubar]').length) !== 1) fail('390: more than one menu bar')
await context.close()
}
// 6b. 720px, the 704-799px band: the desktop header (estilo P0, compact
// bars only), the lead's undo/redo in it and the strip under it.
{
const { context, page } = await open(720, 900)
const m = await measure(page)
await shot(page, '720')
if (!near(m.header.h, 56)) fail(`720: the header is ${m.header.h}px, want 56`)
if (!m.menubar.drawn || !(m.menubar.y < m.header.b)) fail(`720: the menus are not in the header: ${JSON.stringify(m.menubar)}`)
if (!m.lead.drawn || m.stripHistory.drawn) fail(`720: want the header's undo/redo (drawn ${m.lead.drawn}) and not the strip's (drawn ${m.stripHistory.drawn})`)
if (!m.toolbar.drawn || !(m.toolbar.y >= m.header.b - 0.5)) fail(`720: the strip is not under the header: ${JSON.stringify(m.toolbar)}`)
if (m.scrollWidth > m.cw) fail(`720: the page scrolls sideways, ${m.scrollWidth} in ${m.cw}`)
await context.close()
}
// 8. A short window (review on #106): the inspector stops 12px above
// the window's foot and scrolls, and a picker's list opened in it is
// not clipped by it.
{
const { context, page } = await open(1280, 300)
const g = await page.evaluate(() => {
const el = document.querySelector('[docs-inspector]')
const r = el.getBoundingClientRect()
return { bottom: r.bottom, vh: innerHeight, scroll: el.scrollHeight, client: el.clientHeight, anchors: CSS.supports('anchor-name: --x') }
})
if (g.anchors && !(g.bottom <= g.vh - 12 + 0.5 && g.scroll > g.client)) fail(`300px tall: the inspector ends at ${g.bottom} in ${g.vh} (scroll ${g.scroll}, client ${g.client}); want it inside the window, scrolling`)
await page.click('#docs-select-font-combo')
await page.waitForSelector('[docs-inspector] [rst-combo]:has(#docs-select-font-combo) [rst-combo-list]:not([hidden])', { timeout: 5000 }).catch(() => {})
const l = await page.evaluate(() => {
const list = document.querySelector('[docs-inspector] [rst-combo]:has(#docs-select-font-combo) [rst-combo-list]')
const box = document.querySelector('[docs-inspector]').getBoundingClientRect()
const r = list.getBoundingClientRect()
// A point of the list outside the inspector's box and inside the
// window, if it has one: the middle of the band where it hangs
// below the box (or above it), at the list's centre line.
const x = Math.min(innerWidth - 1, Math.max(0, (r.left + r.right) / 2))
const below = [box.bottom, Math.min(r.bottom, innerHeight)]
const above = [Math.max(r.top, 0), box.top]
const outside = below[1] - below[0] > 2 ? { x, y: (below[0] + below[1]) / 2 } : above[1] - above[0] > 2 ? { x, y: (above[0] + above[1]) / 2 } : null
const hit = outside && document.elementFromPoint(outside.x, outside.y)
return { list: { t: r.top, b: r.bottom, l: r.left, r: r.right, h: r.height }, box: { t: box.top, b: box.bottom, l: box.left, r: box.right }, outside, inList: !!(hit && list.contains(hit)), position: getComputedStyle(list).position }
})
if (!g.anchors) { /* no anchor positioning: the panel does not scroll, and the lists are its own (show.html) */ } else if (!l.outside) fail(`300px tall: the font list (${JSON.stringify(l.list)}) never leaves the inspector (${JSON.stringify(l.box)}): it is clipped by it, or select.js shrank it to the room the inspector leaves (both mean the panel is the list's clipping box)`)
else if (!l.inList) fail(`300px tall: the font list is clipped where it leaves the inspector (${JSON.stringify(l)})`)
await context.close()
}
// 7. 320px: nothing overflows the page.
{
const { context, page } = await open(320, 720)
const m = await measure(page)
await shot(page, '320')
if (m.scrollWidth > m.cw) fail(`320: the page scrolls sideways, ${m.scrollWidth} in ${m.cw}`)
await context.close()
}
await browser.close()
}
if (failures.length) {
for (const f of failures) console.log('FAIL ' + f)
process.exit(1)
}
console.log('ok: the I2 header, inspector, Format, undo/redo, sheet centring and narrow layouts, in both engines')