Skip to content

Commit 6a77bdf

Browse files
committed
test(chat): re-read message positions until each is on screen
A re-render after a reload or reconnect can replace a message node between finding it and measuring it, so the order check reads every position in one attempt and retries until all have one.
1 parent 9b11d90 commit 6a77bdf

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

‎apps/sim/scripts/test-chat-steering-e2e.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -668,16 +668,27 @@ async function assertOneBubble(page: Page, text: string) {
668668
await expect(page.getByText(text, { exact: true })).toHaveCount(1)
669669
}
670670

671-
/** The given texts are on screen, top to bottom in this order. */
671+
/**
672+
* The given texts are on screen, top to bottom in this order. Positions are re-read until every
673+
* text has one, since a re-render (after a reload or reconnect) can replace a node between finding
674+
* it and measuring it.
675+
*/
672676
async function assertOrder(page: Page, texts: string[]) {
673-
const positions: number[] = []
674-
for (const text of texts) {
675-
const element = page.getByText(text).first()
676-
await element.waitFor()
677-
const box = await element.boundingBox()
678-
assert(box, `No position for "${text}"`)
679-
positions.push(box.y)
680-
}
677+
let positions: number[] = []
678+
await expect
679+
.poll(
680+
async () => {
681+
positions = []
682+
for (const text of texts) {
683+
const box = await page.getByText(text).first().boundingBox()
684+
if (!box) return false
685+
positions.push(box.y)
686+
}
687+
return true
688+
},
689+
{ message: `Every one of ${texts.map((text) => `"${text}"`).join(', ')} is on screen` }
690+
)
691+
.toBe(true)
681692
for (let index = 1; index < positions.length; index++) {
682693
assert(
683694
(positions[index - 1] ?? 0) < (positions[index] ?? 0),

0 commit comments

Comments
 (0)