2022-10-13 15:18:47 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { ref } from 'vue'
|
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { playbackService } from '@/services'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { CurrentSongKey } from '@/symbols'
|
|
|
|
import { commonStore, favoriteStore, queueStore, recentlyPlayedStore, songStore } from '@/stores'
|
|
|
|
import FooterPlayButton from './FooterPlayButton.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private renderComponent (currentSong: Song | null = null) {
|
|
|
|
return this.render(FooterPlayButton, {
|
|
|
|
global: {
|
|
|
|
provide: {
|
2022-10-27 13:33:32 +00:00
|
|
|
[<symbol>CurrentSongKey]: ref(currentSong)
|
2022-10-13 15:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('toggles the playback of current song', async () => {
|
|
|
|
const toggleMock = this.mock(playbackService, 'toggle')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent(factory<Song>('song'))
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button'))
|
2022-10-13 15:18:47 +00:00
|
|
|
|
|
|
|
expect(toggleMock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it.each<[ScreenName, MethodOf<typeof songStore>]>([
|
|
|
|
['Album', 'fetchForAlbum'],
|
|
|
|
['Artist', 'fetchForArtist'],
|
|
|
|
['Playlist', 'fetchForPlaylist']
|
2022-11-29 10:18:58 +00:00
|
|
|
])('initiates playback for %s screen', async (screenName, fetchMethod) => {
|
2022-10-13 15:18:47 +00:00
|
|
|
commonStore.state.song_count = 10
|
|
|
|
const songs = factory<Song>('song', 3)
|
|
|
|
const fetchMock = this.mock(songStore, fetchMethod).mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
const goMock = this.mock(this.router, 'go')
|
|
|
|
|
2022-10-27 13:33:32 +00:00
|
|
|
await this.router.activateRoute({
|
2022-11-29 10:18:58 +00:00
|
|
|
screen: screenName,
|
2022-10-13 15:18:47 +00:00
|
|
|
path: '_'
|
|
|
|
}, { id: '42' })
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button'))
|
2022-10-13 15:18:47 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(42)
|
|
|
|
expect(playMock).toHaveBeenCalledWith(songs)
|
|
|
|
expect(goMock).toHaveBeenCalledWith('queue')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-12-02 16:17:37 +00:00
|
|
|
it.each<[
|
|
|
|
ScreenName,
|
2023-08-20 22:35:58 +00:00
|
|
|
typeof favoriteStore | typeof recentlyPlayedStore,
|
2022-12-02 16:17:37 +00:00
|
|
|
MethodOf<typeof favoriteStore | typeof recentlyPlayedStore>
|
|
|
|
]>([
|
2022-10-13 15:18:47 +00:00
|
|
|
['Favorites', favoriteStore, 'fetch'],
|
|
|
|
['RecentlyPlayed', recentlyPlayedStore, 'fetch']
|
2022-11-29 10:18:58 +00:00
|
|
|
])('initiates playback for %s screen', async (screenName, store, fetchMethod) => {
|
2022-10-13 15:18:47 +00:00
|
|
|
commonStore.state.song_count = 10
|
|
|
|
const songs = factory<Song>('song', 3)
|
|
|
|
const fetchMock = this.mock(store, fetchMethod).mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
const goMock = this.mock(this.router, 'go')
|
|
|
|
|
2022-10-27 13:33:32 +00:00
|
|
|
await this.router.activateRoute({
|
2022-11-29 10:18:58 +00:00
|
|
|
screen: screenName,
|
2022-10-13 15:18:47 +00:00
|
|
|
path: '_'
|
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button'))
|
2022-10-13 15:18:47 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchMock).toHaveBeenCalled()
|
|
|
|
expect(playMock).toHaveBeenCalledWith(songs)
|
|
|
|
expect(goMock).toHaveBeenCalledWith('queue')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
it.each<[ScreenName]>([['Queue'], ['Songs'], ['Albums']])('initiates playback %s screen', async screenName => {
|
2022-10-13 15:18:47 +00:00
|
|
|
commonStore.state.song_count = 10
|
|
|
|
const songs = factory<Song>('song', 3)
|
|
|
|
const fetchMock = this.mock(queueStore, 'fetchRandom').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
const goMock = this.mock(this.router, 'go')
|
|
|
|
|
2022-10-27 13:33:32 +00:00
|
|
|
await this.router.activateRoute({
|
2022-11-29 10:18:58 +00:00
|
|
|
screen: screenName,
|
2022-10-13 15:18:47 +00:00
|
|
|
path: '_'
|
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button'))
|
2022-10-13 15:18:47 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchMock).toHaveBeenCalled()
|
|
|
|
expect(playMock).toHaveBeenCalledWith(songs)
|
|
|
|
expect(goMock).toHaveBeenCalledWith('queue')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does nothing if there are no songs', async () => {
|
|
|
|
commonStore.state.song_count = 0
|
|
|
|
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
const goMock = this.mock(this.router, 'go')
|
|
|
|
|
2022-10-27 13:33:32 +00:00
|
|
|
await this.router.activateRoute({
|
2022-10-13 15:18:47 +00:00
|
|
|
screen: 'Songs',
|
|
|
|
path: '_'
|
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-10-13 15:18:47 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button'))
|
2022-10-13 15:18:47 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(playMock).not.toHaveBeenCalled()
|
|
|
|
expect(goMock).not.toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|