Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Fix flaky image cell test (#4968)
Olga Bulat499276274e05
diff --git a/frontend/src/components/VImageCell/VImageCell.vue b/frontend/src/components/VImageCell/VImageCell.vueindex 6cbeca221..22ecf9345 100644--- a/frontend/src/components/VImageCell/VImageCell.vue+++ b/frontend/src/components/VImageCell/VImageCell.vue@@ -37,11 +37,7 @@ const props = withDefaults()const toAbsolutePath = (url: string, prefix = "https://") => {- if (- url.startsWith("http://") ||- url.startsWith("https://") ||- url === "/openverse-default.jpg"- ) {+ if (url.startsWith("http://") || url.startsWith("https://")) {return url}return `${prefix}${url}`diff --git a/frontend/src/components/VImageCell/meta/VImageCell.stories.ts b/frontend/src/components/VImageCell/meta/VImageCell.stories.tsindex 21d79d474..85b64b97c 100644--- a/frontend/src/components/VImageCell/meta/VImageCell.stories.ts+++ b/frontend/src/components/VImageCell/meta/VImageCell.stories.ts@@ -49,9 +49,6 @@ export const Default: Story = {searchTerm: "test",relatedTo: "fake-uuid",- image: {- ...image,- thumbnail: "/openverse-default.jpg",- },+ image,},}diff --git a/frontend/test/hars/f54be427bbbd5e2a3dc4f38eda3679769eb1cb4e.webp b/frontend/test/hars/f54be427bbbd5e2a3dc4f38eda3679769eb1cb4e.webpnew file mode 100644index 000000000..e00c2e659Binary files /dev/null and b/frontend/test/hars/f54be427bbbd5e2a3dc4f38eda3679769eb1cb4e.webp differdiff --git a/frontend/test/hars/v-image-cell.har b/frontend/test/hars/v-image-cell.harnew file mode 100644index 000000000..439828655--- /dev/null+++ b/frontend/test/hars/v-image-cell.har@@ -0,0 +1,103 @@+{+ "log": {+ "version": "1.2",+ "creator": {+ "name": "Playwright",+ "version": "1.46.1"+ },+ "browser": {+ "name": "chromium",+ "version": "128.0.6613.18"+ },+ "entries": [+ {+ "startedDateTime": "2024-09-20T04:31:36.157Z",+ "time": 2.468,+ "request": {+ "method": "GET",+ "url": "https://api.openverse.org/v1/images/f166c4a0-7207-4ea2-8728-15350a60d37f/thumb/",+ "httpVersion": "HTTP/2.0",+ "cookies": [],+ "headers": [+ { "name": ":authority", "value": "api.openverse.org" },+ { "name": ":method", "value": "GET" },+ {+ "name": ":path",+ "value": "/v1/images/f166c4a0-7207-4ea2-8728-15350a60d37f/thumb/"+ },+ { "name": ":scheme", "value": "https" },+ {+ "name": "accept",+ "value": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"+ },+ { "name": "accept-encoding", "value": "gzip, deflate, br, zstd" },+ { "name": "accept-language", "value": "en-US" },+ { "name": "priority", "value": "u=1, i" },+ { "name": "referer", "value": "http://localhost:54000/" },+ {+ "name": "sec-ch-ua",+ "value": "\"Chromium\";v=\"128\", \"Not;A=Brand\";v=\"24\", \"HeadlessChrome\";v=\"128\""+ },+ { "name": "sec-ch-ua-mobile", "value": "?0" },+ { "name": "sec-ch-ua-platform", "value": "\"Android\"" },+ { "name": "sec-fetch-dest", "value": "image" },+ { "name": "sec-fetch-mode", "value": "no-cors" },+ { "name": "sec-fetch-site", "value": "cross-site" },+ {+ "name": "user-agent",+ "value": "Mozilla/5.0 (Android 7.0; Mobile; rv:54.0) Gecko/54.0 Firefox/54.0"+ }+ ],+ "queryString": [],+ "headersSize": -1,+ "bodySize": -1+ },+ "response": {+ "status": 200,+ "statusText": "",+ "httpVersion": "HTTP/2.0",+ "cookies": [],+ "headers": [+ { "name": "accept-ranges", "value": "bytes" },+ { "name": "age", "value": "339472" },+ { "name": "allow", "value": "GET, HEAD, OPTIONS" },+ { "name": "cf-cache-status", "value": "HIT" },+ { "name": "cf-ray", "value": "8c5f163cb9a7d394-FRA" },+ { "name": "content-length", "value": "18878" },+ { "name": "content-type", "value": "image/webp" },+ { "name": "cross-origin-opener-policy", "value": "same-origin" },+ { "name": "date", "value": "Fri, 20 Sep 2024 04:31:36 GMT" },+ {+ "name": "last-modified",+ "value": "Mon, 16 Sep 2024 06:13:44 GMT"+ },+ { "name": "referrer-policy", "value": "same-origin" },+ { "name": "server", "value": "cloudflare" },+ {+ "name": "vary",+ "value": "Accept, Authorization, origin, Accept-Encoding"+ },+ { "name": "x-content-type-options", "value": "nosniff" },+ { "name": "x-frame-options", "value": "DENY" },+ { "name": "x-ratelimit-available-anon_thumbnail", "value": "999" },+ { "name": "x-ratelimit-limit-anon_thumbnail", "value": "1000/day" },+ {+ "name": "x-request-id",+ "value": "fa51958d-c23a-47c9-854a-3d4f2df3e8a9"+ }+ ],+ "content": {+ "size": -1,+ "mimeType": "image/webp",+ "_file": "f54be427bbbd5e2a3dc4f38eda3679769eb1cb4e.webp"+ },+ "headersSize": -1,+ "bodySize": -1,+ "redirectURL": ""+ },+ "cache": {},+ "timings": { "send": -1, "wait": -1, "receive": 2.468 }+ }+ ]+ }+}diff --git a/frontend/test/playwright/visual-regression/pages/pages.spec.ts b/frontend/test/playwright/visual-regression/pages/pages.spec.tsindex 50a13f248..63449f647 100644--- a/frontend/test/playwright/visual-regression/pages/pages.spec.ts+++ b/frontend/test/playwright/visual-regression/pages/pages.spec.ts@@ -11,6 +11,7 @@ import {getH1,getHomepageSearchButton,getLanguageSelect,+ getLoadMoreButton,} from "~~/test/playwright/utils/components"test.describe.configure({ mode: "parallel" })@@ -75,6 +76,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()expect(await page.screenshot()).toMatchSnapshot("search-page-rtl-lg-light.png"diff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts b/frontend/test/storybook/visual-regression/v-image-cell.spec.tsindex 9b82f43ba..12cbb04f3 100644--- a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts+++ b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts@@ -1,43 +1,33 @@-import { expect, type Page, test } from "@playwright/test"+import { test } from "@playwright/test"import breakpoints from "~~/test/playwright/utils/breakpoints"import { makeUrlWithArgs } from "~~/test/storybook/utils/args"-import { sleep } from "~~/test/playwright/utils/navigation"-import { waitForResponse } from "~~/test/storybook/utils/response"import type { AspectRatio } from "~/types/media"const imageCell = "a[itemprop='contentUrl']"-const imageCellImage = `${imageCell} img`+// Necessary to make sure we can capture the focus state, which// exceeds the bounds of the actual componentconst screenshotEl = ".image-wrapper"const urlWithArgs = makeUrlWithArgs("components-vimagecell--default")-const goAndWaitForImage = async (- page: Page,- args: Record<string, string | number | boolean>-) => {- // Block the flickr direct url request so that the image cell immediately- // falls back to the local image.- await page.route("**flickr**", (route) => route.abort())- await waitForResponse(page, urlWithArgs(args), /\.jpg/)- await expect(page.locator(imageCellImage)).toBeVisible()- await sleep(500)-}-test.describe.configure({ mode: "parallel" })+const aspectRatios: AspectRatio[] = ["square", "intrinsic"]test.describe("VImageCell", () => {breakpoints.describeMobileXsAndDesktop(({ expectSnapshot }) => {- const aspectRatios: AspectRatio[] = ["square", "intrinsic"]-for (const ratio of aspectRatios) {- test(`${ratio} loaded`, async ({ page }) => {- await goAndWaitForImage(page, { aspectRatio: ratio })+ test.beforeEach(async ({ page }) => {+ await page.routeFromHAR("./test/hars/v-image-cell.har", {+ url: /\/thumb\//,+ })+ })+ test(`${ratio} loaded`, async ({ page }) => {+ await page.goto(urlWithArgs({ aspectRatio: ratio }))await expectSnapshot(page,`v-image-cell-${ratio}-loaded`,@@ -46,7 +36,7 @@ test.describe("VImageCell", () => {})test(`${ratio} focused`, async ({ page }) => {- await goAndWaitForImage(page, { aspectRatio: ratio })+ await page.goto(urlWithArgs({ aspectRatio: ratio }))await page.focus(imageCell)@@ -58,7 +48,7 @@ test.describe("VImageCell", () => {})test(`${ratio} hovered`, async ({ page }) => {- await goAndWaitForImage(page, { aspectRatio: ratio })+ await page.goto(urlWithArgs({ aspectRatio: ratio }))await page.hover(imageCell)@@ -70,7 +60,7 @@ test.describe("VImageCell", () => {})test(`${ratio} focused hovered`, async ({ page }) => {- await goAndWaitForImage(page, { aspectRatio: ratio })+ await page.goto(urlWithArgs({ aspectRatio: ratio }))await page.focus(imageCell)await page.hover(imageCell)diff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xl-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xl-light-linux.pngindex 7ef07f6ce..74346bdcc 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xl-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xl-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xs-light-linux.pngindex b7cc4aa6b..6a482ab07 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-hovered-xs-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xl-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xl-light-linux.pngindex 7ef07f6ce..74346bdcc 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xl-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xl-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xs-light-linux.pngindex b7cc4aa6b..6a482ab07 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-focused-xs-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xl-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xl-light-linux.pngindex 46fc90c6c..9f86e8287 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xl-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xl-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xs-light-linux.pngindex e0f75802d..5163f5a6b 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-hovered-xs-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xl-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xl-light-linux.pngindex 85865b209..7c6c7e48f 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xl-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xl-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xs-light-linux.pngindex 747125520..495e532d2 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-intrinsic-loaded-xs-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-hovered-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-hovered-xs-light-linux.pngindex c33cc9b8d..527a22298 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-hovered-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-hovered-xs-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xl-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xl-light-linux.pngindex 5fdb9a43b..6be7b12c9 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xl-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xl-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xs-light-linux.pngindex c33cc9b8d..527a22298 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-focused-xs-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-hovered-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-hovered-xs-light-linux.pngindex 759aeabcd..3a2e5c9bf 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-hovered-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-hovered-xs-light-linux.png differdiff --git a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-loaded-xs-light-linux.png b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-loaded-xs-light-linux.pngindex a6d68c46b..844e980ab 100644Binary files a/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-loaded-xs-light-linux.png and b/frontend/test/storybook/visual-regression/v-image-cell.spec.ts-snapshots/v-image-cell-square-loaded-xs-light-linux.png differ