Skip to content

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

Show all filetypes of audio in details page (#1763)

Krystle Salazarda1579121b6d
diff --git a/src/components/VAudioDetails/VAudioDetails.vue b/src/components/VAudioDetails/VAudioDetails.vue
index 6375f2aa8..2d01ce678 100644
--- a/src/components/VAudioDetails/VAudioDetails.vue
+++ b/src/components/VAudioDetails/VAudioDetails.vue
@@ -50,7 +50,7 @@
{{ $t('audio-details.table.filetype') }}
</dt>
<dd>
- {{ audio.filetype.toUpperCase() }}
+ {{ audioFormats.toUpperCase() }}
</dd>
</div>
<div>
@@ -86,7 +86,7 @@
</template>
<script lang="ts">
-import { defineComponent, PropType } from '@nuxtjs/composition-api'
+import { computed, defineComponent, PropType } from '@nuxtjs/composition-api'
import type { AudioDetail } from '~/models/media'
@@ -104,6 +104,19 @@ export default defineComponent({
required: true,
},
},
+ setup(props) {
+ const audioFormats = computed(() => {
+ if (!props.audio.alt_files) return props.audio.filetype
+ const altFormats = props.audio.alt_files.map(
+ (altFile) => altFile.filetype
+ )
+ altFormats.unshift(props.audio.filetype)
+ const uniqueFormats = new Set(altFormats)
+ return [...uniqueFormats].join(', ')
+ })
+
+ return { audioFormats }
+ },
})
</script>
diff --git a/test/unit/fixtures/audio.js b/test/unit/fixtures/audio.js
index 84d035568..cf56a02e1 100644
--- a/test/unit/fixtures/audio.js
+++ b/test/unit/fixtures/audio.js
@@ -30,7 +30,10 @@ export const getAudioObj = (overrides = {}) =>
name: 'cuivres',
},
],
- fields_matched: ['tags.name'],
+ alt_files: null,
+ attribution:
+ '"La vie des bêtes" by AS-POTIRONT! is licensed under CC BY-NC-SA 2.5. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/2.5/.',
+ mature: null,
thumbnail:
'https://localhost:8000/v1/audio/e19345b8-6937-49f7-a0fd-03bf057efc28/thumb',
waveform:
diff --git a/test/unit/specs/components/VAudioDetails/v-audio-details.spec.js b/test/unit/specs/components/VAudioDetails/v-audio-details.spec.js
index 254f655e0..d2b7d13eb 100644
--- a/test/unit/specs/components/VAudioDetails/v-audio-details.spec.js
+++ b/test/unit/specs/components/VAudioDetails/v-audio-details.spec.js
@@ -43,4 +43,27 @@ describe('VAudioDetails', () => {
render(VAudioDetails, options)
expect(screen.queryByText('Album')).toBeNull()
})
+
+ it('displays the main filetype when no alternative files are available', () => {
+ render(VAudioDetails, options)
+ screen.getByText('MP32') // throw if not found
+ })
+
+ it('displays multiple filetypes when they are available in alt_files', () => {
+ options.propsData.audio.alt_files = [
+ { filetype: 'wav' },
+ { filetype: 'ogg' },
+ ]
+ render(VAudioDetails, options)
+ screen.getByText('MP32, WAV, OGG')
+ })
+
+ it('displays only distinct filetypes', () => {
+ options.propsData.audio.alt_files = [
+ { filetype: 'ogg' },
+ { filetype: 'ogg' },
+ ]
+ render(VAudioDetails, options)
+ screen.getByText('MP32, OGG')
+ })
})