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-05-03 16:51:59 +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'
|
|
|
|
import { mediaInfoService } from '@/services'
|
2022-07-10 13:50:41 +00:00
|
|
|
import AlbumInfoComponent from './AlbumInfo.vue'
|
2022-07-10 09:31:55 +00:00
|
|
|
|
|
|
|
let album: Album
|
2022-05-03 16:51:59 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-07-10 09:31:55 +00:00
|
|
|
private async renderComponent (mode: MediaInfoDisplayMode = 'aside', info?: AlbumInfo) {
|
2024-01-04 11:35:36 +00:00
|
|
|
commonStore.state.uses_last_fm = true
|
2022-07-10 09:31:55 +00:00
|
|
|
|
|
|
|
if (info === undefined) {
|
|
|
|
info = factory<AlbumInfo>('album-info')
|
|
|
|
}
|
|
|
|
|
|
|
|
album = factory<Album>('album', { name: 'IV' })
|
|
|
|
const fetchMock = this.mock(mediaInfoService, 'fetchForAlbum').mockResolvedValue(info)
|
|
|
|
|
2022-07-10 13:50:41 +00:00
|
|
|
const rendered = this.render(AlbumInfoComponent, {
|
2022-07-10 09:31:55 +00:00
|
|
|
props: {
|
|
|
|
album,
|
|
|
|
mode
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
2022-10-18 14:07:41 +00:00
|
|
|
TrackList: this.stub(),
|
|
|
|
AlbumThumbnail: this.stub('thumbnail')
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
2022-07-10 09:31:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await this.tick(1)
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(album)
|
|
|
|
|
|
|
|
return rendered
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
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-03 16:51:59 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
screen.getByTestId('album-info-tracks')
|
2022-07-10 09:31:55 +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-11-29 10:18:58 +00:00
|
|
|
expect(screen.getByTestId('album-info').classList.contains(mode)).toBe(true)
|
2022-07-10 09:31:55 +00:00
|
|
|
})
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
|
|
|
}
|