koel/resources/assets/js/components/layout/main-wrapper/ExtraPanel.spec.ts

92 lines
3.1 KiB
TypeScript
Raw Normal View History

2022-10-13 15:18:47 +00:00
import { ref, Ref } from 'vue'
import { expect, it } from 'vitest'
import { screen, waitFor } from '@testing-library/vue'
import factory from '@/__tests__/factory'
import { albumStore, artistStore, commonStore, preferenceStore } 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'
import { eventBus } from '@/utils'
import ExtraPanel from './ExtraPanel.vue'
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)) {
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: {
[<symbol>CurrentSongKey]: songRef
}
}
})
}
protected test () {
2022-10-13 15:18:47 +00:00
it('renders without a current song', () => expect(this.renderComponent().html()).toMatchSnapshot())
it('sets the active tab to the preference', async () => {
preferenceStore.activeExtraPanelTab = 'YouTube'
this.renderComponent(ref(factory<Song>('song')))
const tab = screen.getByTestId<HTMLElement>('extra-panel-youtube')
expect(tab.style.display).toBe('none')
await this.tick()
expect(tab.style.display).toBe('')
})
2022-10-13 15:18:47 +00:00
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)
this.renderComponent(songRef)
2022-10-13 15:18:47 +00:00
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 => screen.getByTestId(id))
2022-10-13 15:18:47 +00:00
})
})
2022-10-13 15:18:47 +00:00
it('shows About Koel model', async () => {
const emitMock = this.mock(eventBus, 'emit')
this.renderComponent()
2022-10-13 15:18:47 +00:00
await this.user.click(screen.getByRole('button', { name: 'About Koel' }))
2022-10-13 15:18:47 +00:00
expect(emitMock).toHaveBeenCalledWith('MODAL_SHOW_ABOUT_KOEL')
})
it('notifies new version', async () => {
it('shows new version', () => {
commonStore.state.current_version = 'v1.0.0'
commonStore.state.latest_version = 'v1.0.1'
this.actingAsAdmin().renderComponent().getByRole('button', { name: 'New version available!' })
})
})
2022-10-13 15:18:47 +00:00
it('logs out', async () => {
const emitMock = this.mock(eventBus, 'emit')
this.renderComponent()
await this.user.click(screen.getByRole('button', { name: 'Log out' }))
2022-10-13 15:18:47 +00:00
expect(emitMock).toHaveBeenCalledWith('LOG_OUT')
})
}
}