2022-05-09 15:09:55 +00:00
|
|
|
import { take } from 'lodash'
|
2022-07-21 08:43:57 +00:00
|
|
|
import { ref } from 'vue'
|
2022-05-09 15:09:55 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-07-21 08:43:57 +00:00
|
|
|
import { SelectedSongsKey, SongsKey } from '@/symbols'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-09 15:09:55 +00:00
|
|
|
import SongListControls from './SongListControls.vue'
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-12-06 10:28:48 +00:00
|
|
|
private renderComponent (selectedSongCount = 1, screen: ScreenName = 'Songs') {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 5)
|
2022-05-09 15:09:55 +00:00
|
|
|
|
2022-12-06 10:28:48 +00:00
|
|
|
this.router.activateRoute({
|
|
|
|
screen,
|
2023-08-20 22:35:58 +00:00
|
|
|
path: '_'
|
2022-12-06 10:28:48 +00:00
|
|
|
})
|
|
|
|
|
2022-05-09 15:09:55 +00:00
|
|
|
return this.render(SongListControls, {
|
|
|
|
global: {
|
2022-07-21 08:43:57 +00:00
|
|
|
provide: {
|
2022-09-12 11:11:56 +00:00
|
|
|
[<symbol>SongsKey]: [ref(songs)],
|
|
|
|
[<symbol>SelectedSongsKey]: [ref(take(songs, selectedSongCount))]
|
2022-05-09 15:09:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it.each([[0], [1]])('shuffles all if %s songs are selected', async (selectedCount: number) => {
|
2022-11-29 10:18:58 +00:00
|
|
|
const { emitted } = this.renderComponent(selectedCount)
|
2022-05-09 15:09:55 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Shuffle all songs'))
|
2022-05-09 15:09:55 +00:00
|
|
|
|
|
|
|
expect(emitted().playAll[0]).toEqual([true])
|
|
|
|
})
|
|
|
|
|
|
|
|
it.each([[0], [1]])('plays all if %s songs are selected with Alt pressed', async (selectedCount: number) => {
|
2022-11-29 10:18:58 +00:00
|
|
|
const { emitted } = this.renderComponent(selectedCount)
|
2022-05-09 15:09:55 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.keyboard('{Alt>}')
|
|
|
|
await this.user.click(screen.getByTitle('Play all songs'))
|
|
|
|
await this.user.keyboard('{/Alt}')
|
2022-05-09 15:09:55 +00:00
|
|
|
|
|
|
|
expect(emitted().playAll[0]).toEqual([false])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles selected if more than one song are selected', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
const { emitted } = this.renderComponent(2)
|
2022-05-09 15:09:55 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Shuffle selected songs'))
|
2022-05-09 15:09:55 +00:00
|
|
|
|
|
|
|
expect(emitted().playSelected[0]).toEqual([true])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('plays selected if more than one song are selected with Alt pressed', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
const { emitted } = this.renderComponent(2)
|
2022-05-09 15:09:55 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.keyboard('{Alt>}')
|
|
|
|
await this.user.click(screen.getByTitle('Play selected songs'))
|
|
|
|
await this.user.keyboard('{/Alt}')
|
2022-05-09 15:09:55 +00:00
|
|
|
|
|
|
|
expect(emitted().playSelected[0]).toEqual([false])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('clears queue', async () => {
|
2022-12-06 10:28:48 +00:00
|
|
|
const { emitted } = this.renderComponent(0, 'Queue')
|
2022-05-09 15:09:55 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Clear current queue'))
|
2022-05-09 15:09:55 +00:00
|
|
|
|
|
|
|
expect(emitted().clearQueue).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('deletes current playlist', async () => {
|
2022-12-06 10:28:48 +00:00
|
|
|
const { emitted } = this.renderComponent(0, 'Playlist')
|
2022-05-09 15:09:55 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Delete this playlist'))
|
2022-05-09 15:09:55 +00:00
|
|
|
|
|
|
|
expect(emitted().deletePlaylist).toBeTruthy()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|