(
page: import("@playwright/test").Page,
tolerancePx: number
)
| 2 | |
| 3 | // Helper to run scrollHeight stability test with configurable tolerance |
| 4 | async function testScrollHeightStability( |
| 5 | page: import("@playwright/test").Page, |
| 6 | tolerancePx: number |
| 7 | ) { |
| 8 | await page.goto("http://127.0.0.1:8080/component/?name=virtual_list&", { |
| 9 | timeout: 20 * 60 * 1000, |
| 10 | }); |
| 11 | |
| 12 | const container = page.getByRole("list").first(); |
| 13 | await expect(container).toBeVisible({ timeout: 30000 }); |
| 14 | |
| 15 | // Wait for initial render |
| 16 | await page.waitForTimeout(500); |
| 17 | |
| 18 | // Get initial state |
| 19 | const initialState = await container.evaluate((el) => ({ |
| 20 | scrollHeight: el.scrollHeight, |
| 21 | clientHeight: el.clientHeight, |
| 22 | })); |
| 23 | |
| 24 | const maxScroll = initialState.scrollHeight - initialState.clientHeight; |
| 25 | const steps = 20; |
| 26 | const stepSize = maxScroll / steps; |
| 27 | |
| 28 | const measurements: Array<{ scrollTop: number; scrollHeight: number }> = []; |
| 29 | |
| 30 | // Simulate continuous scrolling (like dragging the scrollbar) |
| 31 | // by setting scrollTop in rapid succession |
| 32 | for (let i = 1; i <= steps; i++) { |
| 33 | const targetScroll = Math.round(stepSize * i); |
| 34 | |
| 35 | await container.evaluate((el, scroll) => { |
| 36 | el.scrollTop = scroll; |
| 37 | }, targetScroll); |
| 38 | |
| 39 | // Wait for scroll event to propagate through Rust and re-render |
| 40 | await page.waitForTimeout(100); |
| 41 | |
| 42 | const state = await container.evaluate((el) => ({ |
| 43 | scrollTop: el.scrollTop, |
| 44 | scrollHeight: el.scrollHeight, |
| 45 | })); |
| 46 | |
| 47 | measurements.push(state); |
| 48 | } |
| 49 | |
| 50 | // Analyze scrollHeight stability during the "drag" |
| 51 | // Exclude last measurement since scrollend fires ~150ms after last scroll, |
| 52 | // which correctly unfreezes the height - we only care about stability DURING scroll |
| 53 | const duringScrollMeasurements = measurements.slice(0, -1); |
| 54 | const scrollHeights = duringScrollMeasurements.map((m) => m.scrollHeight); |
| 55 | const minHeight = Math.min(...scrollHeights); |
| 56 | const maxHeight = Math.max(...scrollHeights); |
| 57 | const heightVariance = maxHeight - minHeight; |
| 58 | |
| 59 | console.log(`scrollHeight range: ${minHeight} - ${maxHeight} (variance: ${heightVariance}px)`); |
| 60 | console.log(`Measurements:`, measurements.map((m, i) => |
| 61 | `step ${i + 1}: scrollTop=${m.scrollTop}, scrollHeight=${m.scrollHeight}` |
no test coverage detected