2022-09-08 05:06:49 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-09-08 05:06:49 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { eventBus } from '@/utils'
|
2022-11-19 19:55:15 +00:00
|
|
|
import { Events } from '@/config'
|
2024-04-04 22:20:42 +00:00
|
|
|
|
|
|
|
import CreateNewPlaylistContextMenu from './CreatePlaylistContextMenu.vue'
|
2022-09-08 05:06:49 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private async renderComponent () {
|
2022-12-02 16:17:37 +00:00
|
|
|
this.render(CreateNewPlaylistContextMenu)
|
2024-01-14 13:20:56 +00:00
|
|
|
eventBus.emit('CREATE_NEW_PLAYLIST_CONTEXT_MENU_REQUESTED', { top: 420, left: 42 })
|
2022-09-08 05:06:49 +00:00
|
|
|
await this.tick(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-11-19 19:55:15 +00:00
|
|
|
it.each<[string, keyof Events]>([
|
2022-09-08 05:06:49 +00:00
|
|
|
['playlist-context-menu-create-simple', 'MODAL_SHOW_CREATE_PLAYLIST_FORM'],
|
|
|
|
['playlist-context-menu-create-smart', 'MODAL_SHOW_CREATE_SMART_PLAYLIST_FORM'],
|
|
|
|
['playlist-context-menu-create-folder', 'MODAL_SHOW_CREATE_PLAYLIST_FOLDER_FORM']
|
|
|
|
])('when clicking on %s, should emit %s', async (id, eventName) => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-09-08 05:06:49 +00:00
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTestId(id))
|
2022-09-08 05:06:49 +00:00
|
|
|
await waitFor(() => expect(emitMock).toHaveBeenCalledWith(eventName))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|