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 { expect, it } from 'vitest'
|
||||||
import { albumStore } from '@/stores'
|
import { albumStore } from '@/stores'
|
||||||
import factory from '@/__tests__/factory'
|
|
||||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||||
import AlbumArtOverlay from './AlbumArtOverlay.vue'
|
import AlbumArtOverlay from './AlbumArtOverlay.vue'
|
||||||
|
import { waitFor } from '@testing-library/vue'
|
||||||
|
|
||||||
let album: Album
|
let albumId: number
|
||||||
|
|
||||||
new class extends UnitTestCase {
|
new class extends UnitTestCase {
|
||||||
private renderComponent () {
|
private async renderComponent () {
|
||||||
album = factory<Album>('album')
|
albumId = 42
|
||||||
|
|
||||||
return this.render(AlbumArtOverlay, {
|
const rendered = this.render(AlbumArtOverlay, {
|
||||||
props: {
|
props: {
|
||||||
album
|
album: albumId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await this.tick()
|
||||||
|
|
||||||
|
return rendered
|
||||||
}
|
}
|
||||||
|
|
||||||
protected test () {
|
protected test () {
|
||||||
it('fetches and displays the album thumbnail', async () => {
|
it('fetches and displays the album thumbnail', async () => {
|
||||||
const mock = this.mock(albumStore, 'fetchThumbnail')
|
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockResolvedValue('https://localhost/thumb.jpg')
|
||||||
mock.mockResolvedValue('https://localhost/thumb.jpg')
|
|
||||||
|
|
||||||
const { html } = this.renderComponent()
|
const { html } = await this.renderComponent()
|
||||||
await this.tick(2)
|
|
||||||
|
|
||||||
expect(mock).toHaveBeenCalledWith(album)
|
await waitFor(() => {
|
||||||
expect(html()).toMatchSnapshot()
|
expect(fetchMock).toHaveBeenCalledWith(albumId)
|
||||||
|
expect(html()).toMatchSnapshot()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('displays nothing if fetching fails', async () => {
|
it('displays nothing if fetching fails', async () => {
|
||||||
const mock = this.mock(albumStore, 'fetchThumbnail', () => {
|
const fetchMock = this.mock(albumStore, 'fetchThumbnail').mockRejectedValue(new Error())
|
||||||
throw 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