From 31094fe283f86420188a6f0049abbbc6f2bda6bc Mon Sep 17 00:00:00 2001 From: Phan An Date: Sun, 10 Jul 2022 17:17:48 +0200 Subject: [PATCH] fix(test): MainWrapper tests --- .../js/components/layout/AppHeader.spec.ts | 8 +-- .../js/components/layout/ModalWrapper.spec.ts | 21 +------ .../js/components/layout/ModalWrapper.vue | 57 ++++++++----------- .../layout/main-wrapper/ExtraPanel.spec.ts | 10 +--- .../smart-playlist/SmartPlaylistEditForm.vue | 9 +-- .../js/components/song/SongEditForm.vue | 19 +++---- .../js/components/user/UserEditForm.vue | 23 +++++--- resources/assets/js/symbols.ts | 5 ++ resources/assets/js/types.d.ts | 2 + 9 files changed, 66 insertions(+), 88 deletions(-) diff --git a/resources/assets/js/components/layout/AppHeader.spec.ts b/resources/assets/js/components/layout/AppHeader.spec.ts index 3a5cfdd8..366ec656 100644 --- a/resources/assets/js/components/layout/AppHeader.spec.ts +++ b/resources/assets/js/components/layout/AppHeader.spec.ts @@ -1,6 +1,6 @@ import isMobile from 'ismobilejs' import { expect, it } from 'vitest' -import { fireEvent, queryAllByTestId } from '@testing-library/vue' +import { fireEvent, queryAllByTestId, waitFor } from '@testing-library/vue' import { eventBus } from '@/utils' import factory from '@/__tests__/factory' import compareVersions from 'compare-versions' @@ -34,9 +34,7 @@ new class extends UnitTestCase { expect(await queryByRole('search')).toBeNull() await fireEvent.click(getByTitle('Show or hide the search form')) - await this.tick() - - getByRole('search') + await waitFor(() => getByRole('search')) }) it.each([[true, true, true], [false, true, false], [true, false, false], [false, false, false]])( @@ -46,7 +44,7 @@ new class extends UnitTestCase { const { queryAllByTestId } = this.actingAs(factory('user', { is_admin: isAdmin })).render(AppHeader) - expect(await queryAllByTestId('new-version')).toHaveLength(announcing ? 1 : 0) + expect(queryAllByTestId('new-version')).toHaveLength(announcing ? 1 : 0) } ) } diff --git a/resources/assets/js/components/layout/ModalWrapper.spec.ts b/resources/assets/js/components/layout/ModalWrapper.spec.ts index 101f06be..bf9895ea 100644 --- a/resources/assets/js/components/layout/ModalWrapper.spec.ts +++ b/resources/assets/js/components/layout/ModalWrapper.spec.ts @@ -1,5 +1,4 @@ import factory from '@/__tests__/factory' -import { httpService } from '@/services' import { eventBus } from '@/utils' import { it } from 'vitest' import { EventName } from '@/config' @@ -8,7 +7,7 @@ import ModalWrapper from './ModalWrapper.vue' new class extends UnitTestCase { protected test () { - it.each<[string, EventName, User | Song | any]>([ + it.each<[string, EventName, User | Song | Playlist | any]>([ ['add-user-form', 'MODAL_SHOW_ADD_USER_FORM', undefined], ['edit-user-form', 'MODAL_SHOW_EDIT_USER_FORM', factory('user')], ['edit-song-form', 'MODAL_SHOW_EDIT_SONG_FORM', [factory('song')]], @@ -16,23 +15,7 @@ new class extends UnitTestCase { ['edit-smart-playlist-form', 'MODAL_SHOW_EDIT_SMART_PLAYLIST_FORM', factory('playlist')], ['about-koel', 'MODAL_SHOW_ABOUT_KOEL', undefined] ])('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 - this.mock(httpService, 'request').mockReturnValue(Promise.resolve({ data: {} })) - } - - const { findByTestId } = this.render(ModalWrapper, { - global: { - stubs: { - CreateSmartPlaylistForm: this.stub('create-smart-playlist-form'), - EditSmartPlaylistForm: this.stub('edit-smart-playlist-form'), - AddUserForm: this.stub('add-user-form'), - EditUserForm: this.stub('edit-user-form'), - EditSongForm: this.stub('edit-song-form'), - AboutKoel: this.stub('about-koel') - } - } - }) + const { findByTestId } = this.render(ModalWrapper) eventBus.emit(eventName, eventParams) diff --git a/resources/assets/js/components/layout/ModalWrapper.vue b/resources/assets/js/components/layout/ModalWrapper.vue index 4f78c15a..823becf4 100644 --- a/resources/assets/js/components/layout/ModalWrapper.vue +++ b/resources/assets/js/components/layout/ModalWrapper.vue @@ -1,33 +1,18 @@