|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { waitForComparisonRouteReady } from "./comparison-page"; |
| 3 | +import { pinComparisonTheme } from "./visual-diff"; |
| 4 | + |
| 5 | +test.describe("component page layout", () => { |
| 6 | + test("keeps rendered framework examples visible near the top of tall previews", async ({ |
| 7 | + page, |
| 8 | + }) => { |
| 9 | + await pinComparisonTheme(page, "dark"); |
| 10 | + await page.goto("/components/searchfield/"); |
| 11 | + await waitForComparisonRouteReady(page); |
| 12 | + |
| 13 | + const section = page.locator("#example").filter({ |
| 14 | + has: page.locator("h2", { hasText: "Example" }), |
| 15 | + }); |
| 16 | + const metrics = await section.locator(".s2-framework-panel").evaluateAll((panels) => |
| 17 | + panels.map((panel) => { |
| 18 | + const fixture = panel.querySelector<HTMLElement>("[data-comparison-control-root]"); |
| 19 | + |
| 20 | + if (fixture == null) { |
| 21 | + throw new Error("Expected framework panel to contain a rendered fixture root."); |
| 22 | + } |
| 23 | + |
| 24 | + const panelRect = panel.getBoundingClientRect(); |
| 25 | + const fixtureRect = fixture.getBoundingClientRect(); |
| 26 | + |
| 27 | + return { |
| 28 | + framework: panel.getAttribute("data-framework") ?? "unknown", |
| 29 | + fixtureTop: Number(fixtureRect.top.toFixed(4)), |
| 30 | + topOffset: Number((fixtureRect.top - panelRect.top).toFixed(4)), |
| 31 | + viewportHeight: window.innerHeight, |
| 32 | + }; |
| 33 | + }), |
| 34 | + ); |
| 35 | + |
| 36 | + expect(metrics).toHaveLength(2); |
| 37 | + |
| 38 | + for (const metric of metrics) { |
| 39 | + expect( |
| 40 | + metric.fixtureTop, |
| 41 | + `${metric.framework} fixture should be in the initial viewport`, |
| 42 | + ).toBeLessThan(metric.viewportHeight); |
| 43 | + expect( |
| 44 | + metric.topOffset, |
| 45 | + `${metric.framework} fixture should not be vertically centered below tall controls`, |
| 46 | + ).toBeLessThanOrEqual(160); |
| 47 | + } |
| 48 | + }); |
| 49 | +}); |
0 commit comments