fix(test): ArtistCard tests

This commit is contained in:
Phan An 2022-07-08 23:25:20 +02:00
parent 653153fc90
commit 5a184c0cd0
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC

View file

@ -1,8 +1,9 @@
import { fireEvent } from '@testing-library/vue' import { fireEvent } from '@testing-library/vue'
import { expect, it } from 'vitest' import { expect, it } from 'vitest'
import factory from '@/__tests__/factory' import factory from '@/__tests__/factory'
import { downloadService } from '@/services' import { downloadService, playbackService } from '@/services'
import UnitTestCase from '@/__tests__/UnitTestCase' import UnitTestCase from '@/__tests__/UnitTestCase'
import { commonStore, songStore } from '@/stores'
import ArtistCard from './ArtistCard.vue' import ArtistCard from './ArtistCard.vue'
let artist: Artist let artist: Artist
@ -11,8 +12,10 @@ new class extends UnitTestCase {
protected beforeEach () { protected beforeEach () {
super.beforeEach(() => { super.beforeEach(() => {
artist = factory<Artist>('artist', { artist = factory<Artist>('artist', {
id: 3, // make sure it's not "Various Artists" name: 'Led Zeppelin',
name: 'Led Zeppelin' album_count: 4,
play_count: 124,
song_count: 16
}) })
}) })
} }
@ -26,7 +29,7 @@ new class extends UnitTestCase {
}) })
expect(getByTestId('name').textContent).toBe('Led Zeppelin') expect(getByTestId('name').textContent).toBe('Led Zeppelin')
getByText(/^4 albums\s+•\s+16 songs.+0 plays$/) getByText(/^4 albums\s+•\s+16 songs.+124 plays$/)
getByTestId('shuffle-artist') getByTestId('shuffle-artist')
getByTestId('download-artist') getByTestId('download-artist')
}) })
@ -41,11 +44,37 @@ new class extends UnitTestCase {
}) })
await fireEvent.click(getByTestId('download-artist')) await fireEvent.click(getByTestId('download-artist'))
expect(mock).toHaveBeenCalledTimes(1) 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()
}) })
it('shuffles', async () => { it('shuffles', async () => {
throw 'Unimplemented' const songs = factory<Song[]>('song', 16)
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)
expect(playMock).toHaveBeenCalled(songs, true)
}) })
} }
} }