2022-10-26 12:34:32 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { playbackService } from '@/services'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2024-01-01 11:40:21 +00:00
|
|
|
import { queueStore } from '@/stores'
|
|
|
|
import SongThumbnail from '@/components/song/SongThumbnail.vue'
|
2022-10-26 12:34:32 +00:00
|
|
|
|
|
|
|
let song: Song
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
2022-11-29 10:18:58 +00:00
|
|
|
it.each<[PlaybackState, string, MethodOf<typeof playbackService>]>([
|
|
|
|
['Stopped', 'Play', 'play'],
|
|
|
|
['Playing', 'Pause', 'pause'],
|
|
|
|
['Paused', 'Resume', 'resume']
|
|
|
|
])('if state is currently "%s", %ss', async (state, name, method) => {
|
2024-01-01 11:40:21 +00:00
|
|
|
this.mock(queueStore, 'queueIfNotQueued')
|
|
|
|
const playbackMock = this.mock(playbackService, method)
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent(state)
|
2022-10-26 12:34:32 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name }))
|
2022-10-26 12:34:32 +00:00
|
|
|
|
2024-01-01 11:40:21 +00:00
|
|
|
expect(playbackMock).toHaveBeenCalled()
|
2022-10-26 12:34:32 +00:00
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private renderComponent (playbackState: PlaybackState = 'Stopped') {
|
2024-06-01 18:02:27 +00:00
|
|
|
song = factory('song', {
|
2024-04-23 21:01:27 +00:00
|
|
|
playback_state: playbackState,
|
|
|
|
play_count: 10,
|
|
|
|
title: 'Foo bar'
|
|
|
|
})
|
|
|
|
|
|
|
|
return this.render(SongThumbnail, {
|
|
|
|
props: {
|
|
|
|
song
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-10-26 12:34:32 +00:00
|
|
|
}
|