2024-01-18 11:13:05 +00:00
|
|
|
import Router from '@/router'
|
2022-07-11 17:03:38 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { commonStore, queueStore, songStore } from '@/stores'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-11 17:03:38 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-07-13 09:49:46 +00:00
|
|
|
import AllSongsScreen from './AllSongsScreen.vue'
|
2022-07-11 17:03:38 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
2024-03-18 22:04:01 +00:00
|
|
|
protected beforeEach (cb?: Closure) {
|
|
|
|
super.beforeEach(cb)
|
2022-07-11 17:03:38 +00:00
|
|
|
commonStore.state.song_count = 420
|
|
|
|
commonStore.state.song_length = 123_456
|
2024-06-01 18:02:27 +00:00
|
|
|
songStore.state.songs = factory('song', 20)
|
2024-03-18 22:04:01 +00:00
|
|
|
this.be()
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:03:38 +00:00
|
|
|
protected test () {
|
|
|
|
it('renders', async () => {
|
2024-01-15 22:26:50 +00:00
|
|
|
const [{ html }] = await this.renderComponent()
|
2022-07-11 17:03:38 +00:00
|
|
|
await waitFor(() => expect(html()).toMatchSnapshot())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles', async () => {
|
|
|
|
const queueMock = this.mock(queueStore, 'fetchRandom')
|
|
|
|
const playMock = this.mock(playbackService, 'playFirstInQueue')
|
2024-01-18 11:13:05 +00:00
|
|
|
const goMock = this.mock(Router, 'go')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-11 17:03:38 +00:00
|
|
|
|
2024-01-15 22:26:50 +00:00
|
|
|
await this.user.click(screen.getByTitle('Shuffle all. Press Alt/⌥ to change mode.'))
|
2022-07-11 17:03:38 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(queueMock).toHaveBeenCalled()
|
|
|
|
expect(playMock).toHaveBeenCalled()
|
|
|
|
expect(goMock).toHaveBeenCalledWith('queue')
|
|
|
|
})
|
|
|
|
})
|
2024-01-15 22:26:50 +00:00
|
|
|
|
|
|
|
it('renders in Plus edition', async () => {
|
|
|
|
this.enablePlusEdition()
|
|
|
|
|
|
|
|
const [{ html }, fetchMock] = await this.renderComponent()
|
|
|
|
await waitFor(() => expect(html()).toMatchSnapshot())
|
|
|
|
|
|
|
|
await this.user.click(screen.getByLabelText('Own songs only'))
|
|
|
|
await waitFor(() => expect(fetchMock).toHaveBeenCalledWith({
|
|
|
|
sort: 'title',
|
|
|
|
order: 'asc',
|
|
|
|
page: 1,
|
|
|
|
own_songs_only: true
|
|
|
|
}))
|
|
|
|
})
|
2022-07-11 17:03:38 +00:00
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private async renderComponent () {
|
|
|
|
const fetchMock = this.mock(songStore, 'paginate').mockResolvedValue(2)
|
|
|
|
|
|
|
|
this.router.$currentRoute.value = {
|
|
|
|
screen: 'Songs',
|
|
|
|
path: '/songs'
|
|
|
|
}
|
|
|
|
|
|
|
|
const rendered = this.render(AllSongsScreen, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
SongList: this.stub('song-list')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitFor(() => expect(fetchMock).toHaveBeenCalledWith({
|
|
|
|
sort: 'title',
|
|
|
|
order: 'asc',
|
|
|
|
page: 1,
|
|
|
|
own_songs_only: false
|
|
|
|
}))
|
|
|
|
|
|
|
|
return [rendered, fetchMock] as const
|
|
|
|
}
|
2022-07-11 17:03:38 +00:00
|
|
|
}
|