2022-05-07 08:51:01 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { mockHelper, render, stub } from '@/__tests__/__helpers__'
|
|
|
|
import { httpService } from '@/services'
|
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import { beforeEach, it } from 'vitest'
|
|
|
|
import { cleanup } from '@testing-library/vue'
|
|
|
|
import { EventName } from '@/config'
|
|
|
|
import ModalWrapper from './ModalWrapper.vue'
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
cleanup()
|
|
|
|
mockHelper.restoreAllMocks()
|
|
|
|
})
|
|
|
|
|
2022-05-07 10:14:35 +00:00
|
|
|
it.each<[string, EventName, User | Song | any]>([
|
|
|
|
['add-user-form', 'MODAL_SHOW_ADD_USER_FORM', undefined],
|
2022-05-07 08:51:01 +00:00
|
|
|
['edit-user-form', 'MODAL_SHOW_EDIT_USER_FORM', factory('user')],
|
|
|
|
['edit-song-form', 'MODAL_SHOW_EDIT_SONG_FORM', [factory('song')]],
|
2022-05-07 10:14:35 +00:00
|
|
|
['create-smart-playlist-form', 'MODAL_SHOW_CREATE_SMART_PLAYLIST_FORM', undefined],
|
2022-05-07 08:51:01 +00:00
|
|
|
['edit-smart-playlist-form', 'MODAL_SHOW_EDIT_SMART_PLAYLIST_FORM', factory('playlist')],
|
2022-05-07 10:14:35 +00:00
|
|
|
['about-koel', 'MODAL_SHOW_ABOUT_KOEL', undefined]
|
2022-05-07 08:51:01 +00:00
|
|
|
])('shows %s modal', async (modalName: string, eventName: EventName, eventParams?: any) => {
|
|
|
|
if (modalName === 'edit-song-form') {
|
|
|
|
// mocking the songInfoService.fetch() request made during edit-form modal opening
|
|
|
|
mockHelper.mock(httpService, 'request').mockReturnValue(Promise.resolve({ data: {} }))
|
|
|
|
}
|
|
|
|
|
|
|
|
const { findByTestId } = render(ModalWrapper, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
CreateSmartPlaylistForm: stub('create-smart-playlist-form'),
|
|
|
|
EditSmartPlaylistForm: stub('edit-smart-playlist-form'),
|
|
|
|
AddUserForm: stub('add-user-form'),
|
|
|
|
EditUserForm: stub('edit-user-form'),
|
|
|
|
EditSongForm: stub('edit-song-form'),
|
|
|
|
AboutKoel: stub('about-koel')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
eventBus.emit(eventName, eventParams)
|
|
|
|
|
|
|
|
findByTestId(modalName)
|
|
|
|
})
|