diff --git a/resources/assets/js/__tests__/ComponentTestCase.ts b/resources/assets/js/__tests__/UnitTestCase.ts similarity index 97% rename from resources/assets/js/__tests__/ComponentTestCase.ts rename to resources/assets/js/__tests__/UnitTestCase.ts index d5c02d15..f60b2bcf 100644 --- a/resources/assets/js/__tests__/ComponentTestCase.ts +++ b/resources/assets/js/__tests__/UnitTestCase.ts @@ -9,7 +9,7 @@ import factory from '@/__tests__/factory' declare type Methods = { [K in keyof T]: T[K] extends Closure ? K : never; }[keyof T] & (string | symbol); -export default abstract class ComponentTestCase { +export default abstract class UnitTestCase { private backupMethods = new Map() public constructor () { diff --git a/resources/assets/js/__tests__/__mocks__/lodash.ts b/resources/assets/js/__tests__/__mocks__/lodash.ts index e496176d..a58a7ce0 100644 --- a/resources/assets/js/__tests__/__mocks__/lodash.ts +++ b/resources/assets/js/__tests__/__mocks__/lodash.ts @@ -1,13 +1,13 @@ /* eslint @typescript-eslint/no-unused-vars: 0 */ -import _, { Cancelable } from 'lodash' +import _ from 'lodash' -_.orderBy = jest.fn((collection: T[]): T[] => collection) +_.orderBy = jest.fn( (collection: T[]): T[] => collection) -_.shuffle = jest.fn((collection: T[]): T[] => collection) +_.shuffle = jest.fn( (collection: T[]): T[] => collection) _.throttle = jest.fn((fn: Function, wait: number): any => fn) -_.sample = jest.fn((collection: T[]): T | undefined => { +_.sample = jest.fn( (collection: T[]): T | undefined => { return collection.length ? collection[0] : undefined }) diff --git a/resources/assets/js/__tests__/__transformers__/image.js b/resources/assets/js/__tests__/__transformers__/image.js deleted file mode 100644 index 786fb45b..00000000 --- a/resources/assets/js/__tests__/__transformers__/image.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - process () { - return 'module.exports = {};' - }, - - getCacheKey () { - return 'imageTransform' - } -} diff --git a/resources/assets/js/__tests__/components/utils/event-listeners.spec.ts b/resources/assets/js/__tests__/components/utils/event-listeners.spec.ts deleted file mode 100644 index 58ae7af8..00000000 --- a/resources/assets/js/__tests__/components/utils/event-listeners.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import Component from '@/components/utils/event-listeners.vue' -import factory from '@/__tests__/factory' -import { playlistStore, userStore } from '@/stores' -import router from '@/router' -import { authService } from '@/services' -import { alerts, eventBus } from '@/utils' -import { mock } from '@/__tests__/__helpers__' -import { mount } from '@/__tests__/adapter' - -describe('utils/event-listeners', () => { - afterEach(() => { - jest.resetModules() - jest.clearAllMocks() - }) - - it('confirms a playlist deleting if the playlist is not empty', () => { - mount(Component) - - const confirmMock = mock(alerts, 'confirm') - eventBus.emit('PLAYLIST_DELETE', factory('playlist', { - name: 'Foo', - populated: true, - songs: factory('song', 3) - })) - - expect(confirmMock).toHaveBeenCalledWith(`Delete the playlist "Foo"?`, expect.any(Function)) - }) - - it("doesn't confirm deleting a playlist if the playlist is empty", () => { - const playlist = factory('playlist', { - populated: true, - songs: [] - }) - - mount(Component) - const confirmMock = mock(alerts, 'confirm') - const deleteMock = mock(playlistStore, 'delete') - eventBus.emit('PLAYLIST_DELETE', playlist) - - expect(confirmMock).not.toHaveBeenCalled() - expect(deleteMock).toHaveBeenCalledWith(playlist) - }) - - it('listens to log out event', () => { - const wrapper = mount(Component) - const authDestroyMock = mock(authService, 'destroy') - const logOutMock = mock(userStore, 'logout') - - eventBus.emit('LOG_OUT') - - wrapper.vm.$nextTick(() => { - expect(authDestroyMock).toHaveBeenCalled() - expect(logOutMock).toHaveBeenCalled() - }) - }) - - it('listen to koel-ready event', () => { - mount(Component) - const initRouterMock = mock(router, 'init') - eventBus.emit('KOEL_READY') - expect(initRouterMock).toHaveBeenCalled() - }) -}) diff --git a/resources/assets/js/__tests__/services/download.spec.ts b/resources/assets/js/__tests__/services/download.spec.ts deleted file mode 100644 index 724d2d71..00000000 --- a/resources/assets/js/__tests__/services/download.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { downloadService } from '@/services' -import { favoriteStore } from '@/stores' -import factory from '@/__tests__/factory' -import { mock } from '@/__tests__/__helpers__' - -describe('services/download', () => { - afterEach(() => { - jest.resetModules() - jest.restoreAllMocks() - jest.clearAllMocks() - }) - - it('downloads songs', () => { - const triggerMock = mock(downloadService, 'trigger') - downloadService.fromSongs([factory('song', { id: 'foo' }), factory('song', { id: 'bar' })]) - - expect(triggerMock).toHaveBeenCalledWith('songs?songs[]=bar&songs[]=foo&') - }) - - it('downloads all by artist', () => { - const triggerMock = mock(downloadService, 'trigger') - downloadService.fromArtist(factory('artist', { id: 42 })) - - expect(triggerMock).toHaveBeenCalledWith('artist/42') - }) - - it('downloads all in album', () => { - const triggerMock = mock(downloadService, 'trigger') - downloadService.fromAlbum(factory('album', { id: 42 })) - - expect(triggerMock).toHaveBeenCalledWith('album/42') - }) - - it.each<[Song[], boolean]>([[[], false], [factory('song', 5), true]])( - 'downloads playlist if available', - (songs, triggered) => { - const triggerMock = mock(downloadService, 'trigger') - downloadService.fromPlaylist(factory('playlist', { id: 42, songs })) - - triggered - ? expect(triggerMock).toHaveBeenCalledWith('playlist/42') - : expect(triggerMock).not.toHaveBeenCalled() - }) - - it.each<[Song[], boolean]>([[[], false], [factory('song', 5), true]])( - 'downloads favorites if available', - (songs, triggered) => { - const triggerMock = mock(downloadService, 'trigger') - favoriteStore.all = songs - downloadService.fromFavorites() - - triggered - ? expect(triggerMock).toHaveBeenCalledWith('favorites') - : expect(triggerMock).not.toHaveBeenCalled() - }) -}) diff --git a/resources/assets/js/__tests__/services/ls.spec.ts b/resources/assets/js/__tests__/services/ls.spec.ts deleted file mode 100644 index 4620cc81..00000000 --- a/resources/assets/js/__tests__/services/ls.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { get, set, remove } from 'local-storage' -import { localStorageService } from '@/services' - -describe('services/ls', () => { - it('gets an existing item from local storage', () => { - set('foo', 'bar') - expect(localStorageService.get('foo')).toBe('bar') - }) - - it('returns the default value for a non exising item', () => { - remove('foo') - expect(localStorageService.get('foo', 42)).toBe(42) - }) - - it('sets an item into local storage', () => { - remove('foo') - localStorageService.set('foo', 42) - expect(get('foo')).toBe(42) - }) - - it('correctly removes an item from local storage', () => { - set('foo', 42) - localStorageService.remove('foo') - expect(get('foo')).toBeNull() - }) -}) diff --git a/resources/assets/js/__tests__/services/youtube.spec.ts b/resources/assets/js/__tests__/services/youtube.spec.ts deleted file mode 100644 index ae9dd65e..00000000 --- a/resources/assets/js/__tests__/services/youtube.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { youtubeService } from '@/services' -import { eventBus } from '@/utils' -import router from '@/router' -import factory from '@/__tests__/factory' -import { mock } from '@/__tests__/__helpers__' - -describe('services/youtube', () => { - afterEach(() => { - jest.resetModules() - jest.restoreAllMocks() - jest.clearAllMocks() - }) - - it('plays a video', () => { - const video = factory('video', { - id: { - videoId: 'foo' - }, - snippet: { - title: 'Bar' - } - }) - const emitMock = mock(eventBus, 'emit') - const goMock = mock(router, 'go') - - youtubeService.play(video) - expect(emitMock).toHaveBeenCalledWith('PLAY_YOUTUBE_VIDEO', { id: 'foo', title: 'Bar' }) - expect(goMock).toHaveBeenCalledWith('youtube') - }) -}) diff --git a/resources/assets/js/components/album/AlbumCard.spec.ts b/resources/assets/js/components/album/AlbumCard.spec.ts index 367d3d65..85069c0e 100644 --- a/resources/assets/js/components/album/AlbumCard.spec.ts +++ b/resources/assets/js/components/album/AlbumCard.spec.ts @@ -2,12 +2,12 @@ import { fireEvent } from '@testing-library/vue' import { expect, it } from 'vitest' import { downloadService, playbackService } from '@/services' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AlbumCard from './AlbumCard.vue' let album: Album -new class extends ComponentTestCase { +new class extends UnitTestCase { protected beforeEach () { super.beforeEach(() => { album = factory('album', { diff --git a/resources/assets/js/components/album/AlbumInfo.spec.ts b/resources/assets/js/components/album/AlbumInfo.spec.ts index 6fc8b6ce..ec4b1296 100644 --- a/resources/assets/js/components/album/AlbumInfo.spec.ts +++ b/resources/assets/js/components/album/AlbumInfo.spec.ts @@ -1,11 +1,11 @@ import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AlbumInfo from './AlbumInfo.vue' import AlbumThumbnail from '@/components/ui/AlbumArtistThumbnail.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it.each([['sidebar'], ['full']])('renders in %s mode', async (mode: string) => { const { getByTestId } = this.render(AlbumInfo, { diff --git a/resources/assets/js/components/album/AlbumTrackList.spec.ts b/resources/assets/js/components/album/AlbumTrackList.spec.ts index 8e8387ea..0033b95a 100644 --- a/resources/assets/js/components/album/AlbumTrackList.spec.ts +++ b/resources/assets/js/components/album/AlbumTrackList.spec.ts @@ -1,10 +1,10 @@ import factory from '@/__tests__/factory' import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AlbumTrackList from './AlbumTrackList.vue' import TrackListItem from './AlbumTrackListItem.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('lists the correct number of tracks', () => { const { queryAllByTestId } = this.render(AlbumTrackList, { diff --git a/resources/assets/js/components/album/AlbumTrackListItem.spec.ts b/resources/assets/js/components/album/AlbumTrackListItem.spec.ts index e5370f99..c1b54f2a 100644 --- a/resources/assets/js/components/album/AlbumTrackListItem.spec.ts +++ b/resources/assets/js/components/album/AlbumTrackListItem.spec.ts @@ -3,7 +3,7 @@ import { expect, it } from 'vitest' import factory from '@/__tests__/factory' import { queueStore, songStore } from '@/stores' import { playbackService } from '@/services' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AlbumTrackListItem from './AlbumTrackListItem.vue' let song: Song @@ -15,7 +15,7 @@ const track = { const album = factory('album', { id: 42 }) -new class extends ComponentTestCase { +new class extends UnitTestCase { protected beforeEach () { super.beforeEach(() => (song = factory('song'))) } diff --git a/resources/assets/js/components/artist/ArtistCard.spec.ts b/resources/assets/js/components/artist/ArtistCard.spec.ts index fce2ab74..542b54b4 100644 --- a/resources/assets/js/components/artist/ArtistCard.spec.ts +++ b/resources/assets/js/components/artist/ArtistCard.spec.ts @@ -2,12 +2,12 @@ import { fireEvent } from '@testing-library/vue' import { expect, it } from 'vitest' import factory from '@/__tests__/factory' import { downloadService, playbackService } from '@/services' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ArtistCard from './ArtistCard.vue' let artist: Artist -new class extends ComponentTestCase { +new class extends UnitTestCase { protected beforeEach () { super.beforeEach(() => { artist = factory('artist', { diff --git a/resources/assets/js/components/artist/ArtistInfo.spec.ts b/resources/assets/js/components/artist/ArtistInfo.spec.ts index 6fbe2a6d..3c9bce24 100644 --- a/resources/assets/js/components/artist/ArtistInfo.spec.ts +++ b/resources/assets/js/components/artist/ArtistInfo.spec.ts @@ -1,11 +1,11 @@ import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ArtistInfo from './ArtistInfo.vue' import ArtistThumbnail from '@/components/ui/AlbumArtistThumbnail.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it.each([['sidebar'], ['full']])('renders in %s mode', async (mode: string) => { const { getByTestId } = this.render(ArtistInfo, { diff --git a/resources/assets/js/components/auth/LoginForm.spec.ts b/resources/assets/js/components/auth/LoginForm.spec.ts index a28010ac..47a9cba1 100644 --- a/resources/assets/js/components/auth/LoginForm.spec.ts +++ b/resources/assets/js/components/auth/LoginForm.spec.ts @@ -1,11 +1,11 @@ import { fireEvent } from '@testing-library/vue' import { expect, it } from 'vitest' import { userStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import LoginFrom from './LoginForm.vue' import Btn from '@/components/ui/Btn.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => expect(this.render(LoginFrom, { global: { diff --git a/resources/assets/js/components/layout/AppHeader.spec.ts b/resources/assets/js/components/layout/AppHeader.spec.ts index dcf8f70b..3a5cfdd8 100644 --- a/resources/assets/js/components/layout/AppHeader.spec.ts +++ b/resources/assets/js/components/layout/AppHeader.spec.ts @@ -4,11 +4,11 @@ import { fireEvent, queryAllByTestId } from '@testing-library/vue' import { eventBus } from '@/utils' import factory from '@/__tests__/factory' import compareVersions from 'compare-versions' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AppHeader from './AppHeader.vue' import SearchForm from '@/components/ui/SearchForm.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('toggles sidebar (mobile only)', async () => { isMobile.any = true diff --git a/resources/assets/js/components/layout/ModalWrapper.spec.ts b/resources/assets/js/components/layout/ModalWrapper.spec.ts index db38f40d..101f06be 100644 --- a/resources/assets/js/components/layout/ModalWrapper.spec.ts +++ b/resources/assets/js/components/layout/ModalWrapper.spec.ts @@ -3,10 +3,10 @@ import { httpService } from '@/services' import { eventBus } from '@/utils' import { it } from 'vitest' import { EventName } from '@/config' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ModalWrapper from './ModalWrapper.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it.each<[string, EventName, User | Song | any]>([ ['add-user-form', 'MODAL_SHOW_ADD_USER_FORM', undefined], diff --git a/resources/assets/js/components/layout/app-footer/FooterExtraControls.spec.ts b/resources/assets/js/components/layout/app-footer/FooterExtraControls.spec.ts index 4c450a2d..2d655c23 100644 --- a/resources/assets/js/components/layout/app-footer/FooterExtraControls.spec.ts +++ b/resources/assets/js/components/layout/app-footer/FooterExtraControls.spec.ts @@ -6,10 +6,10 @@ import Volume from '@/components/ui/Volume.vue' import LikeButton from '@/components/song/SongLikeButton.vue' import RepeatModeSwitch from '@/components/ui/RepeatModeSwitch.vue' import Equalizer from '@/components/ui/Equalizer.vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import FooterExtraControls from './FooterExtraControls.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => { preferenceStore.state.showExtraPanel = true diff --git a/resources/assets/js/components/layout/app-footer/FooterMiddlePane.spec.ts b/resources/assets/js/components/layout/app-footer/FooterMiddlePane.spec.ts index 81f31433..10c7a68c 100644 --- a/resources/assets/js/components/layout/app-footer/FooterMiddlePane.spec.ts +++ b/resources/assets/js/components/layout/app-footer/FooterMiddlePane.spec.ts @@ -1,9 +1,9 @@ import { expect, it } from 'vitest' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import FooterMiddlePane from './FooterMiddlePane.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders without a song', () => { expect(this.render(FooterMiddlePane).html()).toMatchSnapshot() diff --git a/resources/assets/js/components/layout/app-footer/FooterPlayerControl.spec.ts b/resources/assets/js/components/layout/app-footer/FooterPlayerControl.spec.ts index 72b8f7e3..3f93fc99 100644 --- a/resources/assets/js/components/layout/app-footer/FooterPlayerControl.spec.ts +++ b/resources/assets/js/components/layout/app-footer/FooterPlayerControl.spec.ts @@ -2,10 +2,10 @@ import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import { playbackService } from '@/services' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import FooterPlayerControls from './FooterPlayerControls.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it.each<[string, string, MethodOf]>([ ['plays next song', 'Play next song', 'playNext'], diff --git a/resources/assets/js/components/layout/main-wrapper/ExtraPanel.spec.ts b/resources/assets/js/components/layout/main-wrapper/ExtraPanel.spec.ts index 31d41312..ecdf566e 100644 --- a/resources/assets/js/components/layout/main-wrapper/ExtraPanel.spec.ts +++ b/resources/assets/js/components/layout/main-wrapper/ExtraPanel.spec.ts @@ -4,10 +4,10 @@ import factory from '@/__tests__/factory' import { commonStore } from '@/stores' import { songInfoService } from '@/services' import { eventBus } from '@/utils' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ExtraPanel from './ExtraPanel.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent () { return this.render(ExtraPanel, { props: { diff --git a/resources/assets/js/components/layout/main-wrapper/MainContent.spec.ts b/resources/assets/js/components/layout/main-wrapper/MainContent.spec.ts index 06bfcdcd..c06f9e74 100644 --- a/resources/assets/js/components/layout/main-wrapper/MainContent.spec.ts +++ b/resources/assets/js/components/layout/main-wrapper/MainContent.spec.ts @@ -2,12 +2,12 @@ import { expect, it } from 'vitest' import factory from '@/__tests__/factory' import { eventBus } from '@/utils' import { albumStore, preferenceStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import MainContent from '@/components/layout/main-wrapper/MainContent.vue' import AlbumArtOverlay from '@/components/ui/AlbumArtOverlay.vue' import Visualizer from '@/components/ui/Visualizer.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('has a translucent overlay per album', async () => { this.mock(albumStore, 'getThumbnail', 'https://foo/bar.jpg') diff --git a/resources/assets/js/components/layout/main-wrapper/Sidebar.spec.ts b/resources/assets/js/components/layout/main-wrapper/Sidebar.spec.ts index 9e5e3e6b..8a76361a 100644 --- a/resources/assets/js/components/layout/main-wrapper/Sidebar.spec.ts +++ b/resources/assets/js/components/layout/main-wrapper/Sidebar.spec.ts @@ -1,7 +1,7 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('has already been tested in the integration suite', () => expect('😄').toBeTruthy()) } diff --git a/resources/assets/js/components/meta/AboutKoelModal.spec.ts b/resources/assets/js/components/meta/AboutKoelModal.spec.ts index 4d4d9555..0563f086 100644 --- a/resources/assets/js/components/meta/AboutKoelModal.spec.ts +++ b/resources/assets/js/components/meta/AboutKoelModal.spec.ts @@ -1,10 +1,10 @@ import { expect, it } from 'vitest' import { commonStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AboutKoelModel from './AboutKoelModal.vue' import Btn from '@/components/ui/Btn.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected beforeEach () { super.beforeEach(() => (KOEL_ENV = '')); } diff --git a/resources/assets/js/components/meta/SupportKoel.spec.ts b/resources/assets/js/components/meta/SupportKoel.spec.ts index cc9098f5..7cabfbb0 100644 --- a/resources/assets/js/components/meta/SupportKoel.spec.ts +++ b/resources/assets/js/components/meta/SupportKoel.spec.ts @@ -2,10 +2,10 @@ import { expect, it, vi } from 'vitest' import { fireEvent } from '@testing-library/vue' import { eventBus } from '@/utils' import { preferenceStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import SupportKoel from './SupportKoel.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected beforeEach () { super.beforeEach(() => vi.useFakeTimers()); } diff --git a/resources/assets/js/components/playlist/PlaylistNameEditor.spec.ts b/resources/assets/js/components/playlist/PlaylistNameEditor.spec.ts index b8021ed1..2eaab47f 100644 --- a/resources/assets/js/components/playlist/PlaylistNameEditor.spec.ts +++ b/resources/assets/js/components/playlist/PlaylistNameEditor.spec.ts @@ -3,9 +3,9 @@ import PlaylistNameEditor from '@/components/playlist/PlaylistNameEditor.vue' import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import { playlistStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' -new class extends ComponentTestCase { +new class extends UnitTestCase { private useEditor () { const updateMock = this.mock(playlistStore, 'update') diff --git a/resources/assets/js/components/playlist/PlaylistSidebarItem.spec.ts b/resources/assets/js/components/playlist/PlaylistSidebarItem.spec.ts index 7f63c636..b0f3c1ef 100644 --- a/resources/assets/js/components/playlist/PlaylistSidebarItem.spec.ts +++ b/resources/assets/js/components/playlist/PlaylistSidebarItem.spec.ts @@ -1,10 +1,10 @@ import factory from '@/__tests__/factory' import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import PlaylistSidebarItem from '@/components/playlist/PlaylistSidebarItem.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { renderComponent (playlist: Record, type: PlaylistType = 'playlist') { return this.render(PlaylistSidebarItem, { props: { diff --git a/resources/assets/js/components/playlist/PlaylistSidebarList.spec.ts b/resources/assets/js/components/playlist/PlaylistSidebarList.spec.ts index ec77840d..5cc71bdd 100644 --- a/resources/assets/js/components/playlist/PlaylistSidebarList.spec.ts +++ b/resources/assets/js/components/playlist/PlaylistSidebarList.spec.ts @@ -3,9 +3,9 @@ import { playlistStore } from '@/stores' import factory from '@/__tests__/factory' import PlaylistSidebarList from './PlaylistSidebarList.vue' import PlaylistSidebarItem from './PlaylistSidebarItem.vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders all playlists', () => { playlistStore.state.playlists = [ diff --git a/resources/assets/js/components/profile-preferences/LastfmIntegration.spec.ts b/resources/assets/js/components/profile-preferences/LastfmIntegration.spec.ts index 293dcaa9..1ec95b3b 100644 --- a/resources/assets/js/components/profile-preferences/LastfmIntegration.spec.ts +++ b/resources/assets/js/components/profile-preferences/LastfmIntegration.spec.ts @@ -1,7 +1,7 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('is already covered by E2E', () => expect('🤞').toBeTruthy()) } diff --git a/resources/assets/js/components/profile-preferences/PreferencesForm.spec.ts b/resources/assets/js/components/profile-preferences/PreferencesForm.spec.ts index 18bfebd7..161494e9 100644 --- a/resources/assets/js/components/profile-preferences/PreferencesForm.spec.ts +++ b/resources/assets/js/components/profile-preferences/PreferencesForm.spec.ts @@ -1,9 +1,9 @@ import { expect, it } from 'vitest' import isMobile from 'ismobilejs' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import PreferencesForm from './PreferencesForm.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('has "Transcode on mobile" option for mobile users', () => { isMobile.phone = true diff --git a/resources/assets/js/components/profile-preferences/ThemeCard.spec.ts b/resources/assets/js/components/profile-preferences/ThemeCard.spec.ts index 81cb8ec7..07a213b4 100644 --- a/resources/assets/js/components/profile-preferences/ThemeCard.spec.ts +++ b/resources/assets/js/components/profile-preferences/ThemeCard.spec.ts @@ -1,4 +1,4 @@ -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import ThemeCard from './ThemeCard.vue' @@ -8,7 +8,7 @@ const theme: Theme = { thumbnailColor: '#f00' } -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent () { return this.render(ThemeCard, { props: { diff --git a/resources/assets/js/components/profile-preferences/ThemeList.spec.ts b/resources/assets/js/components/profile-preferences/ThemeList.spec.ts index a0c2bb41..f8d19384 100644 --- a/resources/assets/js/components/profile-preferences/ThemeList.spec.ts +++ b/resources/assets/js/components/profile-preferences/ThemeList.spec.ts @@ -1,9 +1,9 @@ import { expect, it } from 'vitest' import { themeStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ThemeList from './ThemeList.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('displays all themes', () => { expect(this.render(ThemeList).getAllByTestId('theme-card').length).toEqual(themeStore.state.themes.length) diff --git a/resources/assets/js/components/screens/search/SearchExcerptsScreen.spec.ts b/resources/assets/js/components/screens/search/SearchExcerptsScreen.spec.ts index a50e1a8a..bdfa176f 100644 --- a/resources/assets/js/components/screens/search/SearchExcerptsScreen.spec.ts +++ b/resources/assets/js/components/screens/search/SearchExcerptsScreen.spec.ts @@ -1,10 +1,10 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import { searchStore } from '@/stores' import { eventBus } from '@/utils' import SearchExceptsScreen from './SearchExcerptsScreen.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('executes searching when the search keyword is changed', async () => { const mock = this.mock(searchStore, 'excerptSearch') diff --git a/resources/assets/js/components/screens/search/SearchSongResultsScreen.spec.ts b/resources/assets/js/components/screens/search/SearchSongResultsScreen.spec.ts index 46fb532f..cab26eb2 100644 --- a/resources/assets/js/components/screens/search/SearchSongResultsScreen.spec.ts +++ b/resources/assets/js/components/screens/search/SearchSongResultsScreen.spec.ts @@ -1,9 +1,9 @@ import { expect, it } from 'vitest' import { searchStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import SearchSongResultsScreen from './SearchSongResultsScreen.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('searches for prop query on created', () => { const resetResultMock = this.mock(searchStore, 'resetSongResultState') diff --git a/resources/assets/js/components/song/AddToMenu.spec.ts b/resources/assets/js/components/song/AddToMenu.spec.ts index e0e1d308..3940395e 100644 --- a/resources/assets/js/components/song/AddToMenu.spec.ts +++ b/resources/assets/js/components/song/AddToMenu.spec.ts @@ -2,7 +2,7 @@ import { clone } from 'lodash' import { expect, it } from 'vitest' import factory from '@/__tests__/factory' import { favoriteStore, playlistStore, queueStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import Btn from '@/components/ui/Btn.vue' import AddToMenu from './AddToMenu.vue' import { arrayify } from '@/utils' @@ -17,7 +17,7 @@ const config: AddToMenuConfig = { newPlaylist: true } -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent (customConfig: Partial = {}) { songs = factory('song', 5) diff --git a/resources/assets/js/components/song/SongCard.spec.ts b/resources/assets/js/components/song/SongCard.spec.ts index a87f7327..e0342c9c 100644 --- a/resources/assets/js/components/song/SongCard.spec.ts +++ b/resources/assets/js/components/song/SongCard.spec.ts @@ -3,12 +3,12 @@ import { queueStore } from '@/stores' import { playbackService } from '@/services' import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import SongCard from './SongCard.vue' let song: Song -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent (playbackState: PlaybackState = 'Stopped') { song = factory('song', { playbackState, diff --git a/resources/assets/js/components/song/SongLikeButton.spec.ts b/resources/assets/js/components/song/SongLikeButton.spec.ts index b2fbc8db..6be048db 100644 --- a/resources/assets/js/components/song/SongLikeButton.spec.ts +++ b/resources/assets/js/components/song/SongLikeButton.spec.ts @@ -2,10 +2,10 @@ import { expect, it } from 'vitest' import factory from '@/__tests__/factory' import { fireEvent } from '@testing-library/vue' import { favoriteStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import SongLikeButton from './SongLikeButton.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it.each<[boolean, string]>([ [true, 'btn-like-liked'], diff --git a/resources/assets/js/components/song/SongList.spec.ts b/resources/assets/js/components/song/SongList.spec.ts index 05c0ff5b..2ed51a03 100644 --- a/resources/assets/js/components/song/SongList.spec.ts +++ b/resources/assets/js/components/song/SongList.spec.ts @@ -3,12 +3,12 @@ import factory from '@/__tests__/factory' import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import { eventBus, noop } from '@/utils' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import SongList from './SongList.vue' let songs: Song[] -new class extends ComponentTestCase { +new class extends UnitTestCase { protected beforeEach () { // suppress the warning super.beforeEach(() => eventBus.on('SET_SELECTED_SONGS', noop)) diff --git a/resources/assets/js/components/song/SongListControls.spec.ts b/resources/assets/js/components/song/SongListControls.spec.ts index a5b8abaf..4b04fa2f 100644 --- a/resources/assets/js/components/song/SongListControls.spec.ts +++ b/resources/assets/js/components/song/SongListControls.spec.ts @@ -2,13 +2,13 @@ import { take } from 'lodash' import { expect, it } from 'vitest' import factory from '@/__tests__/factory' import { fireEvent } from '@testing-library/vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import SongListControls from './SongListControls.vue' import AddToMenu from '@/components/song/AddToMenu.vue' import Btn from '@/components/ui/Btn.vue' import BtnGroup from '@/components/ui/BtnGroup.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent (selectedSongCount = 1, config: Partial = {}) { const songs = factory('song', 5) diff --git a/resources/assets/js/components/song/SongListItem.spec.ts b/resources/assets/js/components/song/SongListItem.spec.ts index e3b216f2..b32f4d06 100644 --- a/resources/assets/js/components/song/SongListItem.spec.ts +++ b/resources/assets/js/components/song/SongListItem.spec.ts @@ -5,11 +5,11 @@ import { queueStore } from '@/stores' import { playbackService } from '@/services' import { fireEvent } from '@testing-library/vue' import SongListItem from './SongListItem.vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' let row: SongRow -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent (columns: SongListColumn[] = ['track', 'title', 'artist', 'album', 'length']) { row = { song: factory('song'), diff --git a/resources/assets/js/components/ui/AlbumArtOverlay.spec.ts b/resources/assets/js/components/ui/AlbumArtOverlay.spec.ts index 34aa3124..8485629c 100644 --- a/resources/assets/js/components/ui/AlbumArtOverlay.spec.ts +++ b/resources/assets/js/components/ui/AlbumArtOverlay.spec.ts @@ -1,12 +1,12 @@ import { expect, it } from 'vitest' import { albumStore } from '@/stores' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AlbumArtOverlay from './AlbumArtOverlay.vue' let album: Album -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent () { album = factory('album') diff --git a/resources/assets/js/components/ui/AlbumArtistThumbnail.spec.ts b/resources/assets/js/components/ui/AlbumArtistThumbnail.spec.ts index cdc6e183..d56dc7be 100644 --- a/resources/assets/js/components/ui/AlbumArtistThumbnail.spec.ts +++ b/resources/assets/js/components/ui/AlbumArtistThumbnail.spec.ts @@ -1,5 +1,5 @@ import { orderBy } from 'lodash' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import { playbackService } from '@/services' @@ -10,7 +10,7 @@ import Thumbnail from './AlbumArtistThumbnail.vue' let album: Album let artist: Artist -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderForAlbum () { album = factory('album', { name: 'IV', diff --git a/resources/assets/js/components/ui/AppleMusicButton.spec.ts b/resources/assets/js/components/ui/AppleMusicButton.spec.ts index 2d387244..08a0619f 100644 --- a/resources/assets/js/components/ui/AppleMusicButton.spec.ts +++ b/resources/assets/js/components/ui/AppleMusicButton.spec.ts @@ -1,8 +1,8 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import AppleMusicButton from './AppleMusicButton.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => { expect(this.render(AppleMusicButton, { diff --git a/resources/assets/js/components/ui/Btn.spec.ts b/resources/assets/js/components/ui/Btn.spec.ts index 0b2837dc..a9ccd93a 100644 --- a/resources/assets/js/components/ui/Btn.spec.ts +++ b/resources/assets/js/components/ui/Btn.spec.ts @@ -1,8 +1,8 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import Btn from './Btn.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => { expect(this.render(Btn, { diff --git a/resources/assets/js/components/ui/BtnCloseModal.spec.ts b/resources/assets/js/components/ui/BtnCloseModal.spec.ts index ba6027f9..0414d28e 100644 --- a/resources/assets/js/components/ui/BtnCloseModal.spec.ts +++ b/resources/assets/js/components/ui/BtnCloseModal.spec.ts @@ -1,9 +1,9 @@ import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import BtnCloseModal from './BtnCloseModal.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => expect(this.render(BtnCloseModal).html()).toMatchSnapshot()) diff --git a/resources/assets/js/components/ui/BtnGroup.spec.ts b/resources/assets/js/components/ui/BtnGroup.spec.ts index ae00f142..1498e79c 100644 --- a/resources/assets/js/components/ui/BtnGroup.spec.ts +++ b/resources/assets/js/components/ui/BtnGroup.spec.ts @@ -1,9 +1,9 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import BtnGroup from './BtnGroup.vue' import Btn from './Btn.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderButtonToSlot (text: string) { return this.render(Btn, { slots: { diff --git a/resources/assets/js/components/ui/BtnScrollToTop.spec.ts b/resources/assets/js/components/ui/BtnScrollToTop.spec.ts index 8c581213..9349c62f 100644 --- a/resources/assets/js/components/ui/BtnScrollToTop.spec.ts +++ b/resources/assets/js/components/ui/BtnScrollToTop.spec.ts @@ -1,10 +1,10 @@ import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import { $ } from '@/utils' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import BtnScrollToTop from './BtnScrollToTop.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => { expect(this.render(BtnScrollToTop).html()).toMatchSnapshot() diff --git a/resources/assets/js/components/ui/LyricsPane.spec.ts b/resources/assets/js/components/ui/LyricsPane.spec.ts index a98788dc..cf55dbd4 100644 --- a/resources/assets/js/components/ui/LyricsPane.spec.ts +++ b/resources/assets/js/components/ui/LyricsPane.spec.ts @@ -1,12 +1,12 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import factory from '@/__tests__/factory' import { eventBus } from '@/utils' import { fireEvent } from '@testing-library/vue' import LyricsPane from './LyricsPane.vue' import TextMagnifier from '@/components/ui/TextMagnifier.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent (song?: Song) { song = song || factory('song', { lyrics: 'Foo bar baz qux' diff --git a/resources/assets/js/components/ui/Overlay.spec.ts b/resources/assets/js/components/ui/Overlay.spec.ts index fc359dc6..0193c21e 100644 --- a/resources/assets/js/components/ui/Overlay.spec.ts +++ b/resources/assets/js/components/ui/Overlay.spec.ts @@ -1,11 +1,11 @@ -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import { expect, it } from 'vitest' import { OverlayState } from 'koel/types/ui' import { eventBus } from '@/utils' import Overlay from './Overlay.vue' import SoundBar from '@/components/ui/SoundBar.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { private async showOverlay (type: OverlayState['type'] = 'loading') { const rendered = this.render(Overlay, { global: { diff --git a/resources/assets/js/components/ui/RepeatModeSwitch.spec.ts b/resources/assets/js/components/ui/RepeatModeSwitch.spec.ts index 13d93759..86211c0d 100644 --- a/resources/assets/js/components/ui/RepeatModeSwitch.spec.ts +++ b/resources/assets/js/components/ui/RepeatModeSwitch.spec.ts @@ -1,11 +1,11 @@ import { expect, it } from 'vitest' import { preferenceStore } from '@/stores' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import RepeatModeSwitch from './RepeatModeSwitch.vue' import { fireEvent } from '@testing-library/vue' import { playbackService } from '@/services' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('changes mode', async () => { const mock = this.mock(playbackService, 'changeRepeatMode') diff --git a/resources/assets/js/components/ui/ScreenControlsToggler.spec.ts b/resources/assets/js/components/ui/ScreenControlsToggler.spec.ts index 25c85325..09f96997 100644 --- a/resources/assets/js/components/ui/ScreenControlsToggler.spec.ts +++ b/resources/assets/js/components/ui/ScreenControlsToggler.spec.ts @@ -1,10 +1,10 @@ import isMobile from 'ismobilejs' import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ScreenControlsToggler from './ScreenControlsToggler.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders and emits an event on mobile', async () => { isMobile.phone = true diff --git a/resources/assets/js/components/ui/ScreenEmptyState.spec.ts b/resources/assets/js/components/ui/ScreenEmptyState.spec.ts index 9ff70bf9..ff8913d7 100644 --- a/resources/assets/js/components/ui/ScreenEmptyState.spec.ts +++ b/resources/assets/js/components/ui/ScreenEmptyState.spec.ts @@ -1,8 +1,8 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ScreenEmptyState from './ScreenEmptyState.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => { expect(this.render(ScreenEmptyState, { diff --git a/resources/assets/js/components/ui/ScreenHeader.spec.ts b/resources/assets/js/components/ui/ScreenHeader.spec.ts index 6095ea63..f535c04e 100644 --- a/resources/assets/js/components/ui/ScreenHeader.spec.ts +++ b/resources/assets/js/components/ui/ScreenHeader.spec.ts @@ -1,8 +1,8 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ScreenHeader from './ScreenHeader.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('renders', () => { expect(this.render(ScreenHeader, { diff --git a/resources/assets/js/components/ui/SearchForm.spec.ts b/resources/assets/js/components/ui/SearchForm.spec.ts index d142faa2..6e41edb0 100644 --- a/resources/assets/js/components/ui/SearchForm.spec.ts +++ b/resources/assets/js/components/ui/SearchForm.spec.ts @@ -1,11 +1,11 @@ import { expect, it, vi } from 'vitest' import router from '@/router' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import SearchForm from './SearchForm.vue' import { fireEvent } from '@testing-library/vue' import { eventBus } from '@/utils' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { // skipping because of unstable getRootNode() issues it.skip('sets focus into search box when requested', async () => { diff --git a/resources/assets/js/components/ui/ViewModeSwitch.spec.ts b/resources/assets/js/components/ui/ViewModeSwitch.spec.ts index 6d6f9b46..659b3c73 100644 --- a/resources/assets/js/components/ui/ViewModeSwitch.spec.ts +++ b/resources/assets/js/components/ui/ViewModeSwitch.spec.ts @@ -1,8 +1,8 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import ViewModeSwitch from './ViewModeSwitch.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it.each<[ArtistAlbumViewMode]>([['thumbnails'], ['list']])('renders %s mode', mode => { expect(this.render(ViewModeSwitch, { diff --git a/resources/assets/js/components/ui/Volume.spec.ts b/resources/assets/js/components/ui/Volume.spec.ts index 0739bd86..22135bbd 100644 --- a/resources/assets/js/components/ui/Volume.spec.ts +++ b/resources/assets/js/components/ui/Volume.spec.ts @@ -1,10 +1,10 @@ import { expect, it } from 'vitest' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import { fireEvent } from '@testing-library/vue' import { playbackService, socketService } from '@/services' import Volume from './Volume.vue' -new class extends ComponentTestCase { +new class extends UnitTestCase { protected test () { it('mutes and unmutes', async () => { const muteMock = this.mock(playbackService, 'mute') diff --git a/resources/assets/js/components/ui/YouTubeVideoItem.spec.ts b/resources/assets/js/components/ui/YouTubeVideoItem.spec.ts index 2b7fb208..e2c28bb6 100644 --- a/resources/assets/js/components/ui/YouTubeVideoItem.spec.ts +++ b/resources/assets/js/components/ui/YouTubeVideoItem.spec.ts @@ -1,12 +1,12 @@ import { expect, it } from 'vitest' import { fireEvent } from '@testing-library/vue' import { youTubeService } from '@/services' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import YouTubeVideoItem from './YouTubeVideoItem.vue' let video: YouTubeVideo -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent () { video = { id: { diff --git a/resources/assets/js/components/ui/YouTubeVideoList.spec.ts b/resources/assets/js/components/ui/YouTubeVideoList.spec.ts index a65a863c..8719d553 100644 --- a/resources/assets/js/components/ui/YouTubeVideoList.spec.ts +++ b/resources/assets/js/components/ui/YouTubeVideoList.spec.ts @@ -1,6 +1,6 @@ import { expect, it } from 'vitest' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import YouTubeVideoList from './YouTubeVideoList.vue' import Btn from '@/components/ui/Btn.vue' import YouTubeVideo from '@/components/ui/YouTubeVideoItem.vue' @@ -9,7 +9,7 @@ import { fireEvent } from '@testing-library/vue' let song: Song -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent () { song = factory('song', { youtube: { diff --git a/resources/assets/js/components/ui/upload/UploadItem.spec.ts b/resources/assets/js/components/ui/upload/UploadItem.spec.ts index 7539c5a9..47459fe0 100644 --- a/resources/assets/js/components/ui/upload/UploadItem.spec.ts +++ b/resources/assets/js/components/ui/upload/UploadItem.spec.ts @@ -1,6 +1,6 @@ import { expect, it } from 'vitest' import { UploadFile, UploadStatus } from '@/config' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import { fireEvent } from '@testing-library/vue' import { uploadService } from '@/services' import Btn from '@/components/ui/Btn.vue' @@ -8,7 +8,7 @@ import UploadItem from './UploadItem.vue' let file: UploadFile -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent (status: UploadStatus) { file = { status, diff --git a/resources/assets/js/components/user/UserCard.spec.ts b/resources/assets/js/components/user/UserCard.spec.ts index 2b0f9ca9..433207b1 100644 --- a/resources/assets/js/components/user/UserCard.spec.ts +++ b/resources/assets/js/components/user/UserCard.spec.ts @@ -1,12 +1,12 @@ import { expect, it } from 'vitest' import factory from '@/__tests__/factory' -import ComponentTestCase from '@/__tests__/ComponentTestCase' +import UnitTestCase from '@/__tests__/UnitTestCase' import UserCard from './UserCard.vue' import Btn from '@/components/ui/Btn.vue' import { fireEvent } from '@testing-library/vue' import router from '@/router' -new class extends ComponentTestCase { +new class extends UnitTestCase { private renderComponent (user: User) { return this.render(UserCard, { props: { diff --git a/resources/assets/js/services/downloadService.spec.ts b/resources/assets/js/services/downloadService.spec.ts new file mode 100644 index 00000000..b3eddfcd --- /dev/null +++ b/resources/assets/js/services/downloadService.spec.ts @@ -0,0 +1,63 @@ +import { favoriteStore, playlistStore } from '@/stores' +import factory from '@/__tests__/factory' +import { expect, it } from 'vitest' +import UnitTestCase from '@/__tests__/UnitTestCase' +import { downloadService } from './downloadService' + +new class extends UnitTestCase { + protected test () { + it('downloads songs', () => { + const mock = this.mock(downloadService, 'trigger') + downloadService.fromSongs([factory('song', { id: 'foo' }), factory('song', { id: 'bar' })]) + + expect(mock).toHaveBeenCalledWith('songs?songs[]=bar&songs[]=foo&') + }) + + it('downloads all by artist', () => { + const mock = this.mock(downloadService, 'trigger') + downloadService.fromArtist(factory('artist', { id: 42 })) + + expect(mock).toHaveBeenCalledWith('artist/42') + }) + + it('downloads all in album', () => { + const mock = this.mock(downloadService, 'trigger') + downloadService.fromAlbum(factory('album', { id: 42 })) + + expect(mock).toHaveBeenCalledWith('album/42') + }) + + it('downloads a playlist', () => { + const getSongsMock = this.mock(playlistStore, 'getSongs', factory('song', 5)) + const mock = this.mock(downloadService, 'trigger') + const playlist = factory('playlist', { id: 42 }) + + downloadService.fromPlaylist(playlist) + + expect(getSongsMock).toHaveBeenCalledWith(playlist) + expect(mock).toHaveBeenCalledWith('playlist/42') + }) + + it('does not download an empty playlist', () => { + const getSongsMock = this.mock(playlistStore, 'getSongs', []) + const triggerMock = this.mock(downloadService, 'trigger') + const playlist = factory('playlist') + + downloadService.fromPlaylist(playlist) + + expect(getSongsMock).toHaveBeenCalledWith(playlist) + expect(triggerMock).not.toHaveBeenCalled() + }) + + it.each<[Song[], boolean]>([[[], false], [factory('song', 5), true]])( + 'downloads favorites if available', + (songs, triggered) => { + const mock = this.mock(downloadService, 'trigger') + favoriteStore.all = songs + + downloadService.fromFavorites() + + triggered ? expect(mock).toHaveBeenCalledWith('favorites') : expect(mock).not.toHaveBeenCalled() + }) + } +} diff --git a/resources/assets/js/services/downloadService.ts b/resources/assets/js/services/downloadService.ts index 409ba440..f0622ecf 100644 --- a/resources/assets/js/services/downloadService.ts +++ b/resources/assets/js/services/downloadService.ts @@ -3,26 +3,26 @@ import { authService } from '.' import { arrayify } from '@/utils' export const downloadService = { - fromSongs (songs: Song | Song[]): void { + fromSongs (songs: Song | Song[]) { const query = arrayify(songs).reduce((q, song) => `songs[]=${song.id}&${q}`, '') this.trigger(`songs?${query}`) }, - fromAlbum (album: Album): void { + fromAlbum (album: Album) { this.trigger(`album/${album.id}`) }, - fromArtist (artist: Artist): void { + fromArtist (artist: Artist) { this.trigger(`artist/${artist.id}`) }, - fromPlaylist (playlist: Playlist): void { + fromPlaylist (playlist: Playlist) { if (playlistStore.getSongs(playlist).length) { this.trigger(`playlist/${playlist.id}`) } }, - fromFavorites (): void { + fromFavorites () { if (favoriteStore.all.length) { this.trigger('favorites') } diff --git a/resources/assets/js/services/localStorageService.spec.ts b/resources/assets/js/services/localStorageService.spec.ts new file mode 100644 index 00000000..c2ff1b69 --- /dev/null +++ b/resources/assets/js/services/localStorageService.spec.ts @@ -0,0 +1,30 @@ +import { get, remove, set } from 'local-storage' +import { expect, it } from 'vitest' +import UnitTestCase from '@/__tests__/UnitTestCase' +import { localStorageService } from './localStorageService' + +new class extends UnitTestCase { + protected test () { + it('gets an existing item from local storage', () => { + set('foo', 'bar') + expect(localStorageService.get('foo')).toBe('bar') + }) + + it('returns the default value for a non exising item', () => { + remove('foo') + expect(localStorageService.get('foo', 42)).toBe(42) + }) + + it('sets an item into local storage', () => { + remove('foo') + localStorageService.set('foo', 42) + expect(get('foo')).toBe(42) + }) + + it('correctly removes an item from local storage', () => { + set('foo', 42) + localStorageService.remove('foo') + expect(get('foo')).toBeNull() + }) + } +} diff --git a/resources/assets/js/services/youTubeService.spec.ts b/resources/assets/js/services/youTubeService.spec.ts new file mode 100644 index 00000000..5c5d42f0 --- /dev/null +++ b/resources/assets/js/services/youTubeService.spec.ts @@ -0,0 +1,29 @@ +import { eventBus } from '@/utils' +import router from '@/router' +import factory from '@/__tests__/factory' +import { expect, it } from 'vitest' +import UnitTestCase from '@/__tests__/UnitTestCase' +import { youTubeService } from './youTubeService' + +new class extends UnitTestCase { + protected test () { + it('plays a video', () => { + const video = factory('video', { + id: { + videoId: 'foo' + }, + snippet: { + title: 'Bar' + } + }) + + const emitMock = this.mock(eventBus, 'emit') + const goMock = this.mock(router, 'go') + + youTubeService.play(video) + + expect(emitMock).toHaveBeenCalledWith('PLAY_YOUTUBE_VIDEO', { id: 'foo', title: 'Bar' }) + expect(goMock).toHaveBeenCalledWith('youtube') + }) + } +}