2022-10-13 15:18:47 +00:00
|
|
|
import { ref } from 'vue'
|
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2024-05-19 05:49:42 +00:00
|
|
|
import { CurrentPlayableKey } from '@/symbols'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2024-06-02 17:15:31 +00:00
|
|
|
import Component from './FooterPlaybackControls.vue'
|
2022-10-13 15:18:47 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
2024-04-23 21:01:27 +00:00
|
|
|
protected test () {
|
2024-06-02 17:15:31 +00:00
|
|
|
it('renders without a current playable', () => expect(this.renderComponent(null).html()).toMatchSnapshot())
|
|
|
|
it('renders with a current playable', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
it('plays the previous song', async () => {
|
|
|
|
const playMock = this.mock(playbackService, 'playPrev')
|
|
|
|
this.renderComponent()
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Play previous in queue' }))
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
expect(playMock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
it('plays the next playable', async () => {
|
2024-04-23 21:01:27 +00:00
|
|
|
const playMock = this.mock(playbackService, 'playNext')
|
|
|
|
this.renderComponent()
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Play next in queue' }))
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
expect(playMock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
private renderComponent (playable?: Playable | null) {
|
|
|
|
if (playable === undefined) {
|
|
|
|
playable = factory('song', {
|
2022-12-02 16:17:37 +00:00
|
|
|
id: '00000000-0000-0000-0000-000000000000',
|
2022-10-13 15:18:47 +00:00
|
|
|
title: 'Fahrstuhl to Heaven',
|
|
|
|
artist_name: 'Led Zeppelin',
|
|
|
|
artist_id: 3,
|
|
|
|
album_name: 'Led Zeppelin IV',
|
|
|
|
album_id: 4,
|
2024-10-13 17:37:01 +00:00
|
|
|
liked: true,
|
2022-10-13 15:18:47 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
return this.render(Component, {
|
2022-10-13 15:18:47 +00:00
|
|
|
global: {
|
|
|
|
stubs: {
|
2024-10-13 17:37:01 +00:00
|
|
|
PlayButton: this.stub('PlayButton'),
|
2022-10-13 15:18:47 +00:00
|
|
|
},
|
|
|
|
provide: {
|
2024-10-13 17:37:01 +00:00
|
|
|
[<symbol>CurrentPlayableKey]: ref(playable),
|
|
|
|
},
|
|
|
|
},
|
2022-10-13 15:18:47 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|