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'
|
|
|
|
import { downloadService, playbackService } from '@/services'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
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', {
|
|
|
|
id: 3, // make sure it's not "Various Artists"
|
|
|
|
name: 'Led Zeppelin',
|
|
|
|
albums: factory<Album>('album', 4),
|
|
|
|
songs: factory<Song>('song', 16)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => {
|
|
|
|
const { getByText, getByTestId } = this.render(ArtistCard, {
|
|
|
|
props: {
|
|
|
|
artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-05-15 20:44:19 +00:00
|
|
|
expect(getByTestId('name').textContent).toBe('Led Zeppelin')
|
2022-05-09 09:59:31 +00:00
|
|
|
getByText(/^4 albums\s+•\s+16 songs.+0 plays$/)
|
|
|
|
getByTestId('shuffle-artist')
|
|
|
|
getByTestId('download-artist')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('downloads', async () => {
|
|
|
|
const mock = this.mock(downloadService, 'fromArtist')
|
|
|
|
|
|
|
|
const { getByTestId } = this.render(ArtistCard, {
|
|
|
|
props: {
|
|
|
|
artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('download-artist'))
|
|
|
|
expect(mock).toHaveBeenCalledTimes(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles', async () => {
|
|
|
|
const mock = this.mock(playbackService, 'playAllByArtist')
|
|
|
|
|
|
|
|
const { getByTestId } = this.render(ArtistCard, {
|
|
|
|
props: {
|
|
|
|
artist
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('shuffle-artist'))
|
|
|
|
expect(mock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|