2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-05-04 21:01:35 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-07-10 13:50:41 +00:00
|
|
|
import { commonStore, songStore } from '@/stores'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-10-08 10:54:25 +00:00
|
|
|
import { mediaInfoService, playbackService } from '@/services'
|
2022-07-10 13:50:41 +00:00
|
|
|
import ArtistInfoComponent from './ArtistInfo.vue'
|
|
|
|
|
2022-09-14 16:45:08 +00:00
|
|
|
let artist: Artist
|
2022-05-04 21:01:35 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-07-10 13:50:41 +00:00
|
|
|
private async renderComponent (mode: MediaInfoDisplayMode = 'aside', info?: ArtistInfo) {
|
|
|
|
commonStore.state.use_last_fm = true
|
2022-12-03 15:55:22 +00:00
|
|
|
info = info ?? factory<ArtistInfo>('artist-info')
|
2022-07-10 13:50:41 +00:00
|
|
|
artist = factory<Artist>('artist', { name: 'Led Zeppelin' })
|
2022-11-29 10:18:58 +00:00
|
|
|
|
2022-07-10 13:50:41 +00:00
|
|
|
const fetchMock = this.mock(mediaInfoService, 'fetchForArtist').mockResolvedValue(info)
|
|
|
|
|
|
|
|
const rendered = this.render(ArtistInfoComponent, {
|
|
|
|
props: {
|
|
|
|
artist,
|
|
|
|
mode
|
2022-10-18 14:07:41 +00:00
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
ArtistThumbnail: this.stub('thumbnail')
|
|
|
|
}
|
2022-07-10 13:50:41 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await this.tick(1)
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(artist)
|
|
|
|
|
|
|
|
return rendered
|
|
|
|
}
|
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
2022-07-10 13:50:41 +00:00
|
|
|
it.each<[MediaInfoDisplayMode]>([['aside'], ['full']])('renders in %s mode', async (mode) => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent(mode)
|
2022-05-09 09:59:31 +00:00
|
|
|
|
2022-10-18 14:07:41 +00:00
|
|
|
if (mode === 'aside') {
|
2022-11-29 10:18:58 +00:00
|
|
|
screen.getByTestId('thumbnail')
|
2022-10-18 14:07:41 +00:00
|
|
|
} else {
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('thumbnail')).toBeNull()
|
2022-10-18 14:07:41 +00:00
|
|
|
}
|
2022-05-09 09:59:31 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.getByTestId('artist-info').classList.contains(mode)).toBe(true)
|
2022-07-10 13:50:41 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('triggers showing full bio for aside mode', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent('aside')
|
|
|
|
expect(screen.queryByTestId('full')).toBeNull()
|
2022-07-10 13:50:41 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Full Bio' }))
|
2022-07-10 13:50:41 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('summary')).toBeNull()
|
|
|
|
screen.getByTestId('full')
|
2022-07-10 13:50:41 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('shows full bio for full mode', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent('full')
|
2022-07-10 13:50:41 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
screen.getByTestId('full')
|
|
|
|
expect(screen.queryByTestId('summary')).toBeNull()
|
|
|
|
expect(screen.queryByRole('button', { name: 'Full Bio' })).toBeNull()
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
|
2022-07-10 13:50:41 +00:00
|
|
|
it('plays', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 3)
|
2022-07-10 13:50:41 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-05-09 09:59:31 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Play all songs by Led Zeppelin'))
|
2022-07-10 13:50:41 +00:00
|
|
|
await this.tick(2)
|
2022-05-09 09:59:31 +00:00
|
|
|
|
2022-07-10 13:50:41 +00:00
|
|
|
expect(fetchMock).toHaveBeenCalledWith(artist)
|
|
|
|
expect(playMock).toHaveBeenCalledWith(songs)
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|