koel/resources/assets/js/components/layout/ModalWrapper.spec.ts

46 lines
2.3 KiB
TypeScript
Raw Normal View History

import { it } from 'vitest'
import { waitFor } from '@testing-library/vue'
import factory from '@/__tests__/factory'
import { eventBus } from '@/utils'
2022-11-19 19:55:15 +00:00
import { Events } from '@/config'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import ModalWrapper from './ModalWrapper.vue'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
2022-11-19 19:55:15 +00:00
it.each<[string, keyof Events, User | Song[] | Playlist | PlaylistFolder | undefined]>([
['add-user-form', 'MODAL_SHOW_ADD_USER_FORM', undefined],
['edit-user-form', 'MODAL_SHOW_EDIT_USER_FORM', factory<User>('user')],
['edit-song-form', 'MODAL_SHOW_EDIT_SONG_FORM', [factory<Song>('song')]],
['create-playlist-form', 'MODAL_SHOW_CREATE_PLAYLIST_FORM', factory<PlaylistFolder>('playlist-folder')],
['create-playlist-folder-form', 'MODAL_SHOW_CREATE_PLAYLIST_FOLDER_FORM', undefined],
['edit-playlist-folder-form', 'MODAL_SHOW_EDIT_PLAYLIST_FOLDER_FORM', factory<PlaylistFolder>('playlist-folder')],
['create-smart-playlist-form', 'MODAL_SHOW_CREATE_SMART_PLAYLIST_FORM', factory<PlaylistFolder>('playlist-folder')],
['edit-playlist-form', 'MODAL_SHOW_EDIT_PLAYLIST_FORM', factory<Playlist>('playlist')],
['edit-smart-playlist-form', 'MODAL_SHOW_EDIT_PLAYLIST_FORM', factory<Playlist>('playlist', { is_smart: true })],
['about-koel', 'MODAL_SHOW_ABOUT_KOEL', undefined]
2022-11-19 19:55:15 +00:00
])('shows %s modal', async (modalName, eventName, eventParams?: any) => {
const { getByTestId } = this.render(ModalWrapper, {
global: {
stubs: {
AddUserForm: this.stub('add-user-form'),
EditUserForm: this.stub('edit-user-form'),
EditSongForm: this.stub('edit-song-form'),
CreatePlaylistForm: this.stub('create-playlist-form'),
CreatePlaylistFolderForm: this.stub('create-playlist-folder-form'),
EditPlaylistFolderForm: this.stub('edit-playlist-folder-form'),
CreateSmartPlaylistForm: this.stub('create-smart-playlist-form'),
EditPlaylistForm: this.stub('edit-playlist-form'),
EditSmartPlaylistForm: this.stub('edit-smart-playlist-form'),
AboutKoelModal: this.stub('about-koel')
}
}
})
eventBus.emit(eventName, eventParams)
await waitFor(() => getByTestId(modalName))
})
}
}