2024-01-18 11:13:05 +00:00
|
|
|
import Router from '@/router'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-11 17:35:58 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { artistStore, commonStore, songStore } from '@/stores'
|
|
|
|
import { downloadService } from '@/services'
|
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import ArtistScreen from './ArtistScreen.vue'
|
|
|
|
|
|
|
|
let artist: Artist
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected async renderComponent () {
|
2024-01-04 11:35:36 +00:00
|
|
|
commonStore.state.uses_last_fm = true
|
2022-07-11 17:35:58 +00:00
|
|
|
|
2024-06-01 18:02:27 +00:00
|
|
|
artist = factory('artist', {
|
2022-07-11 17:35:58 +00:00
|
|
|
id: 42,
|
|
|
|
name: 'Led Zeppelin',
|
|
|
|
})
|
|
|
|
|
2022-08-01 09:38:32 +00:00
|
|
|
const resolveArtistMock = this.mock(artistStore, 'resolve').mockResolvedValue(artist)
|
|
|
|
|
2024-06-01 18:02:27 +00:00
|
|
|
const songs = factory('song', 13)
|
2022-07-11 17:35:58 +00:00
|
|
|
const fetchSongsMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
await this.router.activateRoute({
|
|
|
|
path: 'artists/42',
|
2024-10-13 17:37:01 +00:00
|
|
|
screen: 'Artist',
|
2022-10-08 10:54:25 +00:00
|
|
|
}, { id: '42' })
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(ArtistScreen, {
|
2022-07-11 17:35:58 +00:00
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
ArtistInfo: this.stub('artist-info'),
|
2022-10-18 14:07:41 +00:00
|
|
|
SongList: this.stub('song-list'),
|
2024-10-13 17:37:01 +00:00
|
|
|
AlbumCard: this.stub('album-card'),
|
|
|
|
},
|
|
|
|
},
|
2022-07-11 17:35:58 +00:00
|
|
|
})
|
|
|
|
|
2022-08-01 09:38:32 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(resolveArtistMock).toHaveBeenCalledWith(artist.id)
|
|
|
|
expect(fetchSongsMock).toHaveBeenCalledWith(artist.id)
|
|
|
|
})
|
|
|
|
|
|
|
|
await this.tick(2)
|
2022-07-11 17:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('downloads', async () => {
|
|
|
|
const downloadMock = this.mock(downloadService, 'fromArtist')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-11 17:35:58 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Download All' }))
|
2022-07-11 17:35:58 +00:00
|
|
|
|
|
|
|
expect(downloadMock).toHaveBeenCalledWith(artist)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('goes back to list if artist is deleted', async () => {
|
2024-01-18 11:13:05 +00:00
|
|
|
const goMock = this.mock(Router, 'go')
|
2022-07-11 17:35:58 +00:00
|
|
|
const byIdMock = this.mock(artistStore, 'byId', null)
|
|
|
|
await this.renderComponent()
|
|
|
|
|
|
|
|
eventBus.emit('SONGS_UPDATED')
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(byIdMock).toHaveBeenCalledWith(artist.id)
|
|
|
|
expect(goMock).toHaveBeenCalledWith('artists')
|
|
|
|
})
|
|
|
|
})
|
2022-10-18 14:07:41 +00:00
|
|
|
|
|
|
|
it('shows the song list', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
|
|
|
screen.getByTestId('song-list')
|
2022-10-18 14:07:41 +00:00
|
|
|
})
|
2022-07-11 17:35:58 +00:00
|
|
|
}
|
|
|
|
}
|