koel/resources/assets/js/components/ui/AlbumArtOverlay.spec.ts

48 lines
1.2 KiB
TypeScript
Raw Normal View History

import { waitFor } from '@testing-library/vue'
import { expect, it } from 'vitest'
import { albumStore } from '@/stores'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import AlbumArtOverlay from './AlbumArtOverlay.vue'
2022-07-21 09:24:33 +00:00
let albumId: number
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
it('fetches and displays the album thumbnail', async () => {
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockResolvedValue('http://test/thumb.jpg')
2022-07-21 09:24:33 +00:00
const { html } = await this.renderComponent()
2022-07-21 09:24:33 +00:00
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(albumId)
expect(html()).toMatchSnapshot()
})
})
it('displays nothing if fetching fails', async () => {
2022-07-21 09:24:33 +00:00
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockRejectedValue(new Error())
2022-07-21 09:24:33 +00:00
const { html } = await this.renderComponent()
2022-07-21 09:24:33 +00:00
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(albumId)
expect(html()).toMatchSnapshot()
})
})
}
2024-04-23 21:01:27 +00:00
private async renderComponent () {
albumId = 42
const rendered = this.render(AlbumArtOverlay, {
props: {
album: albumId
}
})
await this.tick()
return rendered
}
}