2022-05-11 07:21:57 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import { albumStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-11 07:21:57 +00:00
|
|
|
import AlbumArtOverlay from './AlbumArtOverlay.vue'
|
2022-07-21 09:24:33 +00:00
|
|
|
import { waitFor } from '@testing-library/vue'
|
2022-05-11 07:21:57 +00:00
|
|
|
|
2022-07-21 09:24:33 +00:00
|
|
|
let albumId: number
|
2022-05-11 07:21:57 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-07-21 09:24:33 +00:00
|
|
|
private async renderComponent () {
|
|
|
|
albumId = 42
|
2022-05-11 07:21:57 +00:00
|
|
|
|
2022-07-21 09:24:33 +00:00
|
|
|
const rendered = this.render(AlbumArtOverlay, {
|
2022-05-11 07:21:57 +00:00
|
|
|
props: {
|
2022-07-21 09:24:33 +00:00
|
|
|
album: albumId
|
2022-05-11 07:21:57 +00:00
|
|
|
}
|
|
|
|
})
|
2022-07-21 09:24:33 +00:00
|
|
|
|
|
|
|
await this.tick()
|
|
|
|
|
|
|
|
return rendered
|
2022-05-11 07:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-05-12 09:03:40 +00:00
|
|
|
it('fetches and displays the album thumbnail', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockResolvedValue('http://localhost/thumb.jpg')
|
2022-05-11 07:21:57 +00:00
|
|
|
|
2022-07-21 09:24:33 +00:00
|
|
|
const { html } = await this.renderComponent()
|
2022-05-11 07:21:57 +00:00
|
|
|
|
2022-07-21 09:24:33 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(albumId)
|
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
})
|
2022-05-11 07:21:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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-05-11 07:21:57 +00:00
|
|
|
|
2022-07-21 09:24:33 +00:00
|
|
|
const { html } = await this.renderComponent()
|
2022-05-11 07:21:57 +00:00
|
|
|
|
2022-07-21 09:24:33 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(albumId)
|
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
})
|
2022-05-11 07:21:57 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|