// fixtures/engines/richer.mjs — three behaviours from the richer-UI pass, // in Chromium and WebKit (Fable's branch review on #105). // // Run by internal/docs/richer_engines_browser_test.go with the same // DOCS_ENGINES_CONFIG as first-reveal.mjs: one "simple" and one "empty" // document per engine. // // 1. Undo and Redo (the bar's lead pair, and the strip's with it) follow // keyboard undo and redo. Those never touch the buttons, which used // to keep whatever the last button-driven change had left. // 2. An empty document opens with the caret in it; a document with text // does not take focus. // 3. On the list, a search emptied with Backspace stays on its results; // Escape and the field's own × go back to the whole list. const { chromium, webkit } = await import('playwright') const config = JSON.parse(process.env.DOCS_ENGINES_CONFIG) const pause = (ms) => new Promise((r) => setTimeout(r, ms)) 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 context = await browser.newContext({ viewport: { width: 1280, height: 900 }, deviceScaleFactor: 1 }) await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' }))) const page = await context.newPage() const focusInText = () => page.evaluate(() => !!document.activeElement && !!document.activeElement.closest('[docs-text]')) // The pair a person sees at this width is the bar's lead slot's (spec // I2); the strip's, drawn below 800px, must agree with it. const disabled = (cmd) => page.evaluate((c) => { const lead = document.querySelector(`[estilo-bar-lead] [data-docs-command="${c}"]`).disabled const strip = document.querySelector(`[docs-bar] > [docs-history] [data-docs-command="${c}"]`).disabled return lead === strip ? lead : 'the two pairs disagree' }, cmd) const until = async (fn, ms = 3000) => { const end = Date.now() + ms while (Date.now() < end) { if (await fn()) return true await pause(50) } return fn() } // 2. Focus: the document with text first, then the empty one. await page.goto(config.origin + '/d/' + config.docs.simple.shift()) await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 }) await pause(1500) if (await focusInText()) fail('a document with text took focus on opening') // 1. Undo and redo, from the keyboard, on that same document. await page.click('[docs-text] p') await page.keyboard.press('End') await page.keyboard.type('xyz') if (!(await until(async () => !(await disabled('undo'))))) fail('Undo is still disabled after typing') await pause(700) await page.keyboard.press('ControlOrMeta+z') if (!(await until(async () => (await disabled('undo')) && !(await disabled('redo'))))) { fail(`after a keyboard undo: undo disabled=${await disabled('undo')}, redo disabled=${await disabled('redo')}; want true, false`) } await page.keyboard.press('ControlOrMeta+Shift+z') if (!(await until(async () => !(await disabled('undo')) && (await disabled('redo'))))) { fail(`after a keyboard redo: undo disabled=${await disabled('undo')}, redo disabled=${await disabled('redo')}; want false, true`) } await page.goto(config.origin + '/d/' + config.docs.empty.shift()) await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 }) if (!(await until(focusInText, 5000))) fail('an empty document did not open with the caret in it') // 3. Search: Backspace to empty stays; Escape clears and leaves. await page.goto(config.origin + '/?q=simple') const input = page.locator('[docs-search-input]') if ((await input.inputValue()) !== 'simple') fail(`the search field holds ${JSON.stringify(await input.inputValue())}, want "simple"`) await input.click() await page.keyboard.press('End') for (let i = 0; i < 6; i++) await page.keyboard.press('Backspace') await pause(800) if (!page.url().includes('q=simple')) fail(`emptying the search with Backspace navigated to ${page.url()}`) await page.keyboard.type('simple') await Promise.all([ page.waitForURL(config.origin + '/', { timeout: 5000 }).catch(() => {}), page.keyboard.press('Escape'), ]) if (page.url() !== config.origin + '/') fail(`clearing the search with Escape left the page at ${page.url()}, field ${JSON.stringify(await input.inputValue())}`) // The field's own ×, clicked where it is drawn: the input's right // end, inside its padding. Chromium fires an input event with no // inputType and then "search"; WebKit fires "search". await page.goto(config.origin + '/?q=simple') await input.hover() const box = await input.boundingBox() const pad = await input.evaluate((el) => parseFloat(getComputedStyle(el).paddingRight) || 0) await Promise.all([ page.waitForURL(config.origin + '/', { timeout: 5000 }).catch(() => {}), page.mouse.click(box.x + box.width - pad - 8, box.y + box.height / 2), ]) if (page.url() !== config.origin + '/') fail(`clicking the field's × left the page at ${page.url()}, field ${JSON.stringify(await input.inputValue().catch(() => '?'))}`) await browser.close() } if (failures.length) { for (const f of failures) console.log('FAIL ' + f) process.exit(1) } console.log('ok: undo/redo stay current, empty documents take the caret, search clear vs backspace, in both engines')