2022-07-13 09:30:33 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { commonStore, queueStore } from '@/stores'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-13 09:30:33 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-07-13 09:49:46 +00:00
|
|
|
import QueueScreen from './QueueScreen.vue'
|
2022-07-13 09:30:33 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private renderComponent (songs: Song[]) {
|
|
|
|
queueStore.state.songs = songs
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(QueueScreen, {
|
2022-07-13 09:30:33 +00:00
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
SongList: this.stub('song-list')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders the queue', () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent(factory<Song>('song', 3))
|
2022-07-13 09:30:33 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('song-list')).toBeTruthy()
|
|
|
|
expect(screen.queryByTestId('screen-empty-state')).toBeNull()
|
2022-07-13 09:30:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders an empty state if no songs queued', () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent([])
|
2022-07-13 09:30:33 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('song-list')).toBeNull()
|
|
|
|
expect(screen.queryByTestId('screen-empty-state')).toBeTruthy()
|
2022-07-13 09:30:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('has an option to plays some random songs if the library is not empty', async () => {
|
|
|
|
commonStore.state.song_count = 300
|
|
|
|
const fetchRandomMock = this.mock(queueStore, 'fetchRandom')
|
|
|
|
const playMock = this.mock(playbackService, 'playFirstInQueue')
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent([])
|
|
|
|
await this.user.click(screen.getByText('playing some random songs'))
|
2022-07-13 09:30:33 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchRandomMock).toHaveBeenCalled()
|
|
|
|
expect(playMock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Shuffles all', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 3)
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent(songs)
|
2022-07-13 09:30:33 +00:00
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
|
2024-01-15 22:26:50 +00:00
|
|
|
await this.user.click(screen.getByTitle('Shuffle all. Press Alt/⌥ to change mode.'))
|
2022-07-13 09:30:33 +00:00
|
|
|
await waitFor(() => expect(playMock).toHaveBeenCalledWith(songs, true))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|