2022-05-09 09:59:31 +00:00
|
|
|
import { fireEvent } from '@testing-library/vue'
|
|
|
|
import { expect, it } from 'vitest'
|
2022-05-02 07:21:14 +00:00
|
|
|
import { downloadService, playbackService } from '@/services'
|
2022-05-02 18:53:19 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-04 20:47:12 +00:00
|
|
|
import AlbumCard from './AlbumCard.vue'
|
2022-05-02 07:21:14 +00:00
|
|
|
|
2022-05-03 16:51:59 +00:00
|
|
|
let album: Album
|
2022-05-02 07:21:14 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 09:59:31 +00:00
|
|
|
protected beforeEach () {
|
|
|
|
super.beforeEach(() => {
|
|
|
|
album = factory<Album>('album', {
|
|
|
|
name: 'IV',
|
|
|
|
songs: factory<Song>('song', 10)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => {
|
|
|
|
const { getByText, getByTestId } = this.render(AlbumCard, {
|
|
|
|
props: {
|
|
|
|
album
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-05-15 20:44:19 +00:00
|
|
|
expect(getByTestId('name').textContent).toBe('IV')
|
2022-05-09 09:59:31 +00:00
|
|
|
getByText(/^10 songs.+0 plays$/)
|
|
|
|
getByTestId('shuffle-album')
|
|
|
|
getByTestId('download-album')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('downloads', async () => {
|
|
|
|
const mock = this.mock(downloadService, 'fromAlbum')
|
|
|
|
|
|
|
|
const { getByTestId } = this.render(AlbumCard, {
|
|
|
|
props: {
|
|
|
|
album
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('download-album'))
|
|
|
|
expect(mock).toHaveBeenCalledTimes(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles', async () => {
|
|
|
|
const mock = this.mock(playbackService, 'playAllInAlbum')
|
|
|
|
|
|
|
|
const { getByTestId } = this.render(AlbumCard, {
|
|
|
|
props: {
|
|
|
|
album
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('shuffle-album'))
|
|
|
|
expect(mock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|