koel/resources/assets/js/components/ui/album-artist/AlbumOrArtistThumbnail.spec.ts

110 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-07-21 09:17:08 +00:00
import { orderBy } from 'lodash'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import { expect, it } from 'vitest'
import factory from '@/__tests__/factory'
import { screen, waitFor } from '@testing-library/vue'
2022-07-21 09:17:08 +00:00
import { queueStore, songStore } from '@/stores'
import { playbackService } from '@/services'
2024-04-29 19:50:03 +00:00
import Thumbnail from './AlbumOrArtistThumbnail.vue'
let album: Album
let artist: Artist
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
it('renders for album', () => {
expect(this.renderForAlbum().html()).toMatchSnapshot()
})
it('renders for artist', () => {
expect(this.renderForArtist().html()).toMatchSnapshot()
})
it('plays album', async () => {
const songs = factory('song', 10)
2022-07-21 09:17:08 +00:00
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
const playMock = this.mock(playbackService, 'queueAndPlay')
this.renderForAlbum()
2022-07-21 09:17:08 +00:00
await this.user.click(screen.getByRole('button'))
2022-07-21 09:17:08 +00:00
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(album)
expect(playMock).toHaveBeenCalledWith(songs)
})
})
it('queues album', async () => {
const songs = factory('song', 10)
2022-07-21 09:17:08 +00:00
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
const queueMock = this.mock(queueStore, 'queue')
this.renderForAlbum()
2022-07-21 09:17:08 +00:00
await this.user.keyboard('{Alt>}')
await this.user.click(screen.getByRole('button'))
await this.user.keyboard('{/Alt}')
2022-07-21 09:17:08 +00:00
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(album)
expect(queueMock).toHaveBeenCalledWith(orderBy(songs, ['disc', 'track']))
})
})
it('plays artist', async () => {
const songs = factory('song', 10)
2022-07-21 09:17:08 +00:00
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
const playMock = this.mock(playbackService, 'queueAndPlay')
this.renderForArtist()
2022-07-21 09:17:08 +00:00
await this.user.click(screen.getByRole('button'))
2022-07-21 09:17:08 +00:00
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(artist)
expect(playMock).toHaveBeenCalledWith(songs)
})
})
it('queues artist', async () => {
const songs = factory('song', 10)
2022-07-21 09:17:08 +00:00
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
const queueMock = this.mock(queueStore, 'queue')
this.renderForArtist()
2022-07-21 09:17:08 +00:00
await this.user.keyboard('{Alt>}')
await this.user.click(screen.getByRole('button'))
await this.user.keyboard('{/Alt}')
2022-07-21 09:17:08 +00:00
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(artist)
expect(queueMock).toHaveBeenCalledWith(orderBy(songs, ['album_id', 'disc', 'track']))
})
})
}
2024-04-23 21:01:27 +00:00
private renderForAlbum () {
album = factory('album', {
2024-04-23 21:01:27 +00:00
name: 'IV',
cover: 'https://test/album.jpg',
2024-04-23 21:01:27 +00:00
})
return this.render(Thumbnail, {
props: {
entity: album,
},
2024-04-23 21:01:27 +00:00
})
}
private renderForArtist () {
artist = factory('artist', {
2024-04-23 21:01:27 +00:00
name: 'Led Zeppelin',
image: 'https://test/blimp.jpg',
2024-04-23 21:01:27 +00:00
})
return this.render(Thumbnail, {
props: {
entity: artist,
},
2024-04-23 21:01:27 +00:00
})
}
}