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'
|
2022-07-10 09:31:55 +00:00
|
|
|
import { commonStore, songStore } from '@/stores'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
2022-10-08 10:54:25 +00:00
|
|
|
import { playbackService, 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) {
|
|
|
|
commonStore.state.use_last_fm = true
|
|
|
|
|
|
|
|
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-07-13 09:49:46 +00:00
|
|
|
TrackList: this.stub()
|
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) => {
|
|
|
|
const { getByTestId } = await this.renderComponent(mode)
|
2022-05-03 16:51:59 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
getByTestId('album-artist-thumbnail')
|
2022-07-10 09:31:55 +00:00
|
|
|
getByTestId('album-info-tracks')
|
|
|
|
|
|
|
|
expect(getByTestId('album-info').classList.contains(mode)).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('triggers showing full wiki for aside mode', async () => {
|
2022-09-14 16:45:08 +00:00
|
|
|
const { getByTestId, queryByTestId } = await this.renderComponent('aside')
|
2022-07-10 09:31:55 +00:00
|
|
|
expect(queryByTestId('full')).toBeNull()
|
|
|
|
|
2022-09-14 16:45:08 +00:00
|
|
|
await fireEvent.click(getByTestId('more-btn'))
|
2022-05-03 16:51:59 +00:00
|
|
|
|
2022-07-10 09:31:55 +00:00
|
|
|
expect(queryByTestId('summary')).toBeNull()
|
|
|
|
expect(queryByTestId('full')).not.toBeNull()
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
2022-05-03 16:51:59 +00:00
|
|
|
|
2022-07-10 09:31:55 +00:00
|
|
|
it('shows full wiki for full mode', async () => {
|
|
|
|
const { queryByTestId } = await this.renderComponent('full')
|
|
|
|
|
|
|
|
expect(queryByTestId('full')).not.toBeNull()
|
|
|
|
expect(queryByTestId('summary')).toBeNull()
|
|
|
|
expect(queryByTestId('more-btn')).toBeNull()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('plays', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 3)
|
2022-07-10 09:31:55 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
const { getByTitle } = await this.renderComponent()
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Play all songs in IV'))
|
|
|
|
await this.tick(2)
|
|
|
|
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(album)
|
|
|
|
expect(playMock).toHaveBeenCalledWith(songs)
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|