-
-
Notifications
You must be signed in to change notification settings - Fork 426
Expand file tree
/
Copy pathscroll.spec.ts
More file actions
72 lines (53 loc) · 2.12 KB
/
scroll.spec.ts
File metadata and controls
72 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { expect, test } from './fixtures'
const check = () => {
const item = document.querySelector('[data-testid="item-1000"]')
const container = document.querySelector('#scroll-container')
if (!item || !container) throw new Error('Elements not found')
const itemRect = item.getBoundingClientRect()
const containerRect = container.getBoundingClientRect()
const scrollTop = container.scrollTop
const top = itemRect.top + scrollTop - containerRect.top
const botttom = top + itemRect.height
const containerBottom = scrollTop + container.clientHeight
return Math.abs(botttom - containerBottom)
}
test('scrolls to index 1000', async ({ page }) => {
await page.goto('/scroll/')
await page.click('#scroll-to-1000')
// Wait for scroll effect (including retries)
await page.waitForTimeout(1000)
await expect(page.locator('[data-testid="item-1000"]')).toBeVisible()
const delta = await page.evaluate(check)
expect(delta).toBeLessThan(1.01)
})
test('scrolls to last item', async ({ page }) => {
await page.goto('/scroll/')
await page.click('#scroll-to-last')
await page.waitForTimeout(1000)
// Last item (index 1001) should be visible
await expect(page.locator('[data-testid="item-1001"]')).toBeVisible()
// Container should be scrolled to the very bottom
const atBottom = await page.evaluate(() => {
const container = document.querySelector('#scroll-container')
if (!container) throw new Error('Container not found')
return Math.abs(
container.scrollTop + container.clientHeight - container.scrollHeight,
)
})
expect(atBottom).toBeLessThan(1.01)
})
test('scrolls to index 0', async ({ page }) => {
await page.goto('/scroll/')
// First scroll down
await page.click('#scroll-to-1000')
await page.waitForTimeout(1000)
// Then scroll to first item
await page.click('#scroll-to-0')
await page.waitForTimeout(1000)
await expect(page.locator('[data-testid="item-0"]')).toBeVisible()
const scrollTop = await page.evaluate(() => {
const container = document.querySelector('#scroll-container')
return container?.scrollTop ?? -1
})
expect(scrollTop).toBeLessThan(1.01)
})