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 {
|
|
|
|
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))
|
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private renderComponent (songs: Song[]) {
|
2024-05-19 05:49:42 +00:00
|
|
|
queueStore.state.playables = songs
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
this.render(QueueScreen, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
SongList: this.stub('song-list')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-07-13 09:30:33 +00:00
|
|
|
}
|