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

Summary

Maintainability
A
1 hr
Test Coverage
import { it } from 'vitest'
import { screen, waitFor } from '@testing-library/vue'
import factory from '@/__tests__/factory'
import { eventBus } from '@/utils'
import { Events } from '@/config'
import UnitTestCase from '@/__tests__/UnitTestCase'
import ModalWrapper from './ModalWrapper.vue'

new class extends UnitTestCase {
  protected test () {
    it.each<[string, keyof Events, User | Song[] | Playlist | PlaylistFolder | undefined]>([
      ['add-user-form', 'MODAL_SHOW_ADD_USER_FORM', undefined],
      ['invite-user-form', 'MODAL_SHOW_INVITE_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]
    ])('shows %s modal', async (modalName, eventName, eventParams?: any) => {
      this.render(ModalWrapper, {
        global: {
          stubs: {
            AddUserForm: this.stub('add-user-form'),
            EditUserForm: this.stub('edit-user-form'),
            InviteUserForm: this.stub('invite-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(() => screen.getByTestId(modalName))
    })
  }
}