Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Fix narrow width audio results (#1281)
sarayourfriend491c640c1b96
diff --git a/src/components/VAudioTrack/layouts/VRowLayout.vue b/src/components/VAudioTrack/layouts/VRowLayout.vueindex eaa8aa326..772daa361 100644--- a/src/components/VAudioTrack/layouts/VRowLayout.vue+++ b/src/components/VAudioTrack/layouts/VRowLayout.vue@@ -65,9 +65,9 @@</div><div+ v-show="!isSmall"class="flex flex-row":class="{- hidden: isSmall,'flex-grow': isMedium,}">diff --git a/src/pages/search/audio.vue b/src/pages/search/audio.vueindex d9a5b6ac1..0323ba0f0 100644--- a/src/pages/search/audio.vue+++ b/src/pages/search/audio.vue@@ -56,12 +56,12 @@ const AudioSearch = defineComponent({const results = computed(() => props.resultItems.audio)- const isMinScreenMd = isMinScreen('md', { shouldPassInSSR: false })+ const isMinScreenMd = isMinScreen('md', { shouldPassInSSR: true })// On SSR, we set the size to small if the User Agent is mobile, otherwise we set the size to medium.const isMobile = useBrowserIsMobile()const audioTrackSize = computed(() => {- return !isMinScreenMd.value && isMobile+ return !isMinScreenMd.value || isMobile? 's': props.isFilterVisible? 'l'diff --git a/test/playwright/README.md b/test/playwright/README.mdindex 70e2c272e..a1393b17f 100644--- a/test/playwright/README.md+++ b/test/playwright/README.md@@ -45,6 +45,12 @@ The describe blocks are passed the following helpers:- `getConfigValues`: Returns useful configuration values if running a snapshot test manually.- `expectSnapshot`: A function accepting an identifier and a screenshot-able object. This will generate the screenshot and match it against a snapshot matching the name passed. Remember to `await` this function or else the `expect` will not be fired within the context of the test (you'll get a nasty error in this case).+Optionally, you may pass a configuration object as the first argument to the `breakpoints.describe*` functions. If you do this, then the describe block is the second argument.++The configuration object currently supports the following options:++- `uaMocking`: This `boolean` option defaults to `true`. When enabled, it will use a mock mobile browser user agent string for narrow viewports. Setting it to `false` for viewport widths above `md` (inclusive) is a no-op.+Please see the [`homepage.spec.ts` visual-regression tests](./visual-regression/homepage.spec.ts) as an example of how to use these helpers.### What to test for visual regressiondiff --git a/test/playwright/utils/breakpoints.ts b/test/playwright/utils/breakpoints.tsindex 93ad1af93..5722b71cc 100644--- a/test/playwright/utils/breakpoints.ts+++ b/test/playwright/utils/breakpoints.ts@@ -42,14 +42,39 @@ const mockUaStrings: Readonly<Record<Breakpoint, string | undefined>> =]))+interface Options {+ /**+ * Whether to mock the UA for mobile browsers.+ *+ * @defaultValue true+ */+ uaMocking: boolean+}++const defaultOptions = Object.freeze({+ uaMocking: true,+})+const makeBreakpointDescribe =- (breakpoint: Breakpoint, screenWidth: number) => (block: BreakpointBlock) => {+ (breakpoint: Breakpoint, screenWidth: number) =>+ <T extends BreakpointBlock | Options>(+ blockOrOptions: T,+ block?: T extends Record<string, unknown> ? BreakpointBlock : undefined+ ) => {test.describe(`screen at breakpoint ${breakpoint} with width ${screenWidth}`,() => {+ const _block = (+ typeof blockOrOptions === 'function' ? blockOrOptions : block+ ) as BreakpointBlock+ const options =+ typeof blockOrOptions !== 'function'+ ? { ...defaultOptions, ...blockOrOptions }+ : defaultOptions+test.use({viewport: { width: screenWidth, height: 700 },- userAgent: mockUaStrings[breakpoint],+ userAgent: options.uaMocking ? mockUaStrings[breakpoint] : undefined,})const getConfigValues = (name: string) => ({@@ -69,7 +94,7 @@ const makeBreakpointDescribe =})}- block({ breakpoint, getConfigValues, expectSnapshot })+ _block({ breakpoint, getConfigValues, expectSnapshot })})}@@ -92,14 +117,18 @@ const breakpointTests = Array.from(SCREEN_SIZES.entries()).reduce()const describeEachBreakpoint =- (breakpoints: readonly Breakpoint[]) => (block: BreakpointBlock) => {+ (breakpoints: readonly Breakpoint[]) =>+ <T extends BreakpointBlock | Options>(+ blockOrOptions: T,+ block?: T extends Record<string, unknown> ? BreakpointBlock : undefined+ ) => {Object.entries(breakpointTests).forEach(([bp, describe]) => {if (breakpoints.includes(bp.replace('describe', '').toLowerCase() as Breakpoint))- describe(block)+ describe(blockOrOptions, block)})}diff --git a/test/playwright/visual-regression/audio-results.spec.ts b/test/playwright/visual-regression/audio-results.spec.tsnew file mode 100644index 000000000..b5fad26d4--- /dev/null+++ b/test/playwright/visual-regression/audio-results.spec.ts@@ -0,0 +1,31 @@+import { test } from '@playwright/test'++import breakpoints from '~~/test/playwright/utils/breakpoints'++test.describe('audio results', () => {+ test.beforeEach(async ({ page }) => {+ await page.goto('/search/audio?q=birds')+ })++ breakpoints.describeEachMobile({ uaMocking: false }, ({ expectSnapshot }) => {+ test('should render small row layout desktop UA with narrow viewport', async ({+ page,+ }) => {+ await expectSnapshot('audio-results-narrow-viewport-desktop-UA', page)+ })+ })++ breakpoints.describeEachMobile({ uaMocking: true }, ({ expectSnapshot }) => {+ test('should render small row layout mobile UA with narrow viewport', async ({+ page,+ }) => {+ await expectSnapshot('audio-results-narrow-viewport-mobile-UA', page)+ })+ })++ breakpoints.describeEachDesktop(({ expectSnapshot }) => {+ test('desktop audio results', async ({ page }) => {+ await expectSnapshot('audio-results-desktop', page)+ })+ })+})diff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-2xl-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-2xl-linux.pngnew file mode 100644index 000000000..da4fe8934Binary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-2xl-linux.png differdiff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-lg-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-lg-linux.pngnew file mode 100644index 000000000..20072cba1Binary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-lg-linux.png differdiff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-md-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-md-linux.pngnew file mode 100644index 000000000..8631102dfBinary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-md-linux.png differdiff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-xl-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-xl-linux.pngnew file mode 100644index 000000000..bdd4f0594Binary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-desktop-xl-linux.png differdiff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-desktop-UA-sm-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-desktop-UA-sm-linux.pngnew file mode 100644index 000000000..0c4e38e08Binary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-desktop-UA-sm-linux.png differdiff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-desktop-UA-xs-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-desktop-UA-xs-linux.pngnew file mode 100644index 000000000..0d1ae01d3Binary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-desktop-UA-xs-linux.png differdiff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-sm-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-sm-linux.pngnew file mode 100644index 000000000..9d2ec1f18Binary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-sm-linux.png differdiff --git a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-xs-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-xs-linux.pngnew file mode 100644index 000000000..1afd13b92Binary files /dev/null and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-xs-linux.png differ