-
-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
const pagesWithSimpleImages = [ | ||
{ url: "/demos/background_images.html", description: "Background images" } | ||
]; | ||
|
||
for (const { url, description } of pagesWithSimpleImages) { | ||
test(description, async ({ page }) => { | ||
await page.goto(url); | ||
const lazyElements = await page.locator(".lazy"); | ||
await page.waitForLoadState("load"); | ||
const elementsCount = await lazyElements.count(); | ||
|
||
const devicePixelRatio = await page.evaluate(() => window.devicePixelRatio); | ||
|
||
// Eventually scroll into view and check if it loads | ||
for (let i = 0; i < elementsCount; i++) { | ||
const element = lazyElements.nth(i); | ||
await element.scrollIntoViewIfNeeded(); | ||
|
||
// Check the src attribute | ||
const expectedBg = await element.getAttribute("data-bg"); | ||
const expectedHiDpiBg = await element.getAttribute("data-bg-hidpi"); | ||
|
||
if (!expectedHiDpiBg) { | ||
await expect(element).toHaveAttribute("style", `background-image: url("${expectedBg}");`); | ||
continue; | ||
} | ||
|
||
if (devicePixelRatio === 1) { | ||
await expect(element).toHaveAttribute("style", `background-image: url("${expectedBg}");`); | ||
} else { | ||
await expect(element).toHaveAttribute( | ||
"style", | ||
`background-image: url("${expectedHiDpiBg}");` | ||
); | ||
} | ||
} | ||
}); | ||
} |