2022-10-13 15:18:47 +00:00
|
|
|
import { ref, Ref } from 'vue'
|
2024-01-01 11:40:21 +00:00
|
|
|
import { expect, it, Mock } from 'vitest'
|
|
|
|
import { RenderResult, screen, waitFor } from '@testing-library/vue'
|
2022-05-06 15:52:37 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
2022-11-20 14:05:53 +00:00
|
|
|
import { albumStore, artistStore, commonStore, preferenceStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2024-05-19 05:49:42 +00:00
|
|
|
import { CurrentPlayableKey } from '@/symbols'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { eventBus } from '@/utils'
|
2022-12-15 16:31:52 +00:00
|
|
|
import ExtraDrawer from './ExtraDrawer.vue'
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
2024-01-01 11:40:21 +00:00
|
|
|
it('renders without a current song', () => expect(this.renderComponent()[0].html()).toMatchSnapshot())
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-20 14:05:53 +00:00
|
|
|
it('sets the active tab to the preference', async () => {
|
2024-01-23 22:50:50 +00:00
|
|
|
preferenceStore.active_extra_panel_tab = 'YouTube'
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent(ref(factory<Song>('song')))
|
2022-12-15 16:31:52 +00:00
|
|
|
const tab = screen.getByTestId<HTMLElement>('extra-drawer-youtube')
|
2022-11-20 14:05:53 +00:00
|
|
|
|
|
|
|
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 () => {
|
2024-01-04 11:35:36 +00:00
|
|
|
commonStore.state.uses_you_tube = true
|
2022-10-13 15:18:47 +00:00
|
|
|
|
|
|
|
const song = factory<Song>('song')
|
|
|
|
const songRef = ref<Song | null>(null)
|
|
|
|
|
2024-01-01 11:40:21 +00:00
|
|
|
const [, resolveArtistMock, resolveAlbumMock] = 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)
|
2022-11-29 10:18:58 +00:00
|
|
|
;['lyrics', 'album-info', 'artist-info', 'youtube-video-list'].forEach(id => screen.getByTestId(id))
|
2022-10-13 15:18:47 +00:00
|
|
|
})
|
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')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-29 10:18:58 +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')
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-10-26 20:44:44 +00:00
|
|
|
it('notifies new version', async () => {
|
|
|
|
it('shows new version', () => {
|
|
|
|
commonStore.state.current_version = 'v1.0.0'
|
|
|
|
commonStore.state.latest_version = 'v1.0.1'
|
2024-01-15 22:26:50 +00:00
|
|
|
this.beAdmin().renderComponent()[0].getByRole('button', { name: 'New version available!' })
|
2022-10-26 20:44:44 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
it('logs out', async () => {
|
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: '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
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private renderComponent (songRef: Ref<Song | null> = ref(null)): [RenderResult, Mock, Mock] {
|
|
|
|
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 rendered = this.render(ExtraDrawer, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
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: {
|
2024-05-19 05:49:42 +00:00
|
|
|
[<symbol>CurrentPlayableKey]: songRef
|
2024-04-23 21:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return [rendered, resolveArtistMock, resolveAlbumMock]
|
|
|
|
}
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|