2022-05-09 12:25:19 +00:00
|
|
|
import { clone } from 'lodash'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-09 12:25:19 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { favoriteStore, playlistStore, queueStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-12-06 10:28:48 +00:00
|
|
|
import { arrayify, eventBus } from '@/utils'
|
2024-04-04 22:20:42 +00:00
|
|
|
import Btn from '@/components/ui/form/Btn.vue'
|
2022-05-09 12:25:19 +00:00
|
|
|
import AddToMenu from './AddToMenu.vue'
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
let playables: Playable[]
|
2022-05-09 12:25:19 +00:00
|
|
|
|
|
|
|
const config: AddToMenuConfig = {
|
|
|
|
queue: true,
|
2022-12-06 10:28:48 +00:00
|
|
|
favorites: true
|
2022-05-09 12:25:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 12:25:19 +00:00
|
|
|
protected test () {
|
|
|
|
it('renders', () => {
|
|
|
|
playlistStore.state.playlists = [
|
2024-06-01 18:02:27 +00:00
|
|
|
factory('playlist', { name: 'Foo' }),
|
|
|
|
factory('playlist', { name: 'Bar' }),
|
|
|
|
factory('playlist', { name: 'Baz' })
|
2022-05-09 12:25:19 +00:00
|
|
|
]
|
|
|
|
|
2022-07-16 09:52:39 +00:00
|
|
|
expect(this.renderComponent().html()).toMatchSnapshot()
|
2022-05-09 12:25:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it.each<[keyof AddToMenuConfig, string | string[]]>([
|
|
|
|
['queue', ['queue-after-current', 'queue-bottom', 'queue-top', 'queue']],
|
|
|
|
['favorites', 'add-to-favorites'],
|
|
|
|
])('renders disabling %s config', (configKey: keyof AddToMenuConfig, testIds: string | string[]) => {
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent({ [configKey]: false })
|
|
|
|
arrayify(testIds).forEach(id => expect(screen.queryByTestId(id)).toBeNull())
|
2022-05-09 12:25:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it.each<[string, string, MethodOf<typeof queueStore>]>([
|
|
|
|
['after current', 'queue-after-current', 'queueAfterCurrent'],
|
|
|
|
['to top', 'queue-top', 'queueToTop'],
|
|
|
|
['to bottom', 'queue-bottom', 'queue']
|
|
|
|
])('queues songs %s', async (_: string, testId: string, queueMethod: MethodOf<typeof queueStore>) => {
|
2024-06-01 18:02:27 +00:00
|
|
|
queueStore.state.playables = factory('song', 5)
|
2024-05-19 05:49:42 +00:00
|
|
|
queueStore.state.playables[2].playback_state = 'Playing'
|
2022-09-12 15:33:41 +00:00
|
|
|
|
2022-05-09 12:25:19 +00:00
|
|
|
const mock = this.mock(queueStore, queueMethod)
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-09 12:25:19 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTestId(testId))
|
2022-05-09 12:25:19 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith(playables)
|
2022-05-09 12:25:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('adds songs to Favorites', async () => {
|
|
|
|
const mock = this.mock(favoriteStore, 'like')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-09 12:25:19 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTestId('add-to-favorites'))
|
2022-05-09 12:25:19 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith(playables)
|
2022-05-09 12:25:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('adds songs to existing playlist', async () => {
|
2024-05-19 05:49:42 +00:00
|
|
|
const mock = this.mock(playlistStore, 'addContent')
|
2024-06-01 18:02:27 +00:00
|
|
|
playlistStore.state.playlists = factory('playlist', 3)
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-09 12:25:19 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getAllByTestId('add-to-playlist')[1])
|
2022-05-09 12:25:19 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith(playlistStore.state.playlists[1], playables)
|
2022-05-09 12:25:19 +00:00
|
|
|
})
|
2022-12-06 10:28:48 +00:00
|
|
|
|
|
|
|
it('creates playlist from selected songs', async () => {
|
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
|
|
|
this.renderComponent()
|
|
|
|
|
|
|
|
await this.user.click(screen.getByText('New Playlist…'))
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
expect(emitMock).toHaveBeenCalledWith('MODAL_SHOW_CREATE_PLAYLIST_FORM', null, playables)
|
2022-12-06 10:28:48 +00:00
|
|
|
})
|
2022-05-09 12:25:19 +00:00
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private renderComponent (customConfig: Partial<AddToMenuConfig> = {}) {
|
2024-06-02 17:15:31 +00:00
|
|
|
playables = factory('song', 5)
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
return this.render(AddToMenu, {
|
|
|
|
props: {
|
2024-06-02 17:15:31 +00:00
|
|
|
playables,
|
2024-04-23 21:01:27 +00:00
|
|
|
config: Object.assign(clone(config), customConfig),
|
|
|
|
showing: true
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
Btn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-05-09 12:25:19 +00:00
|
|
|
}
|