Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Fix unruly URLs in source page table for small viewports (#1241)

sarayourfriend32ce30625757
diff --git a/bin/playwright.sh b/bin/playwright.sh
index f075a24bd..10d264aef 100755
--- a/bin/playwright.sh
+++ b/bin/playwright.sh
@@ -10,4 +10,4 @@ export PLAYWRIGHT_VERSION=$(version)
echo Running Playwright v$PLAYWRIGHT_VERSION as $USER_ID with Playwright arguments $PLAYWRIGHT_ARGS
-docker-compose -f docker-compose.playwright.yml up --abort-on-container-exit --exit-code-from playwright
+docker-compose -f docker-compose.playwright.yml up --build --force-recreate --abort-on-container-exit --exit-code-from playwright
diff --git a/package.json b/package.json
index d4963b902..e17122999 100644
--- a/package.json
+++ b/package.json
@@ -101,7 +101,7 @@
"@nuxtjs/storybook": "^4.3.0",
"@nuxtjs/style-resources": "^1.0.0",
"@pinia/testing": "^0.0.11",
- "@playwright/test": "^1.16.2",
+ "@playwright/test": "^1.20.2",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/user-event": "^13.5.0",
"@testing-library/vue": "^5.8.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fa9280d96..2d4e19531 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -20,7 +20,7 @@ specifiers:
'@nuxtjs/svg': ^0.3.0
'@pinia/nuxt': ^0.1.8
'@pinia/testing': ^0.0.11
- '@playwright/test': ^1.16.2
+ '@playwright/test': ^1.20.2
'@popperjs/core': ^2.11.2
'@tailwindcss/line-clamp': ^0.3.1
'@tailwindcss/typography': ^0.5.2
diff --git a/src/pages/sources.vue b/src/pages/sources.vue
index 3f18c55cf..74800ed22 100644
--- a/src/pages/sources.vue
+++ b/src/pages/sources.vue
@@ -122,9 +122,9 @@
<td>
{{ imageProvider.display_name }}
</td>
- <td class="font-semibold">
+ <td class="font-semibold truncate">
<VLink :href="imageProvider.source_url">
- {{ imageProvider.source_url }}
+ {{ cleanSourceUrlForPresentation(imageProvider.source_url) }}
</VLink>
</td>
<td class="number-cell">
@@ -183,6 +183,14 @@ const SourcePage = {
this.sort = { direction, field }
},
+ cleanSourceUrlForPresentation(url) {
+ const stripProtocol = (s) => s.replace(/https?:\/\//, '')
+ const stripLeadingWww = (s) =>
+ s.startsWith('www.') ? s.replace('www.', '') : s
+ const stripTrailingSlash = (s) => (s.endsWith('/') ? s.slice(0, -1) : s)
+
+ return stripTrailingSlash(stripLeadingWww(stripProtocol(url)))
+ },
},
head() {
return {
diff --git a/test/playwright/utils/breakpoints.ts b/test/playwright/utils/breakpoints.ts
index fd2975df6..93ad1af93 100644
--- a/test/playwright/utils/breakpoints.ts
+++ b/test/playwright/utils/breakpoints.ts
@@ -8,10 +8,15 @@ import {
type Breakpoint = Exclude<AllBreakpoints, 'mob'>
type ScreenshotAble = {
- screenshot(): Promise<Buffer>
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ screenshot(...args: any[]): Promise<Buffer>
}
-type ExpectSnapshot = (name: string, s: ScreenshotAble) => Promise<Buffer>
+type ExpectSnapshot = <T extends ScreenshotAble>(
+ name: string,
+ s: T,
+ options?: Parameters<T['screenshot']>[0]
+) => Promise<Buffer>
type BreakpointBlock = (options: {
getConfigValues: (name: string) => {
@@ -46,15 +51,20 @@ const makeBreakpointDescribe =
viewport: { width: screenWidth, height: 700 },
userAgent: mockUaStrings[breakpoint],
})
+
const getConfigValues = (name: string) => ({
name: `${name}-${breakpoint}.png` as const,
})
- const expectSnapshot = async (
+
+ const expectSnapshot = async <T extends ScreenshotAble>(
name: string,
- screenshotAble: ScreenshotAble
+ screenshotAble: T,
+ options?: Parameters<T['screenshot']>[0]
) => {
const { name: snapshotName } = getConfigValues(name)
- return expect(await screenshotAble.screenshot()).toMatchSnapshot({
+ return expect(
+ await screenshotAble.screenshot(options)
+ ).toMatchSnapshot({
name: snapshotName,
})
}
diff --git a/test/playwright/utils/page.ts b/test/playwright/utils/page.ts
new file mode 100644
index 000000000..0a8c03ebf
--- /dev/null
+++ b/test/playwright/utils/page.ts
@@ -0,0 +1,19 @@
+import type { Page } from '@playwright/test'
+
+export const removeHiddenOverflow = async (page: Page) => {
+ const mainElement = await page.$('.main.embedded.overflow-x-hidden')
+ await mainElement?.evaluate((node) =>
+ node.classList.remove('main', 'embedded', 'overflow-x-hidden')
+ )
+ mainElement?.dispose()
+
+ const appElement = await page.$('.app.grid.h-screen.overflow-hidden.relative')
+ await appElement?.evaluate((node) => node.classList.remove('overflow-hidden'))
+ appElement?.dispose()
+}
+
+export const hideInputCursors = (page: Page) => {
+ return page.addStyleTag({
+ content: '* { caret-color: transparent !important; }',
+ })
+}
diff --git a/test/playwright/visual-regression/homepage.spec.ts b/test/playwright/visual-regression/homepage.spec.ts
index f3b8dae3e..96b386988 100644
--- a/test/playwright/visual-regression/homepage.spec.ts
+++ b/test/playwright/visual-regression/homepage.spec.ts
@@ -1,6 +1,7 @@
import { test, Page } from '@playwright/test'
import breakpoints from '~~/test/playwright/utils/breakpoints'
+import { hideInputCursors } from '~~/test/playwright/utils/page'
const deleteImageCarousel = async (page: Page) => {
const element = await page.$('[data-testid="image-carousel"]')
@@ -32,6 +33,7 @@ test.describe('homepage snapshots', () => {
test('focused', async ({ page }) => {
await page.focus('input')
+ await hideInputCursors(page)
await expectSnapshot(
'focused-search-ltr',
page.locator('form:has(input)')
@@ -64,6 +66,7 @@ test.describe('homepage snapshots', () => {
test('focused', async ({ page }) => {
await page.focus('input')
+ await hideInputCursors(page)
await expectSnapshot(
'focused-search-rtl',
page.locator('form:has(input)')
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-2xl-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-2xl-linux.png
index 4f6079fd6..9bf574502 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-2xl-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-2xl-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-lg-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-lg-linux.png
index 2563a4268..daba1bc13 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-lg-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-lg-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-md-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-md-linux.png
index 3b64f56f5..c47aef271 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-md-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-md-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-sm-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-sm-linux.png
index ad30069a1..dce349ec2 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-sm-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-sm-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xl-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xl-linux.png
index dfc5e6aff..e33a6ecf3 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xl-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xl-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xs-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xs-linux.png
index f01e25836..95c643329 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xs-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-ltr-xs-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-2xl-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-2xl-linux.png
index 2203c3395..16d69b150 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-2xl-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-2xl-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-lg-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-lg-linux.png
index d379754c7..fb5e4faab 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-lg-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-lg-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-md-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-md-linux.png
index 29b1ae3f5..b4a7e09ad 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-md-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-md-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-sm-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-sm-linux.png
index 39d1288ec..85f3232c9 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-sm-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-sm-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xl-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xl-linux.png
index 93145ffdc..b4a7e09ad 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xl-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xl-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xs-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xs-linux.png
index fe064b6b4..c0ba29813 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xs-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/focused-search-rtl-xs-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts b/test/playwright/visual-regression/sources.spec.ts
new file mode 100644
index 000000000..d30c853e2
--- /dev/null
+++ b/test/playwright/visual-regression/sources.spec.ts
@@ -0,0 +1,32 @@
+import { test } from '@playwright/test'
+
+import breakpoints from '~~/test/playwright/utils/breakpoints'
+import { removeHiddenOverflow } from '~~/test/playwright/utils/page'
+
+test.describe('sources page snapshots', () => {
+ test.describe('ltr', () => {
+ test.beforeEach(async ({ page }) => {
+ await page.goto('/sources')
+ })
+
+ breakpoints.describeEvery(({ expectSnapshot }) => {
+ test('top', async ({ page }) => {
+ await removeHiddenOverflow(page)
+ await expectSnapshot('sources-ltr', page, { fullPage: true })
+ })
+ })
+ })
+
+ test.describe('rtl', () => {
+ test.beforeEach(async ({ page }) => {
+ await page.goto('/ar/sources')
+ })
+
+ breakpoints.describeEvery(({ expectSnapshot }) => {
+ test('top', async ({ page }) => {
+ await removeHiddenOverflow(page)
+ await expectSnapshot('sources-rtl', page, { fullPage: true })
+ })
+ })
+ })
+})
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-2xl-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-2xl-linux.png
new file mode 100644
index 000000000..23d04d1cf
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-2xl-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-lg-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-lg-linux.png
new file mode 100644
index 000000000..a07c47ca5
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-lg-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-md-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-md-linux.png
new file mode 100644
index 000000000..4f5817f83
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-md-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-sm-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-sm-linux.png
new file mode 100644
index 000000000..ea4d7a104
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-sm-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-xl-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-xl-linux.png
new file mode 100644
index 000000000..6a0209782
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-xl-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-xs-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-xs-linux.png
new file mode 100644
index 000000000..c009fd04f
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-ltr-xs-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-2xl-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-2xl-linux.png
new file mode 100644
index 000000000..2c4bbebd6
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-2xl-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-lg-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-lg-linux.png
new file mode 100644
index 000000000..e9171cd74
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-lg-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-md-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-md-linux.png
new file mode 100644
index 000000000..fc2a1a458
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-md-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-sm-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-sm-linux.png
new file mode 100644
index 000000000..9c375655e
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-sm-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xl-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xl-linux.png
new file mode 100644
index 000000000..6456bd246
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xl-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xs-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xs-linux.png
new file mode 100644
index 000000000..0a002d34b
Binary files /dev/null and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xs-linux.png differ
diff --git a/test/proxy.js b/test/proxy.js
index 33c26e4b9..8463bf333 100644
--- a/test/proxy.js
+++ b/test/proxy.js
@@ -152,7 +152,7 @@ const opts = /** @type {Partial<TalkbackOptions>} */ ({
record: recordMode,
fallbackMode: talkback.Options.FallbackMode.NOT_FOUND,
ignoreBody: true,
- ignoreHeaders: ['user-agent', 'origin', 'referrer', 'content-length', 'host'],
+ allowHeaders: ['connection'],
name: 'Openverse e2e proxy',
summary: false,
tapeNameGenerator,