Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Set up global audio player (#595)
Dhruv Bhanushalid1d29e310157
diff --git a/src/assets/icons/close-small.svg b/src/assets/icons/close-small.svgnew file mode 100644index 000000000..91847f29d--- /dev/null+++ b/src/assets/icons/close-small.svg@@ -0,0 +1,5 @@+<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">+ <g id="icon" fill="currentColor">+ <path fill-rule="evenodd" clip-rule="evenodd" d="M12 13.0607L15.7123 16.773L16.773 15.7123L13.0607 12L16.773 8.28772L15.7123 7.22706L12 10.9394L8.2877 7.22705L7.22704 8.28771L10.9394 12L7.22704 15.7123L8.2877 16.773L12 13.0607Z"/>+ </g>+</svg>diff --git a/src/components/VAudioTrack/VAudioController.vue b/src/components/VAudioTrack/VAudioController.vuedeleted file mode 100644index 5cf816f85..000000000--- a/src/components/VAudioTrack/VAudioController.vue+++ /dev/null@@ -1,211 +0,0 @@-<template>- <div class="audio-controller">- <VWaveform- v-bind="waveformProps"- :message="message ? $t(`audio-track.messages.${message}`) : null"- :current-time="currentTime"- :duration="duration"- :peaks="audio.peaks"- @seeked="handleSeeked"- />-- <!-- eslint-disable vuejs-accessibility/media-has-caption -->- <audio- v-show="false"- v-bind="$attrs"- :id="audio.id"- ref="audioEl"- class="audio-controller"- controls- :src="audio.url"- crossorigin="anonymous"- @loadedmetadata="handleReady"- @error="handleError"- />- <!-- eslint-enable vuejs-accessibility/media-has-caption -->- </div>-</template>--<script>-import {- computed,- defineComponent,- ref,- useStore,- watch,-} from '@nuxtjs/composition-api'--import VWaveform from '~/components/VAudioTrack/VWaveform.vue'--import { ACTIVE } from '~/constants/store-modules.js'-import {- PAUSE_ACTIVE_MEDIA_ITEM,- SET_ACTIVE_MEDIA_ITEM,-} from '~/constants/mutation-types'--/**- * Controls the interaction between the parent Vue component, the underlying- * HTMLAudioElement and the Active Media Store. Also displays the waveform that- * is deeply linked to timekeeping for the HTMLAudioElement.- */-export default defineComponent({- name: 'VAudioController',- components: { VWaveform },- inheritAttrs: false,- model: {- prop: 'status',- event: 'change',- },- props: {- /**- * the information about the track, typically from a track's detail endpoint- */- audio: {- type: Object,- required: true,- },- /**- * the playing/paused status of the audio- */- status: {- type: String,- required: true,- validator: (val) => ['playing', 'paused', 'played'].includes(val),- },- /**- * the Vue props to pass to the waveform; This can take any form acceptable- * to Vue bindings.- */- waveformProps: {},- },- setup(props, { emit }) {- const store = useStore()-- const audioEl = ref(null) // template ref-- /* Status */-- const isActiveTrack = computed(- () =>- store.state.active.type === 'audio' &&- store.state.active.id === props.audio.id- )- // Sync status from parent to player and store- watch(- () => props.status,- (status, prevStatus) => {- if (!audioEl.value) return-- if (prevStatus === 'played' && status === 'playing') {- // If going from played to playing, then reset the time to the beginning.- // Let the regular logic handle actually triggering the playing of the audio- audioEl.value.currentTime = 0- }-- switch (status) {- case 'playing':- audioEl.value.play()- store.commit(`${ACTIVE}/${SET_ACTIVE_MEDIA_ITEM}`, {- type: 'audio',- id: props.audio.id,- })- window.requestAnimationFrame(updateTimeLoop)- break- case 'paused':- case 'played': // Note that played media shows as paused in the store- audioEl.value.pause()- if (isActiveTrack.value) {- store.commit(`${ACTIVE}/${PAUSE_ACTIVE_MEDIA_ITEM}`)- }- break- }- }- )- // Sync status from store to parent- watch(- () => [store.state.active.type, store.state.active.id],- () => {- const status = isActiveTrack.value ? 'playing' : 'paused'- emit('change', status)- }- )-- /* Error handling */-- const message = ref('loading')- const handleError = (event) => {- const error = event.target.error- let errorMsg- switch (error.code) {- case error.MEDIA_ERR_ABORTED:- errorMsg = 'err_aborted'- break- case error.MEDIA_ERR_NETWORK:- errorMsg = 'err_network'- break- case error.MEDIA_ERR_DECODE:- errorMsg = 'err_decode'- break- case error.MEDIA_ERR_SRC_NOT_SUPPORTED:- errorMsg = 'err_unsupported'- break- }- message.value = errorMsg- }-- /* Timekeeping */-- const currentTime = ref(0)- const duration = ref(0)- const updateTime = () => {- if (!audioEl.value) return-- currentTime.value = audioEl.value.currentTime- duration.value = audioEl.value.duration-- if (currentTime.value >= duration.value) {- emit('finished')- }- }- const updateTimeLoop = () => {- updateTime()- if (props.status === 'playing') {- // Audio is playing, keep looping- window.requestAnimationFrame(updateTimeLoop)- }- }-- /* Metadata readiness */-- const handleReady = () => {- message.value = null- updateTime()- emit('ready')- }-- /* Seeking */-- const handleSeeked = (frac) => {- if (audioEl.value && duration.value) {- audioEl.value.currentTime = duration.value * frac- updateTime()- emit('seeked')- }- }-- return {- audioEl,-- message,- handleError,-- currentTime,- duration,-- handleReady,-- handleSeeked,- }- },-})-</script>diff --git a/src/components/VAudioTrack/VAudioTrack.vue b/src/components/VAudioTrack/VAudioTrack.vueindex 37afa375a..eb3fbecaa 100644--- a/src/components/VAudioTrack/VAudioTrack.vue+++ b/src/components/VAudioTrack/VAudioTrack.vue@@ -5,22 +5,22 @@role="region"><Component :is="layoutComponent" :audio="audio" :size="size">- <template #controller="controllerProps">- <VAudioController- v-model="status"- v-bind="controllerProps"- :audio="audio"- @ready="handleReady"- @finished="handleFinished"+ <template #controller="waveformProps">+ <VWaveform+ v-bind="waveformProps"+ :peaks="audio.peaks"+ :current-time="currentTime"+ :duration="duration"+ :message="message ? $t(`audio-track.messages.${message}`) : null"@seeked="handleSeeked"/></template><template #play-pause="playPauseProps"><VPlayPause- v-model="status"+ :status="status"v-bind="playPauseProps"- :disabled="!isReady"+ @toggle="handleToggle"/></template></Component>@@ -28,16 +28,29 @@</template><script>-import { computed, defineComponent, ref } from '@nuxtjs/composition-api'+import {+ computed,+ defineComponent,+ ref,+ useStore,+ onMounted,+ watch,+} from '@nuxtjs/composition-api'import VPlayPause from '~/components/VAudioTrack/VPlayPause.vue'-import VAudioController from '~/components/VAudioTrack/VAudioController.vue'+import VWaveform from '~/components/VAudioTrack/VWaveform.vue'import VFullLayout from '~/components/VAudioTrack/layouts/VFullLayout.vue'import VRowLayout from '~/components/VAudioTrack/layouts/VRowLayout.vue'import VBoxLayout from '~/components/VAudioTrack/layouts/VBoxLayout.vue'import VGlobalLayout from '~/components/VAudioTrack/layouts/VGlobalLayout.vue'+import { ACTIVE } from '~/constants/store-modules'+import {+ PAUSE_ACTIVE_MEDIA_ITEM,+ SET_ACTIVE_MEDIA_ITEM,+} from '~/constants/mutation-types'+/*** Displays the waveform and basic information about the track, along with* controls to play, pause or seek to a point on the track.@@ -45,8 +58,8 @@ import VGlobalLayout from '~/components/VAudioTrack/layouts/VGlobalLayout.vue'export default defineComponent({name: 'VAudioTrack',components: {- VAudioController,VPlayPause,+ VWaveform,// LayoutsVFullLayout,@@ -82,24 +95,157 @@ export default defineComponent({},},setup(props) {- /* Status */+ const store = useStore()++ /* Local status */const status = ref('paused')+ /**+ * Set the local status to 'playing' and start measuring the current time.+ */+ const localPlay = () => {+ status.value = 'playing'+ updateTimeLoop()+ }+ /**+ * Set the local status to 'paused'.+ */+ const localPause = () => {+ status.value = 'paused'+ }+ onMounted(() => {+ if (isActiveTrack.value && store.state.active.status === 'playing') {+ localPlay()+ } else {+ localPause()+ }+ })++ /* Timekeeping */++ const currentTime = ref(0) // seconds+ const duration = computed(() => (props.audio.duration ?? 0) / 1e3) // seconds++ const updateTime = () => {+ if (window?.audioEl) {+ currentTime.value = window.audioEl.currentTime+ if (currentTime.value >= duration.value) {+ store.commit(`${ACTIVE}/${PAUSE_ACTIVE_MEDIA_ITEM}`)+ status.value = 'played'+ }+ }+ }+ const updateTimeLoop = () => {+ updateTime()+ if (status.value === 'playing') {+ // Audio is playing, keep looping+ window.requestAnimationFrame(updateTimeLoop)+ }+ }++ /* Interface with active media store */++ const isActiveTrack = computed(+ () =>+ store.state.active.type === 'audio' &&+ store.state.active.id === props.audio.id+ )+ const message = computed(() => store.state.active.message)- const handleSeeked = () => {- if (status.value === 'played') {- status.value = 'paused'+ /**+ * Plays the audio using the `HTMLAudioElement`.+ */+ const elPlay = () => {+ if (window?.audioEl) {+ if (window.audioEl.src !== props.audio.url) {+ window.audioEl.src = props.audio.url // resets position to zero+ }+ window.audioEl.play()}}- const handleFinished = () => {- status.value = 'played'+ /**+ * Pauses the audio using the `HTMLAudioElement` and updates local state.+ */+ const elPause = () => {+ if (window?.audioEl) {+ window.audioEl.pause()+ }+ }+ watch(+ () => [store.state.active.id, store.state.active.status],+ ([activeId, activeStatus], [prevActiveId, prevActiveStatus]) => {+ if (activeStatus === 'ejected') {+ elPause()+ localPause()+ } else if (activeStatus !== prevActiveStatus && isActiveTrack.value) {+ // Track status changed+ switch (activeStatus) {+ case 'playing':+ elPlay()+ localPlay()+ break+ case 'paused':+ elPause()+ localPause()+ break+ }+ } else if (activeId !== prevActiveId) {+ // Track ID changed+ if (isActiveTrack.value) {+ elPlay()+ localPlay()+ } else {+ localPause()+ }+ } else {+ // Nothing changed, no action required+ }+ }+ )++ /* Interface with VPlayPause */++ /**+ * Changes the store state to 'playing' with the information about the+ * track. This invokes the active media state watcher which, in turn, calls+ * `elPlay` to actually play the audio.+ */+ const storePlay = () => {+ store.commit(`${ACTIVE}/${SET_ACTIVE_MEDIA_ITEM}`, {+ type: 'audio',+ id: props.audio.id,+ })+ }+ /**+ * Changes the store state to 'paused'. If this is the active track, this+ * invokes the active media state watcher which, in turn, calls `elPause` to+ * actually pause the audio.+ */+ const storePause = () => {+ store.commit(`${ACTIVE}/${PAUSE_ACTIVE_MEDIA_ITEM}`)+ }+ const handleToggle = (state) => {+ switch (state) {+ case 'playing':+ storePlay()+ break+ case 'paused':+ if (isActiveTrack.value) {+ storePause()+ }+ break+ }}- /* Metadata readiness */+ /* Interface with VWaveform */- const isReady = ref(false)- const handleReady = () => {- isReady.value = true+ const elSetTime = (frac) => {+ if (window?.audioEl && isActiveTrack.value) {+ window.audioEl.currentTime = frac * (props.audio.duration / 1e3)+ }+ }+ const handleSeeked = (frac) => {+ elSetTime(frac)}/* Layout */@@ -114,11 +260,12 @@ export default defineComponent({return {status,+ message,+ handleToggle,handleSeeked,- handleFinished,- isReady,- handleReady,+ currentTime,+ duration,layoutComponent,}diff --git a/src/components/VAudioTrack/layouts/VBoxLayout.vue b/src/components/VAudioTrack/layouts/VBoxLayout.vueindex ef82424e5..ea3185d0a 100644--- a/src/components/VAudioTrack/layouts/VBoxLayout.vue+++ b/src/components/VAudioTrack/layouts/VBoxLayout.vue@@ -20,7 +20,7 @@<div v-if="!isSmall" class="player flex flex-row"><slot name="play-pause" size="small" />- <slot name="controller" :waveform-props="{ features: [] }" />+ <slot name="controller" :features="[]" /></div></div></div>@@ -60,7 +60,7 @@ export default defineComponent({</script><style>-.box-track .audio-controller {+.box-track .waveform {@apply flex-grow;--waveform-background-color: theme('colors.yellow');}diff --git a/src/components/VAudioTrack/layouts/VGlobalLayout.vue b/src/components/VAudioTrack/layouts/VGlobalLayout.vueindex 3e4b2be40..2bae4ba4c 100644--- a/src/components/VAudioTrack/layouts/VGlobalLayout.vue+++ b/src/components/VAudioTrack/layouts/VGlobalLayout.vue@@ -12,7 +12,7 @@<p class="text-sr font-semibold">{{ audio.title }}</p></div>- <slot name="controller" :waveform-props="{ 'usable-frac': 0.5 }" />+ <slot name="controller" :usable-frac="0.5" /></div></div></template>@@ -36,10 +36,6 @@ export default defineComponent({@apply h-14 w-14;}-.global-track .audio-controller {- @apply absolute inset-0;-}-.global-track .waveform {@apply h-full;}diff --git a/src/components/VAudioTrack/layouts/VRowLayout.vue b/src/components/VAudioTrack/layouts/VRowLayout.vueindex d539c657a..4b9062ea2 100644--- a/src/components/VAudioTrack/layouts/VRowLayout.vue+++ b/src/components/VAudioTrack/layouts/VRowLayout.vue@@ -1,5 +1,8 @@<template>- <article class="row-track flex flex-row" :class="`size-${size}`">+ <article+ class="row-track flex flex-row"+ :class="[`size-${size}`, { 'items-start': isSmall }]"+ ><divclass="relative flex-shrink-0 rounded-sm overflow-hidden":class="isLarge ? 'w-30 me-6' : 'w-20 me-4'"@@ -71,7 +74,7 @@<slot name="play-pause" :size="isLarge ? 'medium' : 'large'" /><slotname="controller"- :waveform-props="{ features: ['timestamps', 'duration', 'seek'] }"+ :features="['timestamps', 'duration', 'seek']"/></div></div>@@ -127,7 +130,7 @@ export default defineComponent({@apply rounded-ts-sm rounded-bs-sm flex-shrink-0;}-.row-track .audio-controller {+.row-track .waveform {@apply flex-grow;--waveform-background-color: theme('colors.white');}diff --git a/src/components/VGlobalAudioSection/VGlobalAudioSection.vue b/src/components/VGlobalAudioSection/VGlobalAudioSection.vuenew file mode 100644index 000000000..759b21c28--- /dev/null+++ b/src/components/VGlobalAudioSection/VGlobalAudioSection.vue@@ -0,0 +1,125 @@+<template>+ <div class="global-audio sticky sm:hidden bottom-0">+ <VAudioTrack v-if="audio" layout="global" :audio="audio" />++ <!-- eslint-disable vuejs-accessibility/media-has-caption -->+ <audio+ v-show="false"+ ref="audioEl"+ class="audio-controller"+ controls+ crossorigin="anonymous"+ @error="handleError"+ />+ <!-- eslint-enable vuejs-accessibility/media-has-caption -->++ <VIconButton+ v-if="audio"+ class="absolute top-0 end-0 border-none z-10"+ :icon-props="{ iconPath: icons.closeIcon }"+ @click="handleClose"+ />+ </div>+</template>++<script>+import {+ useStore,+ useRoute,+ ref,+ watch,+ onMounted,+ computed,+ onBeforeUnmount,+} from '@nuxtjs/composition-api'++import { ACTIVE } from '~/constants/store-modules'+import {+ SET_MESSAGE,+ EJECT_ACTIVE_MEDIA_ITEM,+} from '~/constants/mutation-types'++import closeIcon from '~/assets/icons/close-small.svg'++export default {+ name: 'VGlobalAudioSection',+ setup() {+ const store = useStore()+ const route = useRoute()++ /* Audio element */++ const audioEl = ref(null)+ onMounted(() => {+ window.audioEl = audioEl.value+ })+ onBeforeUnmount(() => {+ delete window.audioEl+ })++ /* Active audio track */++ const audio = computed(() => {+ const trackId = store.state.active.id+ if (trackId) {+ return store.state.media.results.audio.items[trackId]+ }+ return null+ })++ /* Message */++ const handleError = (event) => {+ const error = event.target.error+ let errorMsg+ switch (error.code) {+ case error.MEDIA_ERR_ABORTED:+ errorMsg = 'err_aborted'+ break+ case error.MEDIA_ERR_NETWORK:+ errorMsg = 'err_network'+ break+ case error.MEDIA_ERR_DECODE:+ errorMsg = 'err_decode'+ break+ case error.MEDIA_ERR_SRC_NOT_SUPPORTED:+ errorMsg = 'err_unsupported'+ break+ }+ store.commit(`${ACTIVE}/${SET_MESSAGE}`, {+ message: errorMsg,+ })+ }++ const handleClose = () => {+ store.commit(`${ACTIVE}/${EJECT_ACTIVE_MEDIA_ITEM}`)+ }++ /* Router observation */++ const routeName = computed(() => route.value.name)+ watch(routeName, (routeNameVal, oldRouteNameVal) => {+ if (+ oldRouteNameVal.includes('audio') &&+ !routeNameVal.includes('audio')+ ) {+ audioEl.value.pause()+ store.commit(`${ACTIVE}/${EJECT_ACTIVE_MEDIA_ITEM}`)+ }+ })++ return {+ icons: {+ closeIcon,+ },++ audioEl,++ audio,++ handleError,+ handleClose,+ }+ },+}+</script>diff --git a/src/constants/mutation-types.js b/src/constants/mutation-types.jsindex 332e0637f..cefb4b102 100644--- a/src/constants/mutation-types.js+++ b/src/constants/mutation-types.js@@ -24,6 +24,7 @@ export const CLEAR_OTHER_MEDIA_TYPE_FILTERS = 'CLEAR_OTHER_MEDIA_TYPE_FILTERS'export const SET_ACTIVE_MEDIA_ITEM = 'SET_ACTIVE_MEDIA_ITEM'export const PAUSE_ACTIVE_MEDIA_ITEM = 'PAUSE_ACTIVE_MEDIA_ITEM'export const EJECT_ACTIVE_MEDIA_ITEM = 'EJECT_ACTIVE_MEDIA_ITEM'+export const SET_MESSAGE = 'SET_MESSAGE'export const RESET_MEDIA = 'RESET_MEDIA'export const REPLACE_FILTERS = 'REPLACE_FILTERS'export const SET_QUERY = 'SET_QUERY'diff --git a/src/layouts/default.vue b/src/layouts/default.vueindex 7d27e0439..d1efad4ec 100644--- a/src/layouts/default.vue+++ b/src/layouts/default.vue@@ -6,6 +6,7 @@<main class="embedded"><Nuxt /></main>+ <VGlobalAudioSection /></div></template>@@ -15,6 +16,7 @@ import { useContext } from '@nuxtjs/composition-api'import VHeader from '~/components/VHeader/VHeader.vue'import MigrationNotice from '~/components/MigrationNotice.vue'import TranslationStatusBanner from '~/components/TranslationStatusBanner.vue'+import VGlobalAudioSection from '~/components/VGlobalAudioSection/VGlobalAudioSection.vue'import iframeHeight from '~/mixins/iframe-height'import { NAV } from '~/constants/store-modules'@@ -25,6 +27,7 @@ const defaultLayout = {VHeader,MigrationNotice,TranslationStatusBanner,+ VGlobalAudioSection,},layout: 'default',mixins: [iframeHeight],diff --git a/src/locales/en.json b/src/locales/en.jsonindex b0098c5e7..065e7816f 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -651,7 +651,8 @@"title": "Audio Category","music": "Music","sound-effects": "Sound Effects",- "podcast": "Podcast"+ "podcast": "Podcast",+ "pronunciation": "Pronunciation"},"license-names": {"cc0": "CC0",diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.potindex 5dfb7da4a..b9b548504 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-01-12T20:51:27+00:00\n"+"POT-Creation-Date: 2022-01-17T06:57:32+00:00\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"@@ -134,6 +134,10 @@ msgctxt "audio-categories.podcast"msgid "Podcast"msgstr ""+msgctxt "audio-categories.pronunciation"+msgid "Pronunciation"+msgstr ""+#: src/components/VHeader/VSearchBar/VSearchButton.vue:7msgctxt "search.search"msgid "Search"@@ -183,7 +187,7 @@ msgid "Loading..."msgstr ""#. Do not translate words between ### ###.-#: src/components/AudioThumbnail/AudioThumbnail.vue:33+#: src/components/VAudioThumbnail/VAudioThumbnail.vue:142msgctxt "audio-thumbnail.alt"msgid "Cover art for \"###title###\" by ###creator###"msgstr ""@@ -194,7 +198,7 @@ msgid "Audio seek bar"msgstr ""#. Do not translate words between ### ###.-#: src/components/VAudioTrack/VWaveform.vue:514+#: src/components/VAudioTrack/VWaveform.vue:516msgctxt "waveform.current-time"msgid "###time### seconds"msgstr ""@@ -1136,13 +1140,13 @@ msgid "An error occurred"msgstr ""#. Do not translate words between ### ###.-#: src/pages/image/_id.vue:54+#: src/pages/image/_id.vue:53msgctxt "error.image-not-found"msgid "Couldn't find image with id ###id###"msgstr ""#. Do not translate words between ### ###.-#: src/pages/audio/_id.vue:70+#: src/pages/audio/_id.vue:69msgctxt "error.media-not-found"msgid "Couldn't find ###mediaType### with id ###id###"msgstr ""@@ -2016,7 +2020,7 @@ msgctxt "header.api-nav-item"msgid "API"msgstr ""-#: src/components/VHeader/VHeader.vue:144+#: src/components/VHeader/VHeader.vue:148msgctxt "header.loading"msgid "Loading..."msgstr ""diff --git a/src/store/active.js b/src/store/active.jsindex 2638c289f..781579d92 100644--- a/src/store/active.js+++ b/src/store/active.js@@ -2,6 +2,7 @@ import {SET_ACTIVE_MEDIA_ITEM,PAUSE_ACTIVE_MEDIA_ITEM,EJECT_ACTIVE_MEDIA_ITEM,+ SET_MESSAGE,} from '~/constants/mutation-types'/**@@ -12,6 +13,7 @@ const state = () => ({type: null,id: null,status: 'ejected', // can be 'playing' or 'paused' as well+ message: null,})const mutations = {@@ -44,6 +46,9 @@ const mutations = {_state.id = null_state.status = 'ejected'},+ [SET_MESSAGE](_state, { message }) {+ _state.message = message+ },}export default {diff --git a/src/store/index.js b/src/store/index.jsindex ad837e167..850798a3b 100644--- a/src/store/index.js+++ b/src/store/index.js@@ -1,6 +1,9 @@+import { createLogger } from 'vuex'import { FETCH_MEDIA_PROVIDERS } from '~/constants/action-types'import { PROVIDER } from '~/constants/store-modules'+export const plugins = [createLogger()]+export const actions = {async nuxtServerInit({ dispatch }) {try {diff --git a/test/unit/specs/components/AudioTrack/audio-track.spec.js b/test/unit/specs/components/AudioTrack/audio-track.spec.jsindex 494787b68..4bdf0ff79 100644--- a/test/unit/specs/components/AudioTrack/audio-track.spec.js+++ b/test/unit/specs/components/AudioTrack/audio-track.spec.js@@ -1,6 +1,7 @@import VAudioTrack from '~/components/VAudioTrack/VAudioTrack.vue'import { render } from '@testing-library/vue'import Vuei18n from 'vue-i18n'+import Vuex from 'vuex'const enMessages = require('~/locales/en.json')const useVueI18n = (vue) => {@@ -16,9 +17,39 @@ const useVueI18n = (vue) => {i18n,}}+const useVuexStore = (vue) => {+ vue.use(Vuex)++ const store = new Vuex.Store({+ modules: {+ active: {+ namespaced: true,+ state: {+ type: 'audio',+ id: 'e19345b8-6937-49f7-a0fd-03bf057efc28',+ message: null,+ state: 'paused',+ },+ },+ },+ })++ return {+ store,+ }+}++const configureVue = (vue) => {+ const { i18n } = useVueI18n(vue)+ const { store } = useVuexStore(vue)++ return {+ i18n,+ store,+ }+}const stubs = {- VAudioController: true,DownloadButton: true,VPlayPause: true,NuxtLink: true,@@ -82,7 +113,7 @@ describe('AudioTrack', () => {})it('should render the full audio track component even without duration', () => {- const { getByText } = render(VAudioTrack, options, useVueI18n)+ const { getByText } = render(VAudioTrack, options, configureVue)getByText(props.audio.creator)})@@ -91,19 +122,19 @@ describe('AudioTrack', () => {...options.propsData,layout: 'row',}- const { getByText } = render(VAudioTrack, options, useVueI18n)+ const { getByText } = render(VAudioTrack, options, configureVue)getByText('by ' + props.audio.creator)})it('should show audio title as main page title', () => {- const { getByText } = render(VAudioTrack, options, useVueI18n)+ const { getByText } = render(VAudioTrack, options, configureVue)const element = getByText(props.audio.title)expect(element).toBeInstanceOf(HTMLHeadingElement)expect(element.tagName).toEqual('H1')})it('should show audio creator with link', () => {- const { getByText } = render(VAudioTrack, options, useVueI18n)+ const { getByText } = render(VAudioTrack, options, configureVue)const element = getByText(props.audio.creator)expect(element).toBeInstanceOf(HTMLAnchorElement)expect(element).toHaveAttribute('href', props.audio.creator_url)