2022-10-13 15:18:47 +00:00
|
|
|
import { ref, Ref } from 'vue'
|
2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { fireEvent, waitFor } from '@testing-library/vue'
|
2022-05-06 15:52:37 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { albumStore, artistStore, commonStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { CurrentSongKey } from '@/symbols'
|
2022-05-06 10:28:02 +00:00
|
|
|
import ExtraPanel from './ExtraPanel.vue'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { eventBus } from '@/utils'
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-10-13 15:18:47 +00:00
|
|
|
private renderComponent (songRef: Ref<Song | null> = ref(null)) {
|
2022-05-09 09:59:31 +00:00
|
|
|
return this.render(ExtraPanel, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
2022-10-13 15:18:47 +00:00
|
|
|
ProfileAvatar: this.stub(),
|
|
|
|
LyricsPane: this.stub('lyrics'),
|
|
|
|
AlbumInfo: this.stub('album-info'),
|
|
|
|
ArtistInfo: this.stub('artist-info'),
|
|
|
|
YouTubeVideoList: this.stub('youtube-video-list'),
|
|
|
|
ExtraPanelTabHeader: this.stub()
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
[CurrentSongKey]: songRef
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
2022-05-06 10:28:02 +00:00
|
|
|
}
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
2022-10-13 15:18:47 +00:00
|
|
|
it('renders without a current song', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
|
|
|
|
|
|
|
it('fetches info for the current song', async () => {
|
2022-06-10 10:47:46 +00:00
|
|
|
commonStore.state.use_you_tube = true
|
2022-10-13 15:18:47 +00:00
|
|
|
const artist = factory<Artist>('artist')
|
|
|
|
const resolveArtistMock = this.mock(artistStore, 'resolve').mockResolvedValue(artist)
|
|
|
|
|
|
|
|
const album = factory<Album>('album')
|
|
|
|
const resolveAlbumMock = this.mock(albumStore, 'resolve').mockResolvedValue(album)
|
|
|
|
|
|
|
|
const song = factory<Song>('song')
|
|
|
|
|
|
|
|
const songRef = ref<Song | null>(null)
|
|
|
|
|
|
|
|
const { getByTestId } = this.renderComponent(songRef)
|
|
|
|
songRef.value = song
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(resolveArtistMock).toHaveBeenCalledWith(song.artist_id)
|
|
|
|
expect(resolveAlbumMock).toHaveBeenCalledWith(song.album_id)
|
|
|
|
;['lyrics', 'album-info', 'artist-info', 'youtube-video-list'].forEach(id => getByTestId(id))
|
|
|
|
})
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
it('shows About Koel model', async () => {
|
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
|
|
|
const { getByTitle } = this.renderComponent()
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('About Koel'))
|
|
|
|
|
|
|
|
expect(emitMock).toHaveBeenCalledWith('MODAL_SHOW_ABOUT_KOEL')
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
it('logs out', async () => {
|
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
|
|
|
const { getByTitle } = this.renderComponent()
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
await fireEvent.click(getByTitle('Log out'))
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
expect(emitMock).toHaveBeenCalledWith('LOG_OUT')
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|