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

49 lines
1.4 KiB
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
import { fireEvent } from '@testing-library/vue'
import factory from '@/__tests__/factory'
import { commonStore } from '@/stores'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import ExtraPanel from './ExtraPanel.vue'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
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()
}
}
})
}
protected test () {
it('has a YouTube tab if using YouTube ', () => {
2022-06-10 10:47:46 +00:00
commonStore.state.use_you_tube = true
const { getByTestId } = this.renderComponent()
getByTestId('extra-tab-youtube')
})
it('does not have a YouTube tab if not using YouTube', async () => {
2022-06-10 10:47:46 +00:00
commonStore.state.use_you_tube = false
const { queryByTestId } = this.renderComponent()
expect(await queryByTestId('extra-tab-youtube')).toBeNull()
})
it.each([['extra-tab-lyrics'], ['extra-tab-album'], ['extra-tab-artist']])('switches to "%s" tab', async (id) => {
const { getByTestId, container } = this.renderComponent()
await fireEvent.click(getByTestId(id))
expect(container.querySelector('[aria-selected=true]')).toBe(getByTestId(id))
})
}
}