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'
|
2022-05-10 22:35:34 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-11-29 10:18:58 +00:00
|
|
|
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-02-24 15:37:01 +00:00
|
|
|
import Thumbnail from './ArtistAlbumThumbnail.vue'
|
2022-05-10 22:35:34 +00:00
|
|
|
|
|
|
|
let album: Album
|
|
|
|
let artist: Artist
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-10 22:35:34 +00:00
|
|
|
private renderForAlbum () {
|
|
|
|
album = factory<Album>('album', {
|
|
|
|
name: 'IV',
|
2022-10-09 10:53:10 +00:00
|
|
|
cover: 'https://test/album.jpg'
|
2022-05-10 22:35:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return this.render(Thumbnail, {
|
|
|
|
props: {
|
|
|
|
entity: album
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderForArtist () {
|
|
|
|
artist = factory<Artist>('artist', {
|
|
|
|
name: 'Led Zeppelin',
|
2022-10-09 10:53:10 +00:00
|
|
|
image: 'https://test/blimp.jpg'
|
2022-05-10 22:35:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return this.render(Thumbnail, {
|
|
|
|
props: {
|
|
|
|
entity: artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders for album', () => {
|
|
|
|
expect(this.renderForAlbum().html()).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders for artist', () => {
|
|
|
|
expect(this.renderForArtist().html()).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('plays album', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 10)
|
2022-07-21 09:17:08 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderForAlbum()
|
2022-07-21 09:17:08 +00:00
|
|
|
|
2022-11-29 10:18:58 +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)
|
|
|
|
})
|
2022-05-10 22:35:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('queues album', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 10)
|
2022-07-21 09:17:08 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
|
|
|
|
const queueMock = this.mock(queueStore, 'queue')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderForAlbum()
|
2022-07-21 09:17:08 +00:00
|
|
|
|
2022-11-29 10:18:58 +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']))
|
|
|
|
})
|
2022-05-10 22:35:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('plays artist', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 10)
|
2022-07-21 09:17:08 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderForArtist()
|
2022-07-21 09:17:08 +00:00
|
|
|
|
2022-11-29 10:18:58 +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)
|
|
|
|
})
|
2022-05-10 22:35:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('queues artist', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 10)
|
2022-07-21 09:17:08 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
|
|
|
|
const queueMock = this.mock(queueStore, 'queue')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderForArtist()
|
2022-07-21 09:17:08 +00:00
|
|
|
|
2022-11-29 10:18:58 +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']))
|
|
|
|
})
|
2022-05-10 22:35:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|