2022-09-12 15:33:41 +00:00
|
|
|
import { ref } from 'vue'
|
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'
|
|
|
|
import { fireEvent, waitFor } from '@testing-library/vue'
|
|
|
|
import { playbackService } from '@/services'
|
|
|
|
import router from '@/router'
|
2022-09-12 15:33:41 +00:00
|
|
|
import { ActiveScreenKey } from '@/symbols'
|
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 {
|
|
|
|
private async renderComponent () {
|
|
|
|
commonStore.state.song_count = 420
|
|
|
|
commonStore.state.song_length = 123_456
|
2022-09-12 11:11:56 +00:00
|
|
|
songStore.state.songs = factory<Song>('song', 20)
|
2022-07-24 11:47:18 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'paginate').mockResolvedValue(2)
|
2022-07-11 17:03:38 +00:00
|
|
|
|
|
|
|
const rendered = this.render(AllSongsScreen, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
SongList: this.stub('song-list')
|
2022-09-12 15:33:41 +00:00
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
[<symbol>ActiveScreenKey]: ref('Songs')
|
2022-07-11 17:03:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await waitFor(() => expect(fetchMock).toHaveBeenCalledWith('title', 'asc', 1))
|
|
|
|
return rendered
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', async () => {
|
|
|
|
const { html } = await this.renderComponent()
|
|
|
|
await waitFor(() => expect(html()).toMatchSnapshot())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles', async () => {
|
|
|
|
const queueMock = this.mock(queueStore, 'fetchRandom')
|
|
|
|
const playMock = this.mock(playbackService, 'playFirstInQueue')
|
|
|
|
const goMock = this.mock(router, 'go')
|
|
|
|
const { getByTitle } = await this.renderComponent()
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Shuffle all songs'))
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(queueMock).toHaveBeenCalled()
|
|
|
|
expect(playMock).toHaveBeenCalled()
|
|
|
|
expect(goMock).toHaveBeenCalledWith('queue')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|