Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Wait for image results to load before the RTL search page snapshot (#5786)
Dhruv Bhanushali31a35a20a07a
diff --git a/frontend/test/playwright/utils/navigation.ts b/frontend/test/playwright/utils/navigation.tsindex ce95043f9..fa753946b 100644--- a/frontend/test/playwright/utils/navigation.ts+++ b/frontend/test/playwright/utils/navigation.ts@@ -404,6 +404,29 @@ export const scrollDownAndUp = async (page: Page) => {await scrollToTop(page)}+/**+ * Wait until the image results in the viewport have loaded. Results use+ * `loading="lazy"`, so images below the fold never load and are skipped.+ */+export const waitForVisibleImagesToLoad = async (page: Page) => {+ await expect+ .poll(() =>+ page.evaluate(() => {+ const images = Array.from(+ document.querySelectorAll<HTMLImageElement>("figure img")+ ).filter((img) => {+ const { top, bottom } = img.getBoundingClientRect()+ return bottom > 0 && top < window.innerHeight+ })+ return (+ images.length > 0 &&+ images.every((img) => img.complete && img.naturalWidth > 0)+ )+ })+ )+ .toBe(true)+}+/*** Adds '/ar' prefix to a rtl route, or a set locale. The path should start with '/'*/diff --git a/frontend/test/playwright/visual-regression/pages/pages.spec.ts b/frontend/test/playwright/visual-regression/pages/pages.spec.tsindex fae36464c..bc52408a0 100644--- a/frontend/test/playwright/visual-regression/pages/pages.spec.ts+++ b/frontend/test/playwright/visual-regression/pages/pages.spec.ts@@ -4,6 +4,7 @@ import breakpoints from "~~/test/playwright/utils/breakpoints"import {pathWithDir,preparePageForTests,+ waitForVisibleImagesToLoad,} from "~~/test/playwright/utils/navigation"import { languageDirections, t } from "~~/test/playwright/utils/i18n"import {@@ -76,6 +77,7 @@ test.describe("layout color is set correctly", () => {await page.waitForURL(/ar\/search/)await expect(getH1(page, "Cat")).toBeVisible()await expect(getLoadMoreButton(page, "rtl")).toBeEnabled()+ await waitForVisibleImagesToLoad(page)expect(await page.screenshot()).toMatchSnapshot("search-page-rtl-lg-light.png"