koel/resources/assets/js/components/playlist/CreatePlaylistContextMenu.spec.ts

29 lines
1.1 KiB
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
import { screen, waitFor } from '@testing-library/vue'
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'
new class extends UnitTestCase {
protected test () {
2022-11-19 19:55:15 +00:00
it.each<[string, keyof Events]>([
['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) => {
await this.renderComponent()
const emitMock = this.mock(eventBus, 'emit')
await this.user.click(screen.getByTestId(id))
await waitFor(() => expect(emitMock).toHaveBeenCalledWith(eventName))
})
}
2024-04-23 21:01:27 +00:00
private async renderComponent () {
this.render(CreateNewPlaylistContextMenu)
eventBus.emit('CREATE_NEW_PLAYLIST_CONTEXT_MENU_REQUESTED', { top: 420, left: 42 })
await this.tick(2)
}
}