chore: fix test

This commit is contained in:
Adam 2026-03-11 16:01:56 -05:00
parent dbc00aa8e0
commit 387ab78bf6
No known key found for this signature in database
GPG Key ID: 9CB48779AF150E75

View File

@ -101,12 +101,31 @@ async function waitMark(page: Parameters<typeof test>[0]["page"], file: string,
)
}
async function spot(page: Parameters<typeof test>[0]["page"], file: string) {
return page.evaluate((file) => {
const view = document.querySelector('[data-slot="session-review-scroll"] .scroll-view__viewport')
if (!(view instanceof HTMLElement)) return null
const row = Array.from(document.querySelectorAll("h3")).find(
(node) => node instanceof HTMLElement && node.textContent?.includes(file),
)
if (!(row instanceof HTMLElement)) return null
const a = row.getBoundingClientRect()
const b = view.getBoundingClientRect()
return {
top: a.top - b.top,
y: view.scrollTop,
}
}, file)
}
test("review keeps scroll position after a live diff update", async ({ page, withProject }) => {
test.setTimeout(180_000)
const tag = `review-${Date.now()}`
const list = files(tag)
const hit = list[list.length - 2]!
const hit = list[list.length - 4]!
const next = `${tag}-live`
await page.setViewportSize({ width: 1600, height: 1000 })
@ -160,8 +179,9 @@ test("review keeps scroll position after a live diff update", async ({ page, wit
await expect(row).toBeVisible()
await row.evaluate((el) => el.scrollIntoView({ block: "center" }))
await expect.poll(() => view.evaluate((el) => el.scrollTop)).toBeGreaterThan(200)
const prev = await view.evaluate((el) => el.scrollTop)
await expect.poll(async () => (await spot(page, hit.file))?.y ?? 0).toBeGreaterThan(200)
const prev = await spot(page, hit.file)
if (!prev) throw new Error(`missing review row for ${hit.file}`)
await patch(sdk, session.id, edit(hit.file, hit.mark, next))
@ -179,8 +199,15 @@ test("review keeps scroll position after a live diff update", async ({ page, wit
await waitMark(page, hit.file, next)
await expect
.poll(async () => Math.abs((await view.evaluate((el) => el.scrollTop)) - prev), { timeout: 60_000 })
.toBeLessThanOrEqual(16)
.poll(
async () => {
const next = await spot(page, hit.file)
if (!next) return Number.POSITIVE_INFINITY
return Math.max(Math.abs(next.top - prev.top), Math.abs(next.y - prev.y))
},
{ timeout: 60_000 },
)
.toBeLessThanOrEqual(32)
})
})
})