fix: event name type

This commit is contained in:
Phan An 2022-11-19 20:55:15 +01:00
parent 9c776cb3b5
commit 53fa7db641
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
4 changed files with 9 additions and 9 deletions

View file

@ -2,13 +2,13 @@ import { it } from 'vitest'
import { waitFor } from '@testing-library/vue'
import factory from '@/__tests__/factory'
import { eventBus } from '@/utils'
import { EventName } from '@/config'
import { Events } from '@/config'
import UnitTestCase from '@/__tests__/UnitTestCase'
import ModalWrapper from './ModalWrapper.vue'
new class extends UnitTestCase {
protected test () {
it.each<[string, EventName, User | Song[] | Playlist | PlaylistFolder | undefined]>([
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')]],
@ -19,7 +19,7 @@ new class extends UnitTestCase {
['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]
])('shows %s modal', async (modalName: string, eventName: EventName, eventParams?: any) => {
])('shows %s modal', async (modalName, eventName, eventParams?: any) => {
const { getByTestId } = this.render(ModalWrapper, {
global: {
stubs: {

View file

@ -2,7 +2,7 @@ import { expect, it } from 'vitest'
import { fireEvent, waitFor } from '@testing-library/vue'
import UnitTestCase from '@/__tests__/UnitTestCase'
import { eventBus } from '@/utils'
import { EventName } from '@/config'
import { Events } from '@/config'
import CreateNewPlaylistContextMenu from './CreateNewPlaylistContextMenu.vue'
new class extends UnitTestCase {
@ -14,7 +14,7 @@ new class extends UnitTestCase {
}
protected test () {
it.each<[string, EventName]>([
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']

View file

@ -11,11 +11,11 @@
<script lang="ts" setup>
import { useContextMenu } from '@/composables'
import { eventBus } from '@/utils'
import { EventName } from '@/config'
import { Events } from '@/config'
const { base, ContextMenuBase, open, trigger } = useContextMenu()
const actionToEventMap: Record<string, EventName> = {
const actionToEventMap: Record<string, keyof Events> = {
'new-playlist': 'MODAL_SHOW_CREATE_PLAYLIST_FORM',
'new-smart-playlist': 'MODAL_SHOW_CREATE_SMART_PLAYLIST_FORM',
'new-folder': 'MODAL_SHOW_CREATE_PLAYLIST_FOLDER_FORM'

View file

@ -1,7 +1,7 @@
import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
import { commonStore, overviewStore } from '@/stores'
import { EventName } from '@/config'
import { Events } from '@/config'
import { eventBus } from '@/utils'
import HomeScreen from './HomeScreen.vue'
@ -42,7 +42,7 @@ new class extends UnitTestCase {
expect(queryByTestId('screen-empty-state')).toBeNull()
})
it.each<[EventName]>([['SONGS_UPDATED'], ['SONGS_DELETED']])
it.each<[keyof Events]>([['SONGS_UPDATED'], ['SONGS_DELETED']])
('refreshes the overviews on %s event', async (eventName) => {
const initMock = this.mock(overviewStore, 'init')
const refreshMock = this.mock(overviewStore, 'refresh')