Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Remove `mob` breakpoint and simplify VFilterButton (#1275)
sarayourfriend55e632c63986
diff --git a/src/components/VContentSwitcher/VSearchTypeButton.vue b/src/components/VContentSwitcher/VSearchTypeButton.vueindex 5442ff5f1..873c3510e 100644--- a/src/components/VContentSwitcher/VSearchTypeButton.vue+++ b/src/components/VContentSwitcher/VSearchTypeButton.vue@@ -3,7 +3,7 @@class="flex flex-row font-semibold py-2 text-sr md:text-base":class="[sizeClasses,- showLabel ? 'max-w-[10rem] sm:max-w-[20rem] md:max-w-[16rem]' : '',+ isHeaderScrolled ? 'max-w-[10rem] sm:max-w-[20rem] md:max-w-[16rem]' : '',]":variant="buttonVariant"size="disabled"@@ -13,9 +13,8 @@><VIcon :icon-path="icon" /><span- v-show="showLabel"- class="hidden xs:block"- :class="{ 'ms-2 truncate text-left': showLabel }"+ class="md:block md:ms-2 md:truncate md:text-left"+ :class="isHeaderScrolled ? 'hidden' : 'block ms-2 truncate text-left'">{{ buttonLabel }}</span><VIcon@@ -103,16 +102,12 @@ export default defineComponent({}[props.activeItem]return i18n.t(labelKey)})- const showLabel = computed(- () => isMinScreenMd.value || !isHeaderScrolled?.value- )return {buttonVariant,sizeClasses,buttonLabel,caretDownIcon,- showLabel,isHeaderScrolled,isMinScreenMd,icon: computed(() => icons[activeItem.value]),diff --git a/src/components/VFilters/VSearchGridFilter.vue b/src/components/VFilters/VSearchGridFilter.vueindex 5a11e1d20..57a47e59d 100644--- a/src/components/VFilters/VSearchGridFilter.vue+++ b/src/components/VFilters/VSearchGridFilter.vue@@ -1,10 +1,11 @@<template>- <div+ <section+ id="filters"+ aria-labelledby="filters-heading"class="filters py-8 px-10 min-h-full md:bg-dark-charcoal-06"- data-testid="filters-list"><div class="flex items-center justify-between mt-2 mb-6">- <h4 class="text-sr font-semibold py-2 uppercase">+ <h4 id="filters-heading" class="text-sr font-semibold py-2 uppercase">{{ $t('filter-list.filter-by') }}</h4><button@@ -36,7 +37,7 @@{{ $t('filter-list.show') }}</button></footer>- </div>+ </section></template><script>diff --git a/src/components/VHeader/VFilterButton.vue b/src/components/VHeader/VFilterButton.vueindex 435beb65c..637bd8c1e 100644--- a/src/components/VHeader/VFilterButton.vue+++ b/src/components/VHeader/VFilterButton.vue@@ -3,27 +3,35 @@:variant="variant"size="disabled"class="self-center gap-2 align-center font-semibold py-2 flex-shrink-0 focus-visible:border-tx focus-visible:ring focus-visible:ring-pink"- :class="{- 'px-3': !isIconButton,- 'w-10 h-10 px-0': isIconButton,- }"+ :class="+ filtersAreApplied+ ? 'px-3 flex-shrink-0'+ : 'w-10 md:w-auto h-10 md:h-auto px-0 md:px-3'+ ":pressed="pressed"- aria-controls="filter-sidebar"- :aria-label="label"- @click="toggleFilters"+ aria-controls="filters"+ :aria-label="mdMinLabel"+ @click="$emit('toggle')">- <VIcon v-show="showIcon" :icon-path="filterIcon" />- <span v-show="showLabel" data-testid="filterbutton-label">{{ label }}</span>+ <VIcon+ :class="filtersAreApplied ? 'hidden' : 'block'"+ :icon-path="filterIcon"+ />+ <span class="hidden md:inline-block">{{ mdMinLabel }}</span>+ <span class="md:hidden" :class="!filtersAreApplied && 'hidden'">{{+ smMaxLabel+ }}</span></VButton></template>-<script>+<script lang="ts">import {computed,defineComponent,inject,toRefs,useContext,+ ref,} from '@nuxtjs/composition-api'import { useSearchStore } from '~/stores/search'@@ -45,12 +53,13 @@ const VFilterButton = defineComponent({default: false,},},- setup(props, { emit }) {+ emits: ['toggle'],+ setup(props) {const { i18n } = useContext()const searchStore = useSearchStore()const { pressed } = toRefs(props)- const isMinScreenMd = inject('isMinScreenMd', false)- const isHeaderScrolled = inject('isHeaderScrolled', false)+ const isMinScreenMd = inject('isMinScreenMd', ref(false))+ const isHeaderScrolled = inject('isHeaderScrolled', ref(false))const filterCount = computed(() => searchStore.appliedFilterCount)const filtersAreApplied = computed(() => filterCount.value > 0)@@ -75,58 +84,32 @@ const VFilterButton = defineComponent({return value})- const label = computed(() => {- // Below medium viewport logic- if (!isMinScreenMd.value) {- return isHeaderScrolled.value- ? filterCount.value- : i18n.tc('header.filter-button.with-count', filterCount.value)- }- // Above the medium viewport, show the count when filters are applied.- return filtersAreApplied.value- ? i18n.tc('header.filter-button.with-count', filterCount.value)- : i18n.t('header.filter-button.simple')- })-/**- * Whether to show the filter icon,- * based on viewport and the application of filters.+ * This label's verbosity makes it useful for the aria-label+ * where it is also used, especially on mobile where the+ * label would just be the number of applied filters, and therefore+ * basically useless as far as a label is concerned!*/- const showIcon = computed(() => {- // When filters are applied, hide the icon- if (filtersAreApplied.value) {- return false- }- // Below the medium viewport, only show when there's no filters applied.- if (!isMinScreenMd.value) {- return !isHeaderScrolled.value || !filtersAreApplied.value- }- return true- })+ const mdMinLabel = computed(() =>+ filtersAreApplied.value+ ? i18n.tc('header.filter-button.with-count', filterCount.value)+ : i18n.t('header.filter-button.simple')+ )- // Hide the label entirely when no filters are applied on mobile.- const showLabel = computed(() => {- return !(!isMinScreenMd.value && !filtersAreApplied.value)- })- const isIconButton = computed(- () =>- !isMinScreenMd.value &&- (!filtersAreApplied.value ||- (filtersAreApplied.value && isHeaderScrolled.value))+ const smMaxLabel = computed(() =>+ isHeaderScrolled.value+ ? filterCount.value+ : i18n.tc('header.filter-button.with-count', filterCount.value))+return {filterCount,filterIcon,- label,- showIcon,- showLabel,- toggleFilters: () => {- emit('toggle')- },+ mdMinLabel,+ smMaxLabel,variant,- isMinScreenMd,isHeaderScrolled,- isIconButton,+ filtersAreApplied,}},})diff --git a/src/components/VHeader/VHeaderFilter.vue b/src/components/VHeader/VHeaderFilter.vueindex ae7f34631..3d6709f62 100644--- a/src/components/VHeader/VHeaderFilter.vue+++ b/src/components/VHeader/VHeaderFilter.vue@@ -4,9 +4,9 @@class="flex justify-end items-stretch text-sr md:text-base"><VFilterButton- v-show="isMinScreenMd || (!isMinScreenMd && !visibleRef)"ref="buttonRef"class="self-stretch"+ :class="visibleRef ? 'hidden md:flex' : 'flex'":pressed="visibleRef"v-bind="triggerA11yProps"@toggle="onTriggerClick"diff --git a/src/components/VHeader/VLogoButton.vue b/src/components/VHeader/VLogoButton.vueindex ebe65560e..a5a9e86ed 100644--- a/src/components/VHeader/VLogoButton.vue+++ b/src/components/VHeader/VLogoButton.vue@@ -11,9 +11,11 @@:auto-resize="autoResizeLogo"/><OpenverseLogoText- v-if="!isHeaderScrolled"- class="hidden xs:block -ml-1 mt-1 me-3"- :class="{ 'md:hidden': isSearchRoute }"+ v-show="!isHeaderScrolled"+ class="-ml-1 mt-1 me-3"+ :class="{+ 'hidden sm:block md:hidden': isSearchRoute,+ }"width="95"height="15"/>diff --git a/src/components/VHeader/meta/VFilterButton.stories.mdx b/src/components/VHeader/meta/VFilterButton.stories.mdxindex 72c2b9a60..da896ca3d 100644--- a/src/components/VHeader/meta/VFilterButton.stories.mdx+++ b/src/components/VHeader/meta/VFilterButton.stories.mdx@@ -5,31 +5,65 @@ import {Meta,Story,} from '@storybook/addon-docs'+import { provide, ref } from '@nuxtjs/composition-api'import VFilterButton from '~/components/VHeader/VFilterButton.vue'+import { useSearchStore } from '~/stores/search'+import { filterData, mediaFilterKeys } from '~/constants/filters'+import { IMAGE } from '~/constants/media'<Metatitle="Components/VHeader/VFilterButton"component={VFilterButton}argTypes={{- input: {- action: 'input',+ pressed: {+ type: 'boolean',},- submit: {- action: 'submit',+ appliedFilters: {+ type: 'number',+ },+ scrolled: {+ type: 'boolean',+ },+ isMinMd: {+ type: 'boolean',},}}/>export const Template = (args, { argTypes }) => ({- template: `- <VFilterButton v-bind="$props" v-on="$props" />`,+ template: `<VFilterButton v-bind="args" />`,components: { VFilterButton },props: Object.keys(argTypes),- store: new Vuex.Store({- getters: {- 'search/appliedFilterTags': () => [{ code: 'by', filterType: 'license' }],- },- }),+ setup() {+ const searchStore = useSearchStore()+ searchStore.setSearchType(IMAGE)+ function applyNFilters(filterCount) {+ const filterTypes = [...mediaFilterKeys[IMAGE]]+ let filterIdx = 0+ // Skip license type filters as they can disable license filters+ let filterTypeIdx = 1+ for (let i = 0; i < filterCount; i++) {+ let filterType = filterTypes[filterTypeIdx]+ searchStore.toggleFilter({+ filterType,+ codeIdx: filterIdx,+ })+ filterIdx += 1+ if (filterData[filterType].length === filterIdx) {+ filterTypeIdx += 1+ filterIdx = 0+ }+ }+ }+ applyNFilters(args.appliedFilters)+ if (args.scrolled) {+ provide('isHeaderScrolled', ref(true))+ }+ if (args.isMinMd) {+ provide('isMinScreenMd', ref(true))+ }+ return { args }+ },})# Filter button@@ -44,22 +78,12 @@ the field receives an input. It also emits the `search` event when the searchbutton is clicked.<Canvas>- <Story- name="Default"- args={{- value: 'Search query',- }}- >- {Template.bind({})}- </Story>+ <Story name="Default">{Template.bind({})}</Story></Canvas><Canvas><Storyname="Mobile Scrolled"- args={{- isScrolled: true,- }}parameters={{viewport: {defaultViewport: 'iphonex',diff --git a/src/composables/use-active-audio.js b/src/composables/use-active-audio.tssimilarity index 68%rename from src/composables/use-active-audio.jsrename to src/composables/use-active-audio.tsindex 2d52ee375..3431e6467 100644--- a/src/composables/use-active-audio.js+++ b/src/composables/use-active-audio.ts@@ -3,10 +3,8 @@ import { ref } from '@nuxtjs/composition-api'/*** This global ref is SSR safe because it will only* change internal value based on client side interaction.- *- * @type {import('@nuxtjs/composition-api').Ref<HTMLAudioElement | undefined>}*/-const obj = ref(undefined)+const obj = ref<HTMLAudioElement | undefined>(undefined)export function useActiveAudio() {return Object.freeze({ obj })diff --git a/src/composables/use-browser-detection.js b/src/composables/use-browser-detection.tssimilarity index 100%rename from src/composables/use-browser-detection.jsrename to src/composables/use-browser-detection.tsdiff --git a/src/composables/use-get-locale-formatted-number.js b/src/composables/use-get-locale-formatted-number.tssimilarity index 80%rename from src/composables/use-get-locale-formatted-number.jsrename to src/composables/use-get-locale-formatted-number.tsindex 26046463d..ee5309097 100644--- a/src/composables/use-get-locale-formatted-number.js+++ b/src/composables/use-get-locale-formatted-number.ts@@ -21,13 +21,8 @@ const WESTERN_ARABIC_NUMERALS = [export const useGetLocaleFormattedNumber = () => {const { i18n } = useContext()- /**- * @param {number} n The number to format- */- return (n) => {- let { locale } = i18n-- const testFormat = n.toLocaleString(locale)+ return (n: number) => {+ const testFormat = n.toLocaleString(i18n.locale)if (WESTERN_ARABIC_NUMERALS.some((numeral) => testFormat.includes(numeral))diff --git a/src/composables/use-media-query.js b/src/composables/use-media-query.tssimilarity index 63%rename from src/composables/use-media-query.jsrename to src/composables/use-media-query.tsindex 0081107fd..5d42f2e8a 100644--- a/src/composables/use-media-query.js+++ b/src/composables/use-media-query.ts@@ -2,23 +2,21 @@which, in turn, is ported from https://github.com/logaretm/vue-use-web by Abdelrahman Awad */import { onBeforeUnmount, ref } from '@nuxtjs/composition-api'-import { SCREEN_SIZES } from '~/constants/screens'-import { defaultWindow } from '~/composables/window'+import { SCREEN_SIZES, Breakpoint } from '~/constants/screens'+import { defaultWindow } from '~/constants/window'-/**- * @typedef Options- * @property {boolean} [shouldPassInSSR]- * @property {Window} [window]- */+interface Options {+ shouldPassInSSR?: boolean+ window?: Window+}/*** Reactive Media Query.- *- * @param {string} query- * @param {Options} [options]*/-export function useMediaQuery(query, options = { shouldPassInSSR: false }) {- /** @type {import('@nuxtjs/composition-api').Ref<boolean>} */+export function useMediaQuery(+ query: string,+ options: Options = { shouldPassInSSR: false }+) {const matches = ref(false)const { window = defaultWindow } = optionsif (!window) {@@ -29,7 +27,7 @@ export function useMediaQuery(query, options = { shouldPassInSSR: false }) {const mediaQuery = window.matchMedia(query)matches.value = mediaQuery.matches- const handler = (/** @type MediaQueryListEvent */ event) => {+ const handler = (event: MediaQueryListEvent) => {matches.value = event.matches}// Before Safari 14, MediaQueryList is based on EventTarget,@@ -54,11 +52,13 @@ export function useMediaQuery(query, options = { shouldPassInSSR: false }) {/*** Check whether the current screen meets* or exceeds the provided breakpoint size.- * @param {'sm'|'md'|'lg'|'xl'|'2xl'} breakpointName- * @param {Options} [options]- * @returns {import('@nuxtjs/composition-api').Ref<boolean>}*/-export const isMinScreen = (breakpointName, options) => {+export const isMinScreen = (breakpointName: Breakpoint, options?: Options) => {+ if (breakpointName === 'xs') {+ // `xs` is the "minimum" so it is always true+ return ref(true)+ }+return useMediaQuery(`(min-width: ${SCREEN_SIZES.get(breakpointName)}px)`,options@@ -67,9 +67,7 @@ export const isMinScreen = (breakpointName, options) => {/*** Check if the user prefers reduced motion or not.- * @param {Options} options- * @returns {import('@nuxtjs/composition-api').Ref<boolean>}*/-export function useReducedMotion(options) {+export function useReducedMotion(options: Options) {return useMediaQuery('(prefers-reduced-motion: reduce)', options)}diff --git a/src/composables/use-window-scroll.js b/src/composables/use-window-scroll.jsindex 68c33c0df..318d8b179 100644--- a/src/composables/use-window-scroll.js+++ b/src/composables/use-window-scroll.js@@ -2,7 +2,7 @@import throttle from 'lodash.throttle'import { ref } from '@nuxtjs/composition-api'-import { defaultWindow } from '~/composables/window'+import { defaultWindow } from '~/constants/window'import { useEventListener } from '~/composables/use-event-listener'/**diff --git a/src/composables/window.js b/src/composables/window.jsdeleted file mode 100644index 2fa7b45ef..000000000--- a/src/composables/window.js+++ /dev/null@@ -1,2 +0,0 @@-export const isClient = typeof window !== 'undefined'-export const defaultWindow = isClient ? window : undefineddiff --git a/src/constants/screens.js b/src/constants/screens.jsindex 79ef5d7e9..4757b1c14 100644--- a/src/constants/screens.js+++ b/src/constants/screens.js@@ -1,43 +1,38 @@-/** @typedef {'2xl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs' | 'mob'} Breakpoints */+/**+ * This file cannot be converted to TypeScript because it's used by the Tailwind config+ */+/** @typedef {'2xl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs'} Breakpoint *//*** Mapping of a breakpoint name to the lower-bound of its screen-width range- * @type {Map<Exclude<Breakpoints, 'mob'>, number>}*/-const SCREEN_SIZES = new Map([- ['2xl', 1536],- ['xl', 1280],- ['lg', 1024],- ['md', 768],- ['sm', 640],- ['xs', 340],-])--const VIEWPORTS = Object.fromEntries(- [...Array.from(SCREEN_SIZES), ['mob', 400]].map(([key, val]) => {- return [- key,- {- name: `${key} (${val}px)`,- styles: { width: `${val}px`, height: '768px' },- },- ]- })+const SCREEN_SIZES = new Map(+ /** @type {const} */ ([+ ['2xl', 1536],+ ['xl', 1280],+ ['lg', 1024],+ ['md', 768],+ ['sm', 640],+ ]))-/**- * Get the breakpoint in which the screen with the given width lies.- * @param {number} screenWidth - the width of the screen- * @returns {Breakpoints} the breakpoint in which the screen lies- */-const getBreakpointName = (screenWidth) => {- for (const [breakpointName, lowerLimit] of SCREEN_SIZES) {- if (screenWidth >= lowerLimit) {- return breakpointName- }- }- return 'mob' // smallest breakpoint-}+const viewportEntries = [+ ...Array.from(SCREEN_SIZES),+ /** @type {const} */ (['xs', 340]),+].map(([key, val]) => {+ return /** @type {const} */ ([+ key,+ {+ name: `${key} (${val}px)`,+ styles: { width: `${val}px`, height: '768px' },+ },+ ])+})++const VIEWPORTS =+ /** @type {Record<Breakpoint, typeof viewportEntries[number][1]>} */ (+ Object.fromEntries(viewportEntries)+ )/*** This module is consumed by Nuxt and Tailwind config so it needs to use CJS modules@@ -45,5 +40,4 @@ const getBreakpointName = (screenWidth) => {module.exports = {SCREEN_SIZES,VIEWPORTS,- getBreakpointName,}diff --git a/src/constants/window.ts b/src/constants/window.tsnew file mode 100644index 000000000..2fcaf5673--- /dev/null+++ b/src/constants/window.ts@@ -0,0 +1,2 @@+export const isClient = process.client+export const defaultWindow = process.client ? window : undefineddiff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.potindex ed3dab38e..7c4e21ed7 100644--- a/src/locales/po-files/openverse.pot+++ b/src/locales/po-files/openverse.pot@@ -4,7 +4,7 @@ msgid ""msgstr """Project-Id-Version: Openverse \n""Report-Msgid-Bugs-To: https://github.com/wordpress/openverse/issues \n"-"POT-Creation-Date: 2022-04-22T12:44:37+00:00\n"+"POT-Creation-Date: 2022-04-27T11:03:45+00:00\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"@@ -806,7 +806,7 @@ msgctxt "browse-page.search-rating.feedback-thanks"msgid "Thank you for the feedback!"msgstr ""-#: src/components/VFilters/VSearchGridFilter.vue:8+#: src/components/VFilters/VSearchGridFilter.vue:9msgctxt "filter-list.filter-by"msgid "Filter by"msgstr ""@@ -815,12 +815,12 @@ msgctxt "filter-list.hide"msgid "Hide filters"msgstr ""-#: src/components/VFilters/VSearchGridFilter.vue:17+#: src/components/VFilters/VSearchGridFilter.vue:18msgctxt "filter-list.clear"msgid "Clear filters"msgstr ""-#: src/components/VFilters/VSearchGridFilter.vue:36+#: src/components/VFilters/VSearchGridFilter.vue:37msgctxt "filter-list.show"msgid "Show results"msgstr ""@@ -1817,7 +1817,7 @@ msgid "Filters"msgstr ""#. Do not translate words between ### ###.-#: src/components/VHeader/VFilterButton.vue:83+#: src/components/VHeader/VFilterButton.vue:95msgctxt "header.filter-button.with-count"msgid "###count### Filter"msgid_plural "###count### Filters"diff --git a/src/utils/pinia-state.ts b/src/utils/pinia-state.tsindex e14b62833..4ee3882a9 100644--- a/src/utils/pinia-state.ts+++ b/src/utils/pinia-state.ts@@ -1,4 +1,4 @@-import { isClient } from '~/composables/window'+import { isClient } from '~/constants/window'import type { StateTree } from 'pinia'diff --git a/test/playwright/e2e/filters.spec.ts b/test/playwright/e2e/filters.spec.tsindex b3c90619d..2dbea2215 100644--- a/test/playwright/e2e/filters.spec.ts+++ b/test/playwright/e2e/filters.spec.ts@@ -152,9 +152,9 @@ test('filters are updated when media type changes', async ({ page }) => {// Only CC0 checkbox is checked, and the filter button label is '1 Filter'await assertCheckboxStatus(page, 'cc0')- const filterButtonSelector =- '[aria-controls="filter-sidebar"], [aria-controls="filter-modal"]'- await expect(page.locator(filterButtonSelector)).toHaveText('1 Filter')+ await expect(+ page.locator('[aria-controls="filters"] span:visible')+ ).toHaveText('1 Filter')await expect(page).toHaveURL('/search/audio?q=cat&license=cc0')})diff --git a/test/playwright/utils/breakpoints.ts b/test/playwright/utils/breakpoints.tsindex 5722b71cc..f9fc8a958 100644--- a/test/playwright/utils/breakpoints.ts+++ b/test/playwright/utils/breakpoints.ts@@ -1,11 +1,6 @@import { test, expect } from '@playwright/test'-import {- Breakpoints as AllBreakpoints,- SCREEN_SIZES,-} from '~/constants/screens'--type Breakpoint = Exclude<AllBreakpoints, 'mob'>+import { Breakpoint, VIEWPORTS } from '~/constants/screens'type ScreenshotAble = {// eslint-disable-next-line @typescript-eslint/no-explicit-any@@ -102,12 +97,20 @@ const makeBreakpointDescribe =const capitalize = (s: string): Capitalize<typeof s> =>`${s[0].toUpperCase()}${s.slice(1)}`-const breakpointTests = Array.from(SCREEN_SIZES.entries()).reduce(- (tests, [breakpoint, screenWidth]) =>+const breakpointTests = Array.from(Object.entries(VIEWPORTS)).reduce(+ (+ tests,+ [+ breakpoint,+ {+ styles: { width },+ },+ ]+ ) =>Object.assign(tests, {[`describe${capitalize(breakpoint)}`]: makeBreakpointDescribe(- breakpoint,- screenWidth+ breakpoint as Breakpoint,+ parseFloat(width.replace('px', ''))),}),{} as Record<@@ -132,7 +135,9 @@ const describeEachBreakpoint =})}-const describeEvery = describeEachBreakpoint(Array.from(SCREEN_SIZES.keys()))+const describeEvery = describeEachBreakpoint(+ Object.keys(VIEWPORTS) as Breakpoint[]+)const describeEachDesktop = describeEachBreakpoint(desktopBreakpoints)const describeEachMobile = describeEachBreakpoint(mobileBreakpoints)diff --git a/test/playwright/utils/navigation.ts b/test/playwright/utils/navigation.tsindex 94b887d1a..1e1c65c2b 100644--- a/test/playwright/utils/navigation.ts+++ b/test/playwright/utils/navigation.ts@@ -1,8 +1,7 @@import { expect, Page } from '@playwright/test'export const openFilters = async (page: Page) => {- const filterButtonSelector =- '[aria-controls="filter-sidebar"], [aria-controls="filter-modal"]'+ const filterButtonSelector = '[aria-controls="filters"]'const isPressed = async () =>await page.getAttribute(filterButtonSelector, 'aria-pressed')if ((await isPressed()) !== 'true') {diff --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.pngindex 0d1ae01d3..89e1c06fa 100644Binary files a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-desktop-UA-xs-linux.png 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-xs-linux.png b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-xs-linux.pngindex 1afd13b92..9468d503e 100644Binary files a/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-xs-linux.png and b/test/playwright/visual-regression/audio-results.spec.ts-snapshots/audio-results-narrow-viewport-mobile-UA-xs-linux.png differdiff --git a/test/playwright/visual-regression/header.spec.ts-snapshots/resting-ltr-xs-linux.png b/test/playwright/visual-regression/header.spec.ts-snapshots/resting-ltr-xs-linux.pngindex 9c6a96ae6..4275ee0b7 100644Binary files a/test/playwright/visual-regression/header.spec.ts-snapshots/resting-ltr-xs-linux.png and b/test/playwright/visual-regression/header.spec.ts-snapshots/resting-ltr-xs-linux.png differdiff --git a/test/playwright/visual-regression/header.spec.ts-snapshots/resting-rtl-xs-linux.png b/test/playwright/visual-regression/header.spec.ts-snapshots/resting-rtl-xs-linux.pngindex 7f015117d..7c3c4596b 100644Binary files a/test/playwright/visual-regression/header.spec.ts-snapshots/resting-rtl-xs-linux.png and b/test/playwright/visual-regression/header.spec.ts-snapshots/resting-rtl-xs-linux.png differdiff --git a/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-ltr-xs-linux.png b/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-ltr-xs-linux.pngindex 4ff359c61..237e97afa 100644Binary files a/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-ltr-xs-linux.png and b/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-ltr-xs-linux.png differdiff --git a/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-rtl-xs-linux.png b/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-rtl-xs-linux.pngindex a2716a0b4..b69af1664 100644Binary files a/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-rtl-xs-linux.png and b/test/playwright/visual-regression/header.spec.ts-snapshots/searchbar-hovered-rtl-xs-linux.png differdiff --git a/test/storybook/utils/args.ts b/test/storybook/utils/args.tsnew file mode 100644index 000000000..2baa31cb0--- /dev/null+++ b/test/storybook/utils/args.ts@@ -0,0 +1,12 @@+import type { Page } from '@playwright/test'++export const makeGotoWithArgs =+ (storySlug: string) => (page: Page, args?: Record<string, unknown>) => {+ const argStrings = Object.entries(args ?? {})+ .map(([k, v]) => `${k}:${v}`)+ .join(';')+ const argsParam = args ? `&args=${argStrings}` : ''++ const url = `/iframe.html?id=${storySlug}${argsParam}`+ return page.goto(url)+ }diff --git a/test/storybook/visual-regression/v-filter-button.spec.ts b/test/storybook/visual-regression/v-filter-button.spec.tsnew file mode 100644index 000000000..6b67087f4--- /dev/null+++ b/test/storybook/visual-regression/v-filter-button.spec.ts@@ -0,0 +1,58 @@+import { test } from '@playwright/test'++import breakpoints from '~~/test/playwright/utils/breakpoints'+import { makeGotoWithArgs } from '~~/test/storybook/utils/args'++const gotoWithArgs = makeGotoWithArgs(+ 'components-vheader-vfilterbutton--default-story'+)++test.describe('VFilterButton', () => {+ breakpoints.describeMd(({ expectSnapshot }) => {+ test('no filters applied', async ({ page }) => {+ await gotoWithArgs(page, { isMinMd: true })+ await expectSnapshot('filter-button-at-rest', page)+ })++ test('no filters pressed', async ({ page }) => {+ await gotoWithArgs(page, { isMinMd: true, pressed: true })+ await expectSnapshot('filter-button-pressed', page)+ })++ test('filters applied', async ({ page }) => {+ await gotoWithArgs(page, { isMinMd: true, appliedFilters: 2 })+ await expectSnapshot('filter-button-2-filters', page)+ })++ test('filters applied and pressed', async ({ page }) => {+ await gotoWithArgs(page, {+ isMinMd: true,+ appliedFilters: 2,+ pressed: true,+ })+ await expectSnapshot('filter-button-2-filters-pressed', page)+ })+ })++ breakpoints.describeXs(({ expectSnapshot }) => {+ test('no filters applied and not scrolled', async ({ page }) => {+ await gotoWithArgs(page)+ await expectSnapshot('filter-button-no-filters-not-scrolled', page)+ })++ test('no filters but scrolled', async ({ page }) => {+ await gotoWithArgs(page, { scrolled: true })+ await expectSnapshot('filter-button-no-filters-scrolled', page)+ })++ test('2 filters not scrolled', async ({ page }) => {+ await gotoWithArgs(page, { appliedFilters: 2 })+ await expectSnapshot('filter-button-2-filters-not-scrolled', page)+ })++ test('2 filters and scrolled', async ({ page }) => {+ await gotoWithArgs(page, { appliedFilters: 2, scrolled: true })+ await expectSnapshot('filter-button-2-filters-scrolled', page)+ })+ })+})diff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-md-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-md-linux.pngnew file mode 100644index 000000000..889c79dfcBinary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-md-linux.png differdiff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-not-scrolled-xs-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-not-scrolled-xs-linux.pngnew file mode 100644index 000000000..f0831c3b8Binary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-not-scrolled-xs-linux.png differdiff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-pressed-md-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-pressed-md-linux.pngnew file mode 100644index 000000000..1ce25b063Binary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-pressed-md-linux.png differdiff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-scrolled-xs-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-scrolled-xs-linux.pngnew file mode 100644index 000000000..1eed6d837Binary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-2-filters-scrolled-xs-linux.png differdiff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-at-rest-md-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-at-rest-md-linux.pngnew file mode 100644index 000000000..464fa9316Binary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-at-rest-md-linux.png differdiff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-no-filters-not-scrolled-xs-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-no-filters-not-scrolled-xs-linux.pngnew file mode 100644index 000000000..5cf2ddb2aBinary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-no-filters-not-scrolled-xs-linux.png differdiff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-no-filters-scrolled-xs-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-no-filters-scrolled-xs-linux.pngnew file mode 100644index 000000000..5cf2ddb2aBinary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-no-filters-scrolled-xs-linux.png differdiff --git a/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-pressed-md-linux.png b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-pressed-md-linux.pngnew file mode 100644index 000000000..e27607b21Binary files /dev/null and b/test/storybook/visual-regression/v-filter-button.spec.ts-snapshots/filter-button-pressed-md-linux.png differdiff --git a/test/unit/specs/components/VHeader/v-filter-button.spec.js b/test/unit/specs/components/VHeader/v-filter-button.spec.jsdeleted file mode 100644index be3a77c3e..000000000--- a/test/unit/specs/components/VHeader/v-filter-button.spec.js+++ /dev/null@@ -1,143 +0,0 @@-import { render, screen } from '@testing-library/vue'-import { createLocalVue } from '@vue/test-utils'-import VueI18n from 'vue-i18n'-import { ref } from '@nuxtjs/composition-api'--import { createPinia, PiniaVuePlugin } from 'pinia'--import messages from '~/locales/en.json'--import { filterData, mediaFilterKeys } from '~/constants/filters'-import { IMAGE } from '~/constants/media'--import { useSearchStore } from '~/stores/search'--import VFilterButton from '~/components/VHeader/VFilterButton.vue'--function applyNFilters(filterCount, searchStore) {- const filterTypes = [...mediaFilterKeys[IMAGE]]- let filterIdx = 0- // Skip license type filters as they can disable license filters- let filterTypeIdx = 1- for (let i = 0; i < filterCount; i++) {- let filterType = filterTypes[filterTypeIdx]- searchStore.toggleFilter({- filterType,- codeIdx: filterIdx,- })- filterIdx += 1- if (filterData[filterType].length === filterIdx) {- filterTypeIdx += 1- filterIdx = 0- }- }-}--describe('VFilterButton', () => {- let options = {}- let localVue- let props = {}- let provided = {- isMinScreenMd: ref(true),- isHeaderScrolled: ref(false),- }- let pinia- let searchStore-- const i18n = new VueI18n({- locale: 'en',- localeProperties: { dir: 'ltr' },- fallbackLocale: 'en',- messages: { en: messages },- })- beforeEach(() => {- localVue = createLocalVue()- localVue.use(VueI18n)- localVue.use(PiniaVuePlugin)- pinia = createPinia()- searchStore = useSearchStore(pinia)- // the default ALL_MEDIA has fewer filters that can be applied,- // ensure that we can test for more than 10 filters- searchStore.setSearchType(IMAGE)-- options = {- localVue,- propsData: props,- mocks: { $nuxt: { context: { i18n } } },- provide: provided,- pinia,- }- })-- describe('Above the medium breakpoint', () => {- it('always shows the label and icon', () => {- provided.isMinScreenMd.value = true- const { container } = render(VFilterButton, options)-- const button = screen.getByText('Filters')- const icon = container.querySelector('svg')-- expect(button).toBeVisible()- expect(icon).toBeVisible()- })- it('shows the count and text when filters are applied', () => {- provided.isMinScreenMd.value = true- // +2 to guarantee it's plural- const filterCount = Math.floor(Math.random() * 9) + 2- applyNFilters(filterCount, searchStore)- const wrapper = render(VFilterButton, options)- const button = wrapper.getByText(`${filterCount} Filters`)-- expect(button).toBeVisible()- })- it('does not show the icon when filters are applied', () => {- provided.isMinScreenMd.value = true- searchStore.toggleFilter({ filterType: 'licenses', codeIdx: 0 })-- const { container } = render(VFilterButton, options)- const icon = container.querySelector('svg')-- expect(icon).not.toBeVisible()- })- })-- describe('below the medium breakpoint', () => {- it('only shows the filter icon by default', () => {- provided.isMinScreenMd.value = false- const { container } = render(VFilterButton, options)-- const icon = container.querySelector('svg')- const label = screen.queryByTestId('filterbutton-label')-- expect(icon).toBeVisible()- expect(label).not.toBeVisible()- })- it('only shows the count and label when filters are applied', () => {- provided.isMinScreenMd.value = false- // +2 to guarantee it's plural- const filterCount = Math.floor(Math.random() * 10) + 2- applyNFilters(filterCount, searchStore)- const { container } = render(VFilterButton, options)-- const icon = container.querySelector('svg')- const button = screen.getByText(`${filterCount} Filters`)-- expect(icon).not.toBeVisible()- expect(button).toBeVisible()- })- it('only shows the count when filters are applied and the user scrolls', () => {- provided.isMinScreenMd.value = false- provided.isHeaderScrolled.value = true- // +2 to guarantee it's plural- const filterCount = Math.floor(Math.random() * 10) + 2- applyNFilters(filterCount, searchStore)- const { container } = render(VFilterButton, options)-- const icon = container.querySelector('svg')- const button = screen.getByText(filterCount)-- expect(icon).not.toBeVisible()- expect(button).toBeVisible()- })- })-})diff --git a/tsconfig.json b/tsconfig.jsonindex d89731ad5..40552a3e6 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -41,6 +41,7 @@"src/components/VMetaSearch/*.vue","src/components/VLicenseElements.vue","src/components/VWarningSuppressor.vue",+ "src/components/VHeader/VFilterButton.vue","src/components/VLink.vue","src/components/VLoadMore.vue","src/components/VIcon/VIcon.vue",@@ -57,13 +58,9 @@"src/components/VAudioTrack/VPlayPause.vue","src/composables/types.js","src/composables/use-event-listener-outside.js",- "src/composables/use-active-audio.js",- "src/composables/use-get-locale-formatted-number.js",- "src/composables/use-browser-detection.js",- "src/composables/use-media-query.js",- "src/composables/window.js",- "src/constants/screens.js",- "src/utils/deep-freeze.js"++ // This section cannot be converted to TypeScript because it's used in non-TS contexts (like Tailwind configuration)+ "src/constants/screens.js"],"exclude": ["node_modules"],"vueCompilerOptions": {