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'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-11 09:12:26 +00:00
|
|
|
import LyricsPane from './LyricsPane.vue'
|
2022-07-21 10:45:23 +00:00
|
|
|
import Magnifier from '@/components/ui/Magnifier.vue'
|
2022-05-11 09:12:26 +00:00
|
|
|
|
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: {
|
2022-07-21 10:45:23 +00:00
|
|
|
Magnifier
|
2022-05-11 09:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-11-29 10:18:58 +00:00
|
|
|
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
2022-05-11 09:12:26 +00:00
|
|
|
|
|
|
|
it('provides a button to add lyrics if current user is admin', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
const song = factory<Song>('song', { lyrics: null })
|
2022-05-11 09:12:26 +00:00
|
|
|
|
|
|
|
const mock = this.mock(eventBus, 'emit')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.actingAsAdmin().renderComponent(song)
|
2022-05-11 09:12:26 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Click here' }))
|
2022-05-11 09:12:26 +00:00
|
|
|
|
|
|
|
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-11-29 10:18:58 +00:00
|
|
|
this.actingAs().renderComponent(factory<Song>('song', { lyrics: null }))
|
|
|
|
expect(screen.queryByRole('button', { name: 'Click here' })).toBeNull()
|
2022-05-11 09:12:26 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|