koel/resources/assets/js/components/ui/AlbumArtOverlay.spec.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
import { albumStore } from '@/stores'
import factory from '@/__tests__/factory'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import AlbumArtOverlay from './AlbumArtOverlay.vue'
let album: Album
2022-05-13 17:58:38 +00:00
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 () => {
2022-06-10 10:47:46 +00:00
const mock = this.mock(albumStore, 'fetchThumbnail')
2022-05-11 15:24:28 +00:00
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 () => {
2022-06-10 10:47:46 +00:00
const mock = this.mock(albumStore, 'fetchThumbnail', () => {
throw new Error()
})
const { html } = this.renderComponent()
await this.tick(2)
expect(mock).toHaveBeenCalledWith(album)
expect(html()).toMatchSnapshot()
})
}
}