|
1 | 1 | import { expect, test } from '@playwright/test' |
2 | 2 |
|
3 | | -test('scrolls to index 1000', async ({ page }) => { |
4 | | - await page.goto('/') |
5 | | - await page.waitForSelector('#scroll-to-1000', { state: 'visible' }) |
6 | | - await page.click('#scroll-to-1000') |
| 3 | +const check = () => { |
| 4 | + const item = document.querySelector('[data-testid="item-1000"]') |
| 5 | + const container = document.querySelector('#scroll-container') |
| 6 | + |
| 7 | + if (!item || !container) throw new Error('Elements not found') |
7 | 8 |
|
8 | | - const delta = await page.evaluate(() => { |
9 | | - const item = document.querySelector('[data-testid="item-1000"]') |
10 | | - const container = document.querySelector('#scroll-container') |
| 9 | + const itemRect = item.getBoundingClientRect() |
| 10 | + const containerRect = container.getBoundingClientRect() |
| 11 | + const scrollTop = container.scrollTop |
11 | 12 |
|
12 | | - if (!item || !container) throw new Error('Elements not found') |
| 13 | + const top = itemRect.top + scrollTop - containerRect.top |
| 14 | + const botttom = top + itemRect.height |
13 | 15 |
|
14 | | - const itemRect = item.getBoundingClientRect() |
15 | | - const containerRect = container.getBoundingClientRect() |
16 | | - const scrollTop = container.scrollTop |
| 16 | + const containerBottom = scrollTop + container.clientHeight |
17 | 17 |
|
18 | | - const top = itemRect.top + scrollTop - containerRect.top |
19 | | - const botttom = top + itemRect.height |
| 18 | + return Math.abs(botttom - containerBottom) |
| 19 | +} |
20 | 20 |
|
21 | | - const containerBottom = scrollTop + container.clientHeight |
| 21 | +test('scrolls to index 1000', async ({ page }) => { |
| 22 | + await page.goto('/') |
| 23 | + await page.click('#scroll-to-1000') |
22 | 24 |
|
23 | | - return Math.abs(botttom - containerBottom) |
24 | | - }) |
25 | | - console.log('delta:', delta) |
| 25 | + // Wait for scroll effect (including retries) |
| 26 | + await page.waitForTimeout(1000) |
26 | 27 |
|
27 | 28 | await expect(page.locator('[data-testid="item-1000"]')).toBeVisible() |
| 29 | + |
| 30 | + const delta = await page.evaluate(check) |
| 31 | + console.log('bootom element detla', delta) |
28 | 32 | }) |
0 commit comments