2022-05-09 09:59:31 +00:00
|
|
|
import { fireEvent } from '@testing-library/vue'
|
|
|
|
import { expect, it } from 'vitest'
|
2022-05-04 20:47:12 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
2022-07-08 21:25:20 +00:00
|
|
|
import { downloadService, playbackService } from '@/services'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-07-08 21:25:20 +00:00
|
|
|
import { commonStore, songStore } from '@/stores'
|
2022-05-09 09:59:31 +00:00
|
|
|
import ArtistCard from './ArtistCard.vue'
|
2022-05-04 20:47:12 +00:00
|
|
|
|
|
|
|
let artist: Artist
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 09:59:31 +00:00
|
|
|
protected beforeEach () {
|
|
|
|
super.beforeEach(() => {
|
|
|
|
artist = factory<Artist>('artist', {
|
2022-10-11 15:28:43 +00:00
|
|
|
id: 42,
|
|
|
|
name: 'Led Zeppelin'
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => {
|
2022-10-11 15:28:43 +00:00
|
|
|
const { html } = this.render(ArtistCard, {
|
2022-05-09 09:59:31 +00:00
|
|
|
props: {
|
|
|
|
artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-10-11 15:28:43 +00:00
|
|
|
expect(html()).toMatchSnapshot()
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('downloads', async () => {
|
|
|
|
const mock = this.mock(downloadService, 'fromArtist')
|
|
|
|
|
|
|
|
const { getByTestId } = this.render(ArtistCard, {
|
|
|
|
props: {
|
|
|
|
artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('download-artist'))
|
2022-07-08 21:25:20 +00:00
|
|
|
expect(mock).toHaveBeenCalledOnce()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not have an option to download if downloading is disabled', async () => {
|
|
|
|
commonStore.state.allow_download = false
|
|
|
|
|
|
|
|
const { queryByTestId } = this.render(ArtistCard, {
|
|
|
|
props: {
|
|
|
|
artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(queryByTestId('download-artist')).toBeNull()
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 16)
|
2022-07-08 21:25:20 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
|
|
|
|
const { getByTestId } = this.render(ArtistCard, {
|
|
|
|
props: {
|
|
|
|
artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('shuffle-artist'))
|
|
|
|
await this.tick()
|
|
|
|
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(artist)
|
2022-09-14 16:45:08 +00:00
|
|
|
expect(playMock).toHaveBeenCalledWith(songs, true)
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|