Skip to content

Commit fc72100

Browse files
committed
fix(e2e): start the markdown keyboard selection inside the word and compare settled chip screenshots
1 parent fccab04 commit fc72100

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

‎apps/sim/scripts/test-browser-extension-e2e.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ const checkNavigation = (name: string, run: () => Promise<void>) => check('navig
191191
const checkComposer = (name: string, run: () => Promise<void>) => check('composer', name, run)
192192
const checkAccess = (name: string, run: () => Promise<void>) => check('access', name, run)
193193

194+
/**
195+
* A screenshot taken once two consecutive captures match, so a pixel comparison between two
196+
* renderings of an element is not decided by a frame captured mid-paint.
197+
*/
198+
async function settledScreenshot(
199+
target: Locator,
200+
options: Parameters<Locator['screenshot']>[0]
201+
): Promise<Buffer> {
202+
let previous = await target.screenshot(options)
203+
for (let capture = 0; capture < 10; capture++) {
204+
const next = await target.screenshot(options)
205+
if (next.equals(previous)) return next
206+
previous = next
207+
}
208+
throw new Error('The element kept repainting across ten screenshots')
209+
}
210+
194211
async function screenshot(name: string, target = panel) {
195212
if (!target) return
196213
for (const frame of target.frames()) {
@@ -1163,8 +1180,8 @@ try {
11631180
.toBe(true)
11641181
if (width === 320) {
11651182
const chip = attachments().first()
1166-
const visible = await chip.screenshot({ animations: 'disabled' })
1167-
const withoutEdgeMask = await chip.screenshot({
1183+
const visible = await settledScreenshot(chip, { animations: 'disabled' })
1184+
const withoutEdgeMask = await settledScreenshot(chip, {
11681185
animations: 'disabled',
11691186
style:
11701187
'div:has(> div > [aria-label="Page attached to next message"]) { mask-image: none !important; }',

‎apps/sim/scripts/test-markdown-viewer-e2e.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,22 @@ async function editLastCell(page: Page, marker: string) {
375375
timeout: 120_000,
376376
})
377377
await page.bringToFront()
378-
await page
379-
.locator('.rich-markdown-prose strong')
380-
.filter({ hasText: /^bold$/ })
381-
.click()
378+
const bold = page.locator('.rich-markdown-prose strong').filter({ hasText: /^bold$/ })
379+
await bold.click()
382380
await expect(page.locator('.rich-markdown-prose[contenteditable="true"]')).toBeFocused()
383-
await page.keyboard.press('ArrowLeft')
381+
// A click can land the caret at the word's edge, where one step left crosses the space before it
382+
// and Shift+ArrowRight selects only that space. Start inside the word: "bo|ld".
383+
await bold.evaluate((element) => {
384+
const text = element.firstChild
385+
if (text?.nodeType !== Node.TEXT_NODE) throw new Error('The bold mark has no text node')
386+
getSelection()?.collapse(text, 2)
387+
})
384388
await page.keyboard.press('Shift+ArrowRight')
385-
assert(
386-
await page.evaluate(() => Boolean(getSelection()?.toString().trim())),
387-
'Keyboard selection did not select text'
388-
)
389+
await expect
390+
.poll(() => page.evaluate(() => getSelection()?.toString() ?? ''), {
391+
message: 'Keyboard selection did not select text',
392+
})
393+
.toBe('l')
389394
await proveToolbar(page, page.getByRole('toolbar', { name: 'Text formatting' }))
390395
await page.keyboard.press('ArrowRight')
391396
}

0 commit comments

Comments
 (0)