mirror of
https://github.com/koel/koel
synced 2024-12-30 06:23:05 +00:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { expect, it } from 'vitest'
|
|
import { albumStore } from '@/stores'
|
|
import factory from '@/__tests__/factory'
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
import AlbumArtOverlay from './AlbumArtOverlay.vue'
|
|
|
|
let album: Album
|
|
|
|
new class extends UnitTestCase {
|
|
private renderComponent () {
|
|
album = factory<Album>('album')
|
|
|
|
return this.render(AlbumArtOverlay, {
|
|
props: {
|
|
album
|
|
}
|
|
})
|
|
}
|
|
|
|
protected test () {
|
|
it('fetches and displays the album thumbnail', async () => {
|
|
const mock = this.mock(albumStore, 'fetchThumbnail')
|
|
mock.mockResolvedValue('https://localhost/thumb.jpg')
|
|
|
|
const { html } = this.renderComponent()
|
|
await this.tick(2)
|
|
|
|
expect(mock).toHaveBeenCalledWith(album)
|
|
expect(html()).toMatchSnapshot()
|
|
})
|
|
|
|
it('displays nothing if fetching fails', async () => {
|
|
const mock = this.mock(albumStore, 'fetchThumbnail', () => {
|
|
throw new Error()
|
|
})
|
|
|
|
const { html } = this.renderComponent()
|
|
await this.tick(2)
|
|
|
|
expect(mock).toHaveBeenCalledWith(album)
|
|
expect(html()).toMatchSnapshot()
|
|
})
|
|
}
|
|
}
|