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'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
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-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-05-09 15:09:55 +00:00
|
|
|
private renderComponent (selectedSongCount = 1, config: Partial<SongListControlsConfig> = {}) {
|
2022-07-21 08:43:57 +00:00
|
|
|
const songs = factory<Song[]>('song', 5)
|
2022-05-09 15:09:55 +00:00
|
|
|
|
|
|
|
return this.render(SongListControls, {
|
|
|
|
props: {
|
2022-07-21 08:43:57 +00:00
|
|
|
config
|
2022-05-09 15:09:55 +00:00
|
|
|
},
|
|
|
|
global: {
|
2022-07-21 08:43:57 +00:00
|
|
|
provide: {
|
|
|
|
[SongsKey]: [ref(songs)],
|
|
|
|
[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) => {
|
|
|
|
const { emitted, getByTitle } = this.renderComponent(selectedCount)
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Shuffle all songs'))
|
|
|
|
|
|
|
|
expect(emitted().playAll[0]).toEqual([true])
|
|
|
|
})
|
|
|
|
|
|
|
|
it.each([[0], [1]])('plays all if %s songs are selected with Alt pressed', async (selectedCount: number) => {
|
|
|
|
const { emitted, getByTitle } = this.renderComponent(selectedCount)
|
|
|
|
|
|
|
|
await fireEvent.keyDown(window, { key: 'Alt' })
|
|
|
|
await fireEvent.click(getByTitle('Play all songs'))
|
|
|
|
|
|
|
|
expect(emitted().playAll[0]).toEqual([false])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles selected if more than one song are selected', async () => {
|
|
|
|
const { emitted, getByTitle } = this.renderComponent(2)
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Shuffle selected songs'))
|
|
|
|
|
|
|
|
expect(emitted().playSelected[0]).toEqual([true])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('plays selected if more than one song are selected with Alt pressed', async () => {
|
|
|
|
const { emitted, getByTitle } = this.renderComponent(2)
|
|
|
|
|
|
|
|
await fireEvent.keyDown(window, { key: 'Alt' })
|
|
|
|
await fireEvent.click(getByTitle('Play selected songs'))
|
|
|
|
|
|
|
|
expect(emitted().playSelected[0]).toEqual([false])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('toggles Add To menu', async () => {
|
|
|
|
const { getByTitle, getByTestId } = this.renderComponent()
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Add selected songs to…'))
|
|
|
|
expect(getByTestId('add-to-menu').style.display).toBe('')
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Cancel'))
|
|
|
|
expect(getByTestId('add-to-menu').style.display).toBe('none')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('clears queue', async () => {
|
|
|
|
const { emitted, getByTitle } = this.renderComponent(0, { clearQueue: true })
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Clear current queue'))
|
|
|
|
|
|
|
|
expect(emitted().clearQueue).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('deletes current playlist', async () => {
|
|
|
|
const { emitted, getByTitle } = this.renderComponent(0, { deletePlaylist: true })
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Delete this playlist'))
|
|
|
|
|
|
|
|
expect(emitted().deletePlaylist).toBeTruthy()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|