2022-11-29 10:18:58 +00:00
|
|
|
import { waitFor } from '@testing-library/vue'
|
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
|
|
|
let albumId: number
|
2022-05-11 07:21:57 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
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-10-09 10:53:10 +00:00
|
|
|
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockResolvedValue('http://test/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 () => {
|
2024-10-13 17:37:01 +00:00
|
|
|
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockRejectedValue(new Error('Failed to fetch'))
|
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
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private async renderComponent () {
|
|
|
|
albumId = 42
|
|
|
|
|
|
|
|
const rendered = this.render(AlbumArtOverlay, {
|
|
|
|
props: {
|
2024-10-13 17:37:01 +00:00
|
|
|
album: albumId,
|
|
|
|
},
|
2024-04-23 21:01:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
await this.tick()
|
|
|
|
|
|
|
|
return rendered
|
|
|
|
}
|
2022-05-11 07:21:57 +00:00
|
|
|
}
|