|
| 1 | +import { expect, test } from "@playwright/test" |
| 2 | +import { Model } from "./models/model" |
| 3 | + |
| 4 | +/** Standalone virtualizer examples (see shared/src/routes.ts). */ |
| 5 | +const virtualizerRoutes = [ |
| 6 | + "/virtualizer/list", |
| 7 | + "/virtualizer/grid", |
| 8 | + "/virtualizer/padding", |
| 9 | + "/virtualizer/sticky", |
| 10 | + "/virtualizer/window", |
| 11 | +] as const |
| 12 | + |
| 13 | +/** Heavy perf comparison pages (large item counts). */ |
| 14 | +const virtualizerPerfRoutes = ["/virtualizer/perf", "/virtualizer/perf-variable", "/virtualizer/perf-dynamic"] as const |
| 15 | + |
| 16 | +/** Components integrating @zag-js/virtualizer. */ |
| 17 | +const virtualizedComponentRoutes = [ |
| 18 | + "/select/virtualized", |
| 19 | + "/combobox/virtualized", |
| 20 | + "/listbox/virtualized", |
| 21 | + "/gridlist/virtualized", |
| 22 | + "/tree-view/virtualized", |
| 23 | + "/dnd/virtualized", |
| 24 | +] as const |
| 25 | + |
| 26 | +test.describe("virtualizer examples", () => { |
| 27 | + for (const path of virtualizerRoutes) { |
| 28 | + test(`smoke ${path}`, async ({ page }) => { |
| 29 | + const I = new Model(page) |
| 30 | + await page.goto(path) |
| 31 | + await page.waitForSelector("main", { state: "visible" }) |
| 32 | + await I.dontSeeInConsole("flushSync was called from inside a lifecycle method", 3000) |
| 33 | + await I.checkAccessibility("main") |
| 34 | + |
| 35 | + if (path === "/virtualizer/window") { |
| 36 | + // Layout uses `main { overflow-y: auto }` — scroll the main element, not the window. |
| 37 | + const main = page.locator("main") |
| 38 | + await main.evaluate((el) => { |
| 39 | + el.scrollTop = 400 |
| 40 | + }) |
| 41 | + await expect.poll(async () => main.evaluate((el) => el.scrollTop)).toBeGreaterThan(0) |
| 42 | + |
| 43 | + // Verify a scroll-to button works (triggers smooth scroll on the real scroll target). |
| 44 | + await page.getByRole("button", { name: "Scroll to top" }).click() |
| 45 | + await expect.poll(async () => main.evaluate((el) => el.scrollTop), { timeout: 5000 }).toBeLessThan(10) |
| 46 | + } else { |
| 47 | + const overflow = page.locator("main").locator("div[style*='overflow']").first() |
| 48 | + if ((await overflow.count()) > 0) { |
| 49 | + await overflow.evaluate((el) => { |
| 50 | + el.scrollTop = 400 |
| 51 | + }) |
| 52 | + await expect.poll(async () => overflow.evaluate((el) => (el as HTMLElement).scrollTop)).toBeGreaterThan(0) |
| 53 | + } |
| 54 | + } |
| 55 | + }) |
| 56 | + } |
| 57 | + |
| 58 | + test.describe("perf comparisons", () => { |
| 59 | + test.describe.configure({ timeout: 120_000 }) |
| 60 | + |
| 61 | + for (const path of virtualizerPerfRoutes) { |
| 62 | + test(`smoke ${path} — Zag and TanStack panels`, async ({ page }) => { |
| 63 | + const I = new Model(page) |
| 64 | + await page.goto(path) |
| 65 | + await page.waitForSelector("main", { state: "visible" }) |
| 66 | + await I.dontSeeInConsole("flushSync was called from inside a lifecycle method", 3000) |
| 67 | + await expect(page.getByRole("heading", { name: "@zag-js/virtualizer" })).toBeVisible() |
| 68 | + await expect(page.getByRole("heading", { name: "@tanstack/react-virtual" })).toBeVisible() |
| 69 | + await I.checkAccessibility("main") |
| 70 | + }) |
| 71 | + } |
| 72 | + }) |
| 73 | + |
| 74 | + for (const path of virtualizedComponentRoutes) { |
| 75 | + test(`smoke ${path}`, async ({ page }) => { |
| 76 | + const I = new Model(page) |
| 77 | + await page.goto(path) |
| 78 | + await page.waitForSelector("main", { state: "visible" }) |
| 79 | + await I.dontSeeInConsole("flushSync was called from inside a lifecycle method", 3000) |
| 80 | + await I.checkAccessibility("main") |
| 81 | + }) |
| 82 | + } |
| 83 | +}) |
0 commit comments