Skip to content

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

Use more descriptive accessible headings for search result pages (#3941)

sarayourfrienda51ac8d5af46
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 715646bf5..40a8098c9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,4 +1,4 @@
-exclude: Pipfile\.lock|migrations|\.idea|node_modules|archive|retired
+exclude: Pipfile\.lock|migrations|\.idea|node_modules|archive|retired|\.snap
repos:
- repo: local # More local hooks are defined at the bottom.
diff --git a/frontend/jest.config.js b/frontend/jest.config.js
index c04870c65..dd2538818 100644
--- a/frontend/jest.config.js
+++ b/frontend/jest.config.js
@@ -2,6 +2,9 @@ module.exports = {
globals: {
"vue-jest": {
experimentalCSSCompile: false,
+ templateCompiler: {
+ prettify: false,
+ },
},
},
moduleFileExtensions: ["ts", "js", "vue", "json"],
diff --git a/frontend/package.json b/frontend/package.json
index 15205a2f3..435e9803a 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -25,7 +25,7 @@
"talkback": "node ./test/proxy.js",
"pretest": "pnpm install",
"test": "pnpm test:unit && pnpm test:playwright",
- "test:unit": "jest",
+ "test:unit": "pnpm run i18n:en && jest",
"test:unit:watch": "pnpm test:unit --collectCoverage=false --watch",
"test:playwright": "./bin/playwright.sh",
"test:playwright:local": "playwright test -c test/playwright",
diff --git a/frontend/src/components/VSearchResultsGrid/VSearchResults.vue b/frontend/src/components/VSearchResultsGrid/VSearchResults.vue
index 1205d2f16..71c564b88 100644
--- a/frontend/src/components/VSearchResultsGrid/VSearchResults.vue
+++ b/frontend/src/components/VSearchResultsGrid/VSearchResults.vue
@@ -9,7 +9,10 @@
<template #header>
<header v-if="searchTerm" class="my-0 md:mb-8 md:mt-4">
<VSearchResultsTitle
+ :search-term="searchTerm"
:size="results.type === 'all' ? 'large' : 'default'"
+ :search-type="results.type"
+ :result-counts="resultCounts"
>{{ searchTerm }}</VSearchResultsTitle
>
</header>
@@ -99,7 +102,9 @@ export default defineComponent({
const collectionLabel = computed(() => {
return i18n
- .t("browsePage.aria.results", { query: props.searchTerm })
+ .t(`browsePage.aria.results.${props.results.type}`, {
+ query: props.searchTerm,
+ })
.toString()
})
const contentLinkPath = (mediaType: SupportedMediaType) =>
diff --git a/frontend/src/components/VSearchResultsTitle.vue b/frontend/src/components/VSearchResultsTitle.vue
index 5901c6feb..7e684d24c 100644
--- a/frontend/src/components/VSearchResultsTitle.vue
+++ b/frontend/src/components/VSearchResultsTitle.vue
@@ -7,21 +7,117 @@
: 'heading-2 !leading-none',
]"
>
- <slot default />
+ <span aria-hidden="true">{{ searchTerm }}</span
+ ><span class="sr-only">{{ ariaHeading }}</span>
</h1>
</template>
<script lang="ts">
-import { defineComponent, PropType } from "vue"
+import { defineComponent, PropType, computed } from "vue"
+
+import type { SupportedMediaType, SupportedSearchType } from "~/constants/media"
+
+import { useGetLocaleFormattedNumber } from "~/composables/use-get-locale-formatted-number"
+import { getCountKey } from "~/composables/use-i18n-utilities"
+import { useI18n } from "~/composables/use-i18n"
export default defineComponent({
name: "VSearchResultsTitle",
props: {
+ searchTerm: {
+ required: true,
+ type: String,
+ },
size: {
required: false,
default: "default",
type: String as PropType<"default" | "large">,
},
+ resultCounts: {
+ required: true,
+ type: Array as PropType<[SupportedMediaType, number][]>,
+ },
+ searchType: {
+ required: true,
+ type: String as PropType<SupportedSearchType>,
+ },
+ },
+ setup(props) {
+ const getLocaleFormattedNumber = useGetLocaleFormattedNumber()
+ const i18n = useI18n()
+ const mediaLocaleCounts = computed(() =>
+ props.resultCounts.reduce(
+ (acc, [mediaType, count]) => {
+ return {
+ ...acc,
+ [mediaType]: {
+ count,
+ countKey: getCountKey(count),
+ localeCount: getLocaleFormattedNumber(count),
+ },
+ }
+ },
+ {} as Record<
+ SupportedMediaType,
+ { count: number; countKey: string; localeCount: string }
+ >
+ )
+ )
+
+ const _getAllMediaAriaHeading = () => {
+ const imageLocaleCounts = mediaLocaleCounts.value.image
+ const imageResults = i18n.tc(
+ `browsePage.aria.allResultsHeadingCount.image.${imageLocaleCounts.countKey}`,
+ imageLocaleCounts.count,
+ {
+ localeCount: imageLocaleCounts.localeCount,
+ }
+ )
+
+ const audioLocaleCounts = mediaLocaleCounts.value.audio
+ const audioResults = i18n.tc(
+ `browsePage.aria.allResultsHeadingCount.audio.${audioLocaleCounts.countKey}`,
+ audioLocaleCounts.count,
+ {
+ localeCount: audioLocaleCounts.localeCount,
+ }
+ )
+
+ return i18n
+ .t("browsePage.aria.results.all", {
+ query: props.searchTerm,
+ imageResults,
+ audioResults,
+ })
+ .toString()
+ }
+
+ const ariaHeading = computed((): string => {
+ switch (props.searchType) {
+ case "image": {
+ const { count, countKey, localeCount } = mediaLocaleCounts.value.image
+ return i18n.tc(`browsePage.aria.results.image.${countKey}`, count, {
+ localeCount,
+ query: props.searchTerm,
+ })
+ }
+ case "audio": {
+ const { count, countKey, localeCount } = mediaLocaleCounts.value.audio
+ return i18n.tc(`browsePage.aria.results.audio.${countKey}`, count, {
+ localeCount,
+ query: props.searchTerm,
+ })
+ }
+ default:
+ case "all": {
+ return _getAllMediaAriaHeading()
+ }
+ }
+ })
+
+ return {
+ ariaHeading,
+ }
},
})
</script>
diff --git a/frontend/src/composables/use-i18n-utilities.ts b/frontend/src/composables/use-i18n-utilities.ts
index 8a2025950..6ef4bc592 100644
--- a/frontend/src/composables/use-i18n-utilities.ts
+++ b/frontend/src/composables/use-i18n-utilities.ts
@@ -4,72 +4,81 @@ import type { SupportedMediaType, SupportedSearchType } from "~/constants/media"
import { ALL_MEDIA, AUDIO, IMAGE } from "~/constants/media"
import { Collection } from "~/types/search"
+type KeyCollection = {
+ zero: string
+ count: string
+ countMore: string
+}
+type KeyMapping = Record<SupportedMediaType, KeyCollection> & {
+ all?: KeyCollection
+}
/**
* Not using dynamically-generated keys to ensure that
* correct line is shown in the 'po' locale files
*/
const searchResultKeys = {
[ALL_MEDIA]: {
- noResult: "browsePage.allNoResults",
- result: "browsePage.allResultCount",
- more: "browsePage.allResultCountMore",
+ zero: "browsePage.allNoResults",
+ count: "browsePage.allResultCount",
+ countMore: "browsePage.allResultCountMore",
},
[IMAGE]: {
- noResult: "browsePage.contentLink.image.zero",
- result: "browsePage.contentLink.image.count",
- more: "browsePage.contentLink.image.countMore",
+ zero: "browsePage.contentLink.image.zero",
+ count: "browsePage.contentLink.image.count",
+ countMore: "browsePage.contentLink.image.countMore",
},
[AUDIO]: {
- noResult: "browsePage.contentLink.audio.zero",
- result: "browsePage.contentLink.audio.count",
- more: "browsePage.contentLink.audio.countMore",
+ zero: "browsePage.contentLink.audio.zero",
+ count: "browsePage.contentLink.audio.count",
+ countMore: "browsePage.contentLink.audio.countMore",
},
-}
+} satisfies KeyMapping
+
const collectionKeys = {
source: {
[IMAGE]: {
- noResult: "collection.resultCountLabel.source.image.zero",
- result: "collection.resultCountLabel.source.image.count",
- more: "collection.resultCountLabel.source.image.countMore",
+ zero: "collection.resultCountLabel.source.image.zero",
+ count: "collection.resultCountLabel.source.image.count",
+ countMore: "collection.resultCountLabel.source.image.countMore",
},
[AUDIO]: {
- noResult: "collection.resultCountLabel.source.audio.zero",
- result: "collection.resultCountLabel.source.audio.count",
- more: "collection.resultCountLabel.source.audio.countMore",
+ zero: "collection.resultCountLabel.source.audio.zero",
+ count: "collection.resultCountLabel.source.audio.count",
+ countMore: "collection.resultCountLabel.source.audio.countMore",
},
},
creator: {
[IMAGE]: {
- noResult: "collection.resultCountLabel.creator.image.zero",
- result: "collection.resultCountLabel.creator.image.count",
- more: "collection.resultCountLabel.creator.image.countMore",
+ zero: "collection.resultCountLabel.creator.image.zero",
+ count: "collection.resultCountLabel.creator.image.count",
+ countMore: "collection.resultCountLabel.creator.image.countMore",
},
[AUDIO]: {
- noResult: "collection.resultCountLabel.creator.audio.zero",
- result: "collection.resultCountLabel.creator.audio.count",
- more: "collection.resultCountLabel.creator.audio.countMore",
+ zero: "collection.resultCountLabel.creator.audio.zero",
+ count: "collection.resultCountLabel.creator.audio.count",
+ countMore: "collection.resultCountLabel.creator.audio.countMore",
},
},
tag: {
[IMAGE]: {
- noResult: "collection.resultCountLabel.tag.image.zero",
- result: "collection.resultCountLabel.tag.image.count",
- more: "collection.resultCountLabel.tag.image.countMore",
+ zero: "collection.resultCountLabel.tag.image.zero",
+ count: "collection.resultCountLabel.tag.image.count",
+ countMore: "collection.resultCountLabel.tag.image.countMore",
},
[AUDIO]: {
- noResult: "collection.resultCountLabel.tag.audio.zero",
- result: "collection.resultCountLabel.tag.audio.count",
- more: "collection.resultCountLabel.tag.audio.countMore",
+ zero: "collection.resultCountLabel.tag.audio.zero",
+ count: "collection.resultCountLabel.tag.audio.count",
+ countMore: "collection.resultCountLabel.tag.audio.countMore",
},
},
-}
+} satisfies Record<Collection, KeyMapping>
-function getCountKey(resultsCount: number) {
+export function getCountKey(resultsCount: number): keyof KeyCollection {
return resultsCount === 0
- ? "noResult"
+ ? "zero"
: resultsCount >= 10000
- ? "more"
- : "result"
+ ? "countMore"
+ : "count"
}
/**
diff --git a/frontend/src/locales/scripts/en.json5 b/frontend/src/locales/scripts/en.json5
index 815ffeefe..3b0e1b9f0 100644
--- a/frontend/src/locales/scripts/en.json5
+++ b/frontend/src/locales/scripts/en.json5
@@ -685,7 +685,41 @@
creator: "search by creator",
imageTitle: "Image: {title}",
audioTitle: "Audio: {title}",
- results: "Search results for {query}.",
+ results: {
+ /**
+ * "imageResults" and "audioResults" are interpolated from the strings under
+ * browsePage.aria.allResultsHeadingCount.*
+ */
+ all: 'All results for "{query}", {imageResults} and {audioResults}.',
+ image: {
+ zero: 'No image results for "{query}"',
+ count: '{localeCount} image result for "{query}".|{localeCount} image results for "{query}".',
+ countMore: 'Over {localeCount} image results for "{query}".',
+ },
+ audio: {
+ zero: 'No audio tracks for "{query}"',
+ count: '{localeCount} audio track for "{query}".|{localeCount} audio tracks for "{query}".',
+ countMore: 'Over {localeCount} audio tracks for "{query}".',
+ },
+ },
+ allResultsHeadingCount: {
+ image: {
+ /* Interpolated into browsePage.aria.results.all */
+ zero: "no images",
+ /* Interpolated into browsePage.aria.results.all */
+ count: "{localeCount} image|{localeCount} images",
+ /* Interpolated into browsePage.aria.results.all */
+ countMore: "over {localeCount} images",
+ },
+ audio: {
+ /* Interpolated into browsePage.aria.results.all */
+ zero: "no audio tracks",
+ /* Interpolated into browsePage.aria.results.all */
+ count: "{localeCount} audio track|{localeCount} audio tracks",
+ /* Interpolated into browsePage.aria.results.all */
+ countMore: "over {localeCount} audio tracks",
+ },
+ },
},
},
mediaDetails: {
diff --git a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-sm-linux.png b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-sm-linux.png
index cd08a22ae..55f457335 100644
Binary files a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-sm-linux.png and b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-sm-linux.png differ
diff --git a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-xs-linux.png b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-xs-linux.png
index 7e49bf261..84c812591 100644
Binary files a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-xs-linux.png and b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-checked-ltr-xs-linux.png differ
diff --git a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-sm-linux.png b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-sm-linux.png
index e810b7cc5..71b83b8a1 100644
Binary files a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-sm-linux.png and b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-sm-linux.png differ
diff --git a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-xs-linux.png b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-xs-linux.png
index 05bc6f961..703b95b8b 100644
Binary files a/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-xs-linux.png and b/frontend/test/playwright/visual-regression/components/filters.spec.ts-snapshots/filters-modal-ltr-xs-linux.png differ
diff --git a/frontend/test/unit/specs/components/__snapshots__/v-search-results-title.spec.js.snap b/frontend/test/unit/specs/components/__snapshots__/v-search-results-title.spec.js.snap
new file mode 100644
index 000000000..63c3ca5e1
--- /dev/null
+++ b/frontend/test/unit/specs/components/__snapshots__/v-search-results-title.spec.js.snap
@@ -0,0 +1,685 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",0],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", no images and no audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",0],["audio",10]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", no images and 10 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",0],["audio",4300]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", no images and 4,300 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",0],["audio",10000]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", no images and over 10,000 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",0],["audio",10001]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", no images and over 10,001 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 10 images and no audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10],["audio",10]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 10 images and 10 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10],["audio",4300]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 10 images and 4,300 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10],["audio",10000]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 10 images and over 10,000 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10],["audio",10001]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 10 images and over 10,001 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",4300],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 4,300 images and no audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",4300],["audio",10]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 4,300 images and 10 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",4300],["audio",4300]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 4,300 images and 4,300 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",4300],["audio",10000]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 4,300 images and over 10,000 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",4300],["audio",10001]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 4,300 images and over 10,001 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10000],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,000 images and no audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10000],["audio",10]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,000 images and 10 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10000],["audio",4300]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,000 images and 4,300 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10000],["audio",10000]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,000 images and over 10,000 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10000],["audio",10001]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,000 images and over 10,001 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10001],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,001 images and no audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10001],["audio",10]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,001 images and 10 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10001],["audio",4300]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,001 images and 4,300 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10001],["audio",10000]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,001 images and over 10,000 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"all","resultCounts":[["image",10001],["audio",10001]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", over 10,001 images and over 10,001 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"audio","resultCounts":[["audio",0],["image",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ No audio tracks for "zack"
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"audio","resultCounts":[["audio",10],["image",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ 10 audio tracks for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"audio","resultCounts":[["audio",4300],["image",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ 4,300 audio tracks for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"audio","resultCounts":[["audio",10000],["image",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ Over 10,000 audio tracks for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"audio","resultCounts":[["audio",10001],["image",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ Over 10,001 audio tracks for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"image","resultCounts":[["image",0],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ No image results for "zack"
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"image","resultCounts":[["image",10],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ 10 image results for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"image","resultCounts":[["image",4300],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ 4,300 image results for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"image","resultCounts":[["image",10000],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ Over 10,000 image results for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle accessible heading {"searchType":"image","resultCounts":[["image",10001],["audio",0]]} 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ Over 10,001 image results for "zack".
+ </span>
+ </h1>
+</div>
+`;
+
+exports[`VSearchResultsTitle should render an h1 tag containing the correct text 1`] = `
+<div>
+ <h1
+ class="sr-only break-words md:not-sr-only heading-2 lg:heading-1 !leading-none lg:!leading-none"
+ >
+ <span
+ aria-hidden="true"
+ >
+ zack
+ </span>
+ <span
+ class="sr-only"
+ >
+ All results for "zack", 10 images and 10 audio tracks.
+ </span>
+ </h1>
+</div>
+`;
diff --git a/frontend/test/unit/specs/components/v-search-results-title.spec.js b/frontend/test/unit/specs/components/v-search-results-title.spec.js
index cb0a3dcad..0e1e94471 100644
--- a/frontend/test/unit/specs/components/v-search-results-title.spec.js
+++ b/frontend/test/unit/specs/components/v-search-results-title.spec.js
@@ -2,19 +2,79 @@ import { render } from "~~/test/unit/test-utils/render"
import VSearchResultsTitle from "~/components/VSearchResultsTitle.vue"
+const DEFAULT_PROPS = {
+ size: "large",
+ searchTerm: "zack",
+ searchType: "all",
+ resultCounts: [
+ ["image", 10],
+ ["audio", 10],
+ ],
+}
+
+/**
+ * Build test scenarios out of all possible
+ * result count combinations.
+ */
+function getScenarios() {
+ const counts = [0, 10, 4300, 10000, 10001]
+ let scenarios = []
+ counts.forEach((count) => {
+ counts.forEach((innerCount) => {
+ scenarios.push({
+ searchType: "all",
+ resultCounts: [
+ ["image", count],
+ ["audio", innerCount],
+ ],
+ })
+ })
+ scenarios.push({
+ searchType: "image",
+ resultCounts: [
+ ["image", count],
+ ["audio", 0],
+ ],
+ })
+ scenarios.push({
+ searchType: "audio",
+ resultCounts: [
+ ["audio", count],
+ ["image", 0],
+ ],
+ })
+ })
+ return scenarios.map((scenario) => [JSON.stringify(scenario), scenario])
+}
+
describe("VSearchResultsTitle", () => {
- let options = {
+ const getOptions = ({ props, ...options } = {}) => ({
+ ...options,
props: {
- size: "large",
- },
- scopedSlots: {
- default: () => "zack",
+ ...DEFAULT_PROPS,
+ ...props,
},
- }
+ })
it("should render an h1 tag containing the correct text", async () => {
- const { findByText } = render(VSearchResultsTitle, options)
- const button = await findByText("zack")
- expect(button.tagName).toBe("H1")
+ const { container } = render(VSearchResultsTitle, getOptions())
+ expect(container).toMatchSnapshot()
+ })
+
+ describe("accessible heading", () => {
+ it.each(getScenarios())("%s", (_, { searchType, resultCounts }) => {
+ const { container } = render(
+ VSearchResultsTitle,
+ getOptions({
+ props: {
+ searchType,
+ resultCounts,
+ },
+ })
+ )
+
+ // Cannot use inline snapshot in `each` test
+ expect(container).toMatchSnapshot()
+ })
})
})
diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json
index 92651e148..9530cbbc5 100644
--- a/packages/eslint-plugin/package.json
+++ b/packages/eslint-plugin/package.json
@@ -15,7 +15,7 @@
"@typescript-eslint/parser": "^6.5.0",
"@typescript-eslint/utils": "^6.5.0",
"eslint": "^8.48.0",
- "eslint-config-prettier": "^8.6.0",
+ "eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.28.1",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d56a55f21..dd66141af 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -213,7 +213,7 @@ importers:
version: 1.0.2
'@types/jest':
specifier: ^29.5.4
- version: 29.5.12
+ version: 29.5.4
'@types/node':
specifier: 18.19.28
version: 18.19.28
@@ -326,8 +326,8 @@ importers:
specifier: ^8.48.0
version: 8.48.0
eslint-config-prettier:
- specifier: ^8.6.0
- version: 8.6.0([email protected])
+ specifier: ^9.1.0
+ version: 9.1.0([email protected])
eslint-import-resolver-typescript:
specifier: ^3.6.0
version: 3.6.0(@typescript-eslint/[email protected])([email protected])([email protected])
@@ -7469,8 +7469,8 @@ packages:
dependencies:
'@types/istanbul-lib-report': 3.0.0
- resolution: {integrity: sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==}
+ resolution: {integrity: sha512-PhglGmhWeD46FYOVLt3X7TiWjzwuVGW9wG/4qocPevXMjCmrIc5b6db9WjeGE4QYVpUAWMDv3v0IiBwObY289A==}
dependencies:
expect: 29.6.4
pretty-format: 29.6.3
@@ -7639,7 +7639,7 @@ packages:
resolution: {integrity: sha512-vehbtyHUShPxIa9SioxDwCvgxukDMH//icJG90sXQBUm5lJOHLT5kNeU9tnivhnA/TkOFMzGIXN2cTc4hY8/kg==}
dependencies:
- '@types/jest': 29.5.12
+ '@types/jest': 29.5.4
dev: true
@@ -11767,8 +11767,8 @@ packages:
semver: 7.5.4
dev: false
- resolution: {integrity: sha512-bAF0eLpLVqP5oEVUFKpMA+NnRFICwn9X8B5jrR9FcqnYBuPbqWEjTEspPWMj5ye6czoSLDweCzSo3Ko7gGrZaA==}
+ resolution: {integrity: sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==}
hasBin: true
peerDependencies:
eslint: '>=7.0.0'
diff --git a/prettier.config.js b/prettier.config.js
index 33f7b4fda..b95548cd5 100644
--- a/prettier.config.js
+++ b/prettier.config.js
@@ -14,7 +14,8 @@ module.exports = {
{
files: ["frontend/**/*"],
options: {
- plugins: ["prettier-plugin-tailwindcss"],
+ // Do not include tailwind plugin in test environment, as it breaks jest
+ plugins: global.test ? [] : ["prettier-plugin-tailwindcss"],
tailwindConfig: "frontend/tailwind.config.ts",
vueIndentScriptAndStyle: false,
},