mirror of
https://github.com/koel/koel
synced 2024-11-28 06:50:27 +00:00
fix(test): AlbumArtOverlay tests
This commit is contained in:
parent
e6dd82503b
commit
44985fa23a
1 changed files with 23 additions and 20 deletions
|
@ -1,44 +1,47 @@
|
|||
import { expect, it } from 'vitest'
|
||||
import { albumStore } from '@/stores'
|
||||
import factory from '@/__tests__/factory'
|
||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||
import AlbumArtOverlay from './AlbumArtOverlay.vue'
|
||||
import { waitFor } from '@testing-library/vue'
|
||||
|
||||
let album: Album
|
||||
let albumId: number
|
||||
|
||||
new class extends UnitTestCase {
|
||||
private renderComponent () {
|
||||
album = factory<Album>('album')
|
||||
private async renderComponent () {
|
||||
albumId = 42
|
||||
|
||||
return this.render(AlbumArtOverlay, {
|
||||
const rendered = this.render(AlbumArtOverlay, {
|
||||
props: {
|
||||
album
|
||||
album: albumId
|
||||
}
|
||||
})
|
||||
|
||||
await this.tick()
|
||||
|
||||
return rendered
|
||||
}
|
||||
|
||||
protected test () {
|
||||
it('fetches and displays the album thumbnail', async () => {
|
||||
const mock = this.mock(albumStore, 'fetchThumbnail')
|
||||
mock.mockResolvedValue('https://localhost/thumb.jpg')
|
||||
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockResolvedValue('https://localhost/thumb.jpg')
|
||||
|
||||
const { html } = this.renderComponent()
|
||||
await this.tick(2)
|
||||
const { html } = await this.renderComponent()
|
||||
|
||||
expect(mock).toHaveBeenCalledWith(album)
|
||||
expect(html()).toMatchSnapshot()
|
||||
await waitFor(() => {
|
||||
expect(fetchMock).toHaveBeenCalledWith(albumId)
|
||||
expect(html()).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
it('displays nothing if fetching fails', async () => {
|
||||
const mock = this.mock(albumStore, 'fetchThumbnail', () => {
|
||||
throw new Error()
|
||||
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockRejectedValue(new Error())
|
||||
|
||||
const { html } = await this.renderComponent()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(fetchMock).toHaveBeenCalledWith(albumId)
|
||||
expect(html()).toMatchSnapshot()
|
||||
})
|
||||
|
||||
const { html } = this.renderComponent()
|
||||
await this.tick(2)
|
||||
|
||||
expect(mock).toHaveBeenCalledWith(album)
|
||||
expect(html()).toMatchSnapshot()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue