fix(tests): make frontend tests compatible with current frontend setup

This commit is contained in:
Kasper Seweryn 2023-05-06 12:25:33 +02:00 committed by jo
commit ed4b923b1e
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984
6 changed files with 129 additions and 22 deletions

View file

@ -0,0 +1,9 @@
import { AudioContext } from 'standardized-audio-context-mock'
import { vi, beforeAll } from 'vitest'
beforeAll(() => {
vi.mock('standardized-audio-context', () => ({
AudioContext
}))
})

View file

@ -0,0 +1,14 @@
import { config } from '@vue/test-utils'
import { createI18n } from 'vue-i18n'
import en from '~/locales/en_US.json'
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: {
en
}
})
config.global.plugins ??= []
config.global.plugins.push(i18n)

View file

@ -3,7 +3,8 @@ import AlbumDetail from '~/views/admin/library/AlbumDetail.vue'
import SanitizedHtml from '~/components/SanitizedHtml.vue'
import HumanDate from '~/components/common/HumanDate.vue'
import moxios from 'moxios'
import MockAdapter from 'axios-mock-adapter'
import axios from 'axios'
import { shallowMount } from '@vue/test-utils'
import { sleep } from '?/utils'
@ -11,23 +12,15 @@ import { sleep } from '?/utils'
import router from '~/router'
import store from '~/store'
beforeEach(() => moxios.install())
afterEach(() => moxios.uninstall())
const axiosMock = new MockAdapter(axios)
describe('views/admin/library', () => {
describe('Album details', () => {
it('displays default cover', async () => {
const album = { cover: null, artist: { id: 1 }, title: 'dummy', id: 1, creation_date: '2020-01-01' }
moxios.stubRequest('manage/library/albums/1/', {
status: 200,
response: album
})
moxios.stubRequest('manage/library/albums/1/stats/', {
status: 200,
response: {}
})
axiosMock.onGet('manage/library/albums/1/').reply(200, album)
axiosMock.onGet('manage/library/albums/1/stats/').reply(200, {})
const wrapper = shallowMount(AlbumDetail, {
props: { id: 1 },