2022-05-11 09:12:26 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-11 09:12:26 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
|
|
|
import LyricsPane from './LyricsPane.vue'
|
|
|
|
import TextMagnifier from '@/components/ui/TextMagnifier.vue'
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-11 09:12:26 +00:00
|
|
|
private renderComponent (song?: Song) {
|
|
|
|
song = song || factory<Song>('song', {
|
|
|
|
lyrics: 'Foo bar baz qux'
|
|
|
|
})
|
|
|
|
|
|
|
|
return this.render(LyricsPane, {
|
|
|
|
props: {
|
|
|
|
song
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
TextMagnifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => {
|
|
|
|
expect(this.renderComponent().html()).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('provides a button to add lyrics if current user is admin', async () => {
|
|
|
|
const song = factory<Song>('song', {
|
|
|
|
lyrics: null
|
|
|
|
})
|
|
|
|
|
|
|
|
const mock = this.mock(eventBus, 'emit')
|
|
|
|
const { getByTestId } = this.actingAsAdmin().renderComponent(song)
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('add-lyrics-btn'))
|
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('MODAL_SHOW_EDIT_SONG_FORM', song, 'lyrics')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not have a button to add lyrics if current user is not an admin', async () => {
|
2022-07-19 08:19:57 +00:00
|
|
|
const { queryByTestId } = this.actingAs().renderComponent(factory<Song>('song', {
|
2022-05-11 09:12:26 +00:00
|
|
|
lyrics: null
|
|
|
|
}))
|
|
|
|
|
|
|
|
expect(await queryByTestId('add-lyrics-btn')).toBeNull()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|