2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
2022-05-06 15:52:37 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { commonStore } from '@/stores'
|
|
|
|
import { songInfoService } from '@/services'
|
|
|
|
import { eventBus } from '@/utils'
|
2022-05-09 09:59:31 +00:00
|
|
|
import ComponentTestCase from '@/__tests__/ComponentTestCase'
|
2022-05-06 10:28:02 +00:00
|
|
|
import ExtraPanel from './ExtraPanel.vue'
|
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
new class extends ComponentTestCase {
|
|
|
|
private renderComponent () {
|
|
|
|
return this.render(ExtraPanel, {
|
|
|
|
props: {
|
|
|
|
song: factory<Song>('song')
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
LyricsPane: this.stub(),
|
|
|
|
AlbumInfo: this.stub(),
|
|
|
|
ArtistInfo: this.stub(),
|
|
|
|
YouTubeVideoList: this.stub()
|
|
|
|
}
|
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 () {
|
|
|
|
it('has a YouTube tab if using YouTube ', () => {
|
|
|
|
commonStore.state.useYouTube = true
|
|
|
|
const { getByTestId } = this.renderComponent()
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
getByTestId('extra-tab-youtube')
|
|
|
|
})
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('does not have a YouTube tab if not using YouTube', async () => {
|
|
|
|
commonStore.state.useYouTube = false
|
|
|
|
const { queryByTestId } = this.renderComponent()
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(await queryByTestId('extra-tab-youtube')).toBeNull()
|
|
|
|
})
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it.each([['extra-tab-lyrics'], ['extra-tab-album'], ['extra-tab-artist']])('switches to "%s" tab', async (id) => {
|
|
|
|
const { getByTestId, container } = this.renderComponent()
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
await fireEvent.click(getByTestId(id))
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(container.querySelector('[aria-selected=true]')).toBe(getByTestId(id))
|
|
|
|
})
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('fetches song info when a new song is played', () => {
|
|
|
|
this.renderComponent()
|
|
|
|
const song = factory<Song>('song')
|
|
|
|
const mock = this.mock(songInfoService, 'fetch', song)
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
eventBus.emit('SONG_STARTED', song)
|
2022-05-06 10:28:02 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith(song)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|