koel/resources/assets/js/components/song/SongListControls.spec.ts

91 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-01-18 11:13:05 +00:00
import { merge, take } from 'lodash'
2022-07-21 08:43:57 +00:00
import { ref } from 'vue'
import { expect, it } from 'vitest'
import factory from '@/__tests__/factory'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
2024-06-03 07:16:29 +00:00
import { PlayablesKey, SelectedPlayablesKey } from '@/symbols'
import { screen } from '@testing-library/vue'
import SongListControls from './SongListControls.vue'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
it.each([[0], [1]])('shuffles all if %s songs are selected', async (selectedCount: number) => {
const { emitted } = this.renderComponent(selectedCount)
await this.user.click(screen.getByTitle('Shuffle all. Press Alt/⌥ to change mode.'))
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 } = this.renderComponent(selectedCount)
await this.user.keyboard('{Alt>}')
await this.user.click(screen.getByTitle('Play all. Press Alt/⌥ to change mode.'))
await this.user.keyboard('{/Alt}')
expect(emitted().playAll[0]).toEqual([false])
})
it('shuffles selected if more than one song are selected', async () => {
const { emitted } = this.renderComponent(2)
await this.user.click(screen.getByTitle('Shuffle selected. Press Alt/⌥ to change mode.'))
expect(emitted().playSelected[0]).toEqual([true])
})
it('plays selected if more than one song are selected with Alt pressed', async () => {
const { emitted } = this.renderComponent(2)
await this.user.keyboard('{Alt>}')
await this.user.click(screen.getByTitle('Play selected. Press Alt/⌥ to change mode.'))
await this.user.keyboard('{/Alt}')
expect(emitted().playSelected[0]).toEqual([false])
})
it('clears queue', async () => {
2024-01-18 11:13:05 +00:00
const { emitted } = this.renderComponent(0)
await this.user.click(screen.getByTitle('Clear current queue'))
expect(emitted().clearQueue).toBeTruthy()
})
it('deletes current playlist', async () => {
2024-01-18 11:13:05 +00:00
const { emitted } = this.renderComponent(0)
await this.user.click(screen.getByTitle('Delete this playlist'))
expect(emitted().deletePlaylist).toBeTruthy()
})
}
2024-04-23 21:01:27 +00:00
private renderComponent (selectedSongCount = 1, configOverrides: Partial<SongListControlsConfig> = {}) {
const songs = factory('song', 5)
2024-04-23 21:01:27 +00:00
const config: SongListControlsConfig = merge({
addTo: {
queue: true,
favorites: true
},
clearQueue: true,
deletePlaylist: true,
refresh: true,
filter: true
}, configOverrides)
return this.render(SongListControls, {
global: {
provide: {
2024-05-19 05:49:42 +00:00
[<symbol>PlayablesKey]: [ref(songs)],
[<symbol>SelectedPlayablesKey]: [ref(take(songs, selectedSongCount))]
2024-04-23 21:01:27 +00:00
}
},
props: {
config
}
})
}
}