mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-09 18:29:39 +00:00
chore: fix test
This commit is contained in:
@@ -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("review keeps scroll position after a live diff update", async ({ page, withProject }) => {
|
||||||
test.setTimeout(180_000)
|
test.setTimeout(180_000)
|
||||||
|
|
||||||
const tag = `review-${Date.now()}`
|
const tag = `review-${Date.now()}`
|
||||||
const list = files(tag)
|
const list = files(tag)
|
||||||
const hit = list[list.length - 2]!
|
const hit = list[list.length - 4]!
|
||||||
const next = `${tag}-live`
|
const next = `${tag}-live`
|
||||||
|
|
||||||
await page.setViewportSize({ width: 1600, height: 1000 })
|
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 expect(row).toBeVisible()
|
||||||
await row.evaluate((el) => el.scrollIntoView({ block: "center" }))
|
await row.evaluate((el) => el.scrollIntoView({ block: "center" }))
|
||||||
|
|
||||||
await expect.poll(() => view.evaluate((el) => el.scrollTop)).toBeGreaterThan(200)
|
await expect.poll(async () => (await spot(page, hit.file))?.y ?? 0).toBeGreaterThan(200)
|
||||||
const prev = await view.evaluate((el) => el.scrollTop)
|
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))
|
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 waitMark(page, hit.file, next)
|
||||||
|
|
||||||
await expect
|
await expect
|
||||||
.poll(async () => Math.abs((await view.evaluate((el) => el.scrollTop)) - prev), { timeout: 60_000 })
|
.poll(
|
||||||
.toBeLessThanOrEqual(16)
|
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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user