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'
|
2024-04-22 21:04:03 +00:00
|
|
|
import { commonStore } from '@/stores'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2024-04-22 21:04:03 +00:00
|
|
|
import { mediaInfoService } 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 {
|
2024-04-23 21:01:27 +00:00
|
|
|
protected test () {
|
|
|
|
it.each<[MediaInfoDisplayMode]>([['aside'], ['full']])('renders in %s mode', async (mode) => {
|
|
|
|
await this.renderComponent(mode)
|
|
|
|
|
|
|
|
if (mode === 'aside') {
|
|
|
|
screen.getByTestId('thumbnail')
|
|
|
|
} else {
|
|
|
|
expect(screen.queryByTestId('thumbnail')).toBeNull()
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(screen.getByTestId('artist-info').classList.contains(mode)).toBe(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-10 13:50:41 +00:00
|
|
|
private async renderComponent (mode: MediaInfoDisplayMode = 'aside', info?: ArtistInfo) {
|
2024-01-04 11:35:36 +00:00
|
|
|
commonStore.state.uses_last_fm = true
|
2024-06-01 18:02:27 +00:00
|
|
|
info = info ?? factory('artist-info')
|
|
|
|
artist = factory('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
|
|
|
}
|