2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
2022-05-05 15:30:10 +00:00
|
|
|
import { playbackService } from '@/services'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-05 15:30:10 +00:00
|
|
|
import FooterPlayerControls from './FooterPlayerControls.vue'
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
2022-05-09 12:25:19 +00:00
|
|
|
it.each<[string, string, MethodOf<typeof playbackService>]>([
|
2022-05-09 09:59:31 +00:00
|
|
|
['plays next song', 'Play next song', 'playNext'],
|
|
|
|
['plays previous song', 'Play previous song', 'playPrev'],
|
|
|
|
['plays/resumes current song', 'Play or resume', 'toggle']
|
2022-05-09 12:25:19 +00:00
|
|
|
])('%s', async (_: string, title: string, playbackMethod: MethodOf<typeof playbackService>) => {
|
|
|
|
const mock = this.mock(playbackService, playbackMethod)
|
2022-05-09 09:59:31 +00:00
|
|
|
|
|
|
|
const { getByTitle } = this.render(FooterPlayerControls, {
|
|
|
|
props: {
|
|
|
|
song: factory<Song>('song')
|
|
|
|
}
|
|
|
|
})
|
2022-05-05 15:30:10 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
await fireEvent.click(getByTitle(title))
|
|
|
|
expect(mock).toHaveBeenCalled()
|
|
|
|
})
|
2022-05-05 15:30:10 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('pauses the current song', async () => {
|
|
|
|
const mock = this.mock(playbackService, 'toggle')
|
2022-05-05 15:30:10 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
const { getByTitle } = this.render(FooterPlayerControls, {
|
|
|
|
props: {
|
|
|
|
song: factory<Song>('song', {
|
|
|
|
playbackState: 'Playing'
|
|
|
|
})
|
|
|
|
}
|
2022-05-05 15:30:10 +00:00
|
|
|
})
|
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
await fireEvent.click(getByTitle('Pause'))
|
|
|
|
expect(mock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|