2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-07-08 10:32:44 +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-11-29 10:18:58 +00:00
|
|
|
import { commonStore, songStore } from '@/stores'
|
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-07-08 10:32:44 +00:00
|
|
|
private renderComponent () {
|
|
|
|
album = factory<Album>('album', {
|
2022-10-11 15:28:43 +00:00
|
|
|
id: 42,
|
2022-07-08 10:32:44 +00:00
|
|
|
name: 'IV',
|
2022-10-12 09:27:35 +00:00
|
|
|
artist_id: 17,
|
2022-10-11 15:28:43 +00:00
|
|
|
artist_name: 'Led Zeppelin'
|
2022-07-08 10:32:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return this.render(AlbumCard, {
|
|
|
|
props: {
|
|
|
|
album
|
2022-10-28 23:59:04 +00:00
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
AlbumArtistThumbnail: this.stub('thumbnail')
|
|
|
|
}
|
2022-07-08 10:32:44 +00:00
|
|
|
}
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-10-28 23:59:04 +00:00
|
|
|
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
2022-05-09 09:59:31 +00:00
|
|
|
|
|
|
|
it('downloads', async () => {
|
|
|
|
const mock = this.mock(downloadService, 'fromAlbum')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-09 09:59:31 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Download all songs in the album IV'))
|
2022-07-08 10:32:44 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledTimes(1)
|
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
it('does not have an option to download if downloading is disabled', async () => {
|
2024-01-04 11:35:36 +00:00
|
|
|
commonStore.state.allows_download = false
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
|
|
|
|
|
|
|
expect(screen.queryByText('Download')).toBeNull()
|
|
|
|
})
|
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('shuffles', async () => {
|
2022-07-08 10:32:44 +00:00
|
|
|
const songs = factory<Song>('song', 10)
|
|
|
|
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
|
|
|
|
const shuffleMock = this.mock(playbackService, 'queueAndPlay').mockResolvedValue(void 0)
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-07-08 10:32:44 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Shuffle all songs in the album IV'))
|
2022-07-08 10:32:44 +00:00
|
|
|
await this.tick()
|
|
|
|
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(album)
|
|
|
|
expect(shuffleMock).toHaveBeenCalledWith(songs, true)
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|