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'
|
2024-06-02 17:15:31 +00:00
|
|
|
import Component from './SongThumbnail.vue'
|
2022-10-26 12:34:32 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
let playable: Playable
|
2022-10-26 12:34:32 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
2024-06-02 17:15:31 +00:00
|
|
|
it.each<[PlaybackState, MethodOf<typeof playbackService>]>([
|
|
|
|
['Stopped', 'play'],
|
|
|
|
['Playing', 'pause'],
|
|
|
|
['Paused', 'resume']
|
|
|
|
])('if state is currently "%s", %ss', async (state, 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
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
await this.user.click(screen.getByRole('button'))
|
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-02 17:15:31 +00:00
|
|
|
playable = factory('song', {
|
2024-04-23 21:01:27 +00:00
|
|
|
playback_state: playbackState,
|
|
|
|
play_count: 10,
|
|
|
|
title: 'Foo bar'
|
|
|
|
})
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
return this.render(Component, {
|
2024-04-23 21:01:27 +00:00
|
|
|
props: {
|
2024-06-02 17:15:31 +00:00
|
|
|
playable
|
2024-04-23 21:01:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-10-26 12:34:32 +00:00
|
|
|
}
|