2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
2022-09-08 05:06:49 +00:00
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-08-10 14:56:01 +00:00
|
|
|
import PlaylistSidebarItem from './PlaylistSidebarItem.vue'
|
2022-05-08 18:43:52 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-09-08 05:06:49 +00:00
|
|
|
renderComponent (list: PlaylistLike) {
|
2022-05-09 09:59:31 +00:00
|
|
|
return this.render(PlaylistSidebarItem, {
|
|
|
|
props: {
|
2022-09-08 05:06:49 +00:00
|
|
|
list
|
2022-05-08 18:43:52 +00:00
|
|
|
}
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
2022-05-08 18:43:52 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
2022-09-08 05:06:49 +00:00
|
|
|
it('requests context menu if is playlist', async () => {
|
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
|
|
|
const playlist = factory<Playlist>('playlist')
|
|
|
|
const { getByTestId } = this.renderComponent(playlist)
|
2022-05-08 18:43:52 +00:00
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
await fireEvent.contextMenu(getByTestId('playlist-sidebar-item'))
|
2022-05-08 18:43:52 +00:00
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
expect(emitMock).toHaveBeenCalledWith('PLAYLIST_CONTEXT_MENU_REQUESTED', expect.anything(), playlist)
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
2022-05-08 18:43:52 +00:00
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
it.each<FavoriteList['name'] | RecentlyPlayedList['name']>(['Favorites', 'Recently Played'])
|
|
|
|
('does not request context menu if not playlist', async (name) => {
|
|
|
|
const list: FavoriteList | RecentlyPlayedList = {
|
|
|
|
name,
|
2022-05-09 09:59:31 +00:00
|
|
|
songs: []
|
2022-09-08 05:06:49 +00:00
|
|
|
}
|
2022-05-08 18:43:52 +00:00
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
|
|
|
const { getByTestId } = this.renderComponent(list)
|
2022-05-08 18:43:52 +00:00
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
await fireEvent.contextMenu(getByTestId('playlist-sidebar-item'))
|
2022-05-09 09:59:31 +00:00
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
expect(emitMock).not.toHaveBeenCalledWith('PLAYLIST_CONTEXT_MENU_REQUESTED', list)
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|