|
| 1 | +import { chromium, type Browser } from "playwright"; |
| 2 | +import { afterAll, beforeAll, describe, expect, it } from "vitest"; |
| 3 | +import { readStyleSheet } from "../../../test/helpers/ui-style-fixtures.js"; |
| 4 | +import { |
| 5 | + canRunPlaywrightChromium, |
| 6 | + resolvePlaywrightChromiumExecutablePath, |
| 7 | +} from "../test-helpers/control-ui-e2e.ts"; |
| 8 | + |
| 9 | +const chromiumExecutablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath()); |
| 10 | +const describeShimmer = canRunPlaywrightChromium(chromiumExecutablePath) ? describe : describe.skip; |
| 11 | + |
| 12 | +let browser: Browser; |
| 13 | + |
| 14 | +beforeAll(async () => { |
| 15 | + if (!canRunPlaywrightChromium(chromiumExecutablePath)) { |
| 16 | + return; |
| 17 | + } |
| 18 | + browser = await chromium.launch({ executablePath: chromiumExecutablePath, headless: true }); |
| 19 | +}); |
| 20 | + |
| 21 | +afterAll(async () => { |
| 22 | + await browser?.close().catch(() => {}); |
| 23 | +}); |
| 24 | + |
| 25 | +describeShimmer("Control UI shimmer", () => { |
| 26 | + it("moves loading highlights on compositor-safe pseudo-elements", async () => { |
| 27 | + const page = await browser.newPage(); |
| 28 | + try { |
| 29 | + await page.setContent(`<!doctype html><html><head><style> |
| 30 | + ${readStyleSheet("ui/src/styles/base.css")} |
| 31 | + ${readStyleSheet("ui/src/styles/memory-import.css")} |
| 32 | + ${readStyleSheet("ui/src/styles/usage.css")} |
| 33 | + </style></head><body> |
| 34 | + <div class="skeleton skeleton-line"></div> |
| 35 | + <div class="skeleton usage-skeleton-block"></div> |
| 36 | + <div class="skeleton memory-import__skeleton"></div> |
| 37 | + </body></html>`); |
| 38 | + |
| 39 | + for (const selector of [ |
| 40 | + ".skeleton-line", |
| 41 | + ".usage-skeleton-block", |
| 42 | + ".memory-import__skeleton", |
| 43 | + ]) { |
| 44 | + const styles = await page.locator(selector).evaluate((element) => { |
| 45 | + const host = getComputedStyle(element); |
| 46 | + const highlight = getComputedStyle(element, "::after"); |
| 47 | + return { |
| 48 | + hostAnimation: host.animationName, |
| 49 | + hostBackground: host.backgroundImage, |
| 50 | + hostOverflow: host.overflow, |
| 51 | + highlightAnimation: highlight.animationName, |
| 52 | + highlightBackground: highlight.backgroundImage, |
| 53 | + highlightWillChange: highlight.willChange, |
| 54 | + }; |
| 55 | + }); |
| 56 | + |
| 57 | + expect(styles).toMatchObject({ |
| 58 | + hostAnimation: "none", |
| 59 | + hostBackground: "none", |
| 60 | + hostOverflow: "hidden", |
| 61 | + highlightAnimation: "shimmer", |
| 62 | + highlightWillChange: "transform", |
| 63 | + }); |
| 64 | + expect(styles.highlightBackground).toContain("linear-gradient"); |
| 65 | + } |
| 66 | + } finally { |
| 67 | + await page.close().catch(() => {}); |
| 68 | + } |
| 69 | + }); |
| 70 | + |
| 71 | + it("keeps the global reduced-motion gate", async () => { |
| 72 | + const page = await browser.newPage({ reducedMotion: "reduce" }); |
| 73 | + try { |
| 74 | + await page.setContent(`<!doctype html><html><head><style> |
| 75 | + ${readStyleSheet("ui/src/styles/base.css")} |
| 76 | + ${readStyleSheet("ui/src/styles/memory-import.css")} |
| 77 | + ${readStyleSheet("ui/src/styles/usage.css")} |
| 78 | + </style></head><body> |
| 79 | + <div class="skeleton skeleton-line"></div> |
| 80 | + <div class="skeleton usage-skeleton-block"></div> |
| 81 | + <div class="skeleton memory-import__skeleton"></div> |
| 82 | + </body></html>`); |
| 83 | + |
| 84 | + for (const selector of [ |
| 85 | + ".skeleton-line", |
| 86 | + ".usage-skeleton-block", |
| 87 | + ".memory-import__skeleton", |
| 88 | + ]) { |
| 89 | + const animation = await page.locator(selector).evaluate((element) => { |
| 90 | + const highlight = getComputedStyle(element, "::after"); |
| 91 | + return { |
| 92 | + duration: highlight.animationDuration, |
| 93 | + iterations: highlight.animationIterationCount, |
| 94 | + }; |
| 95 | + }); |
| 96 | + |
| 97 | + expect(animation).toEqual({ duration: "1e-05s", iterations: "1" }); |
| 98 | + } |
| 99 | + } finally { |
| 100 | + await page.close().catch(() => {}); |
| 101 | + } |
| 102 | + }); |
| 103 | +}); |
0 commit comments