2022-07-23 11:07:14 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { reactive } from 'vue'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-09-15 09:07:25 +00:00
|
|
|
import { http } from '@/services'
|
2022-09-14 16:45:08 +00:00
|
|
|
import { albumStore, artistStore, ExcerptSearchResult, searchStore, songStore } from '.'
|
2022-07-23 11:07:14 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected beforeEach () {
|
|
|
|
super.beforeEach(() => {
|
|
|
|
searchStore.state = reactive({
|
|
|
|
excerpt: {
|
2024-05-19 05:49:42 +00:00
|
|
|
playables: [],
|
2022-07-23 11:07:14 +00:00
|
|
|
albums: [],
|
|
|
|
artists: []
|
|
|
|
},
|
2024-05-19 05:49:42 +00:00
|
|
|
playables: []
|
2022-07-23 11:07:14 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('performs an excerpt search', async () => {
|
|
|
|
const result: ExcerptSearchResult = {
|
2024-06-01 18:02:27 +00:00
|
|
|
playables: factory('song', 3),
|
|
|
|
albums: factory('album', 3),
|
|
|
|
artists: factory('artist', 3)
|
2022-07-23 11:07:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-15 09:07:25 +00:00
|
|
|
const getMock = this.mock(http, 'get').mockResolvedValue(result)
|
2022-07-23 11:07:14 +00:00
|
|
|
const syncSongsMock = this.mock(songStore, 'syncWithVault', result.songs)
|
|
|
|
const syncAlbumsMock = this.mock(albumStore, 'syncWithVault', result.albums)
|
|
|
|
const syncArtistsMock = this.mock(artistStore, 'syncWithVault', result.artists)
|
|
|
|
|
|
|
|
await searchStore.excerptSearch('test')
|
|
|
|
|
|
|
|
expect(getMock).toHaveBeenCalledWith('search?q=test')
|
|
|
|
expect(syncSongsMock).toHaveBeenCalledWith(result.songs)
|
|
|
|
expect(syncAlbumsMock).toHaveBeenCalledWith(result.albums)
|
|
|
|
expect(syncArtistsMock).toHaveBeenCalledWith(result.artists)
|
|
|
|
|
|
|
|
expect(searchStore.state.excerpt.songs).toEqual(result.songs)
|
|
|
|
expect(searchStore.state.excerpt.albums).toEqual(result.albums)
|
|
|
|
expect(searchStore.state.excerpt.artists).toEqual(result.artists)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('performs a song search', async () => {
|
2024-06-01 18:02:27 +00:00
|
|
|
const songs = factory('song', 3)
|
2022-07-23 11:07:14 +00:00
|
|
|
|
2022-09-15 09:07:25 +00:00
|
|
|
const getMock = this.mock(http, 'get').mockResolvedValue(songs)
|
2022-07-23 11:07:14 +00:00
|
|
|
const syncMock = this.mock(songStore, 'syncWithVault', songs)
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
await searchStore.playableSearch('test')
|
2022-07-23 11:07:14 +00:00
|
|
|
|
|
|
|
expect(getMock).toHaveBeenCalledWith('search/songs?q=test')
|
|
|
|
expect(syncMock).toHaveBeenCalledWith(songs)
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
expect(searchStore.state.playables).toEqual(songs)
|
2022-07-23 11:07:14 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('resets the song result state', () => {
|
2024-06-02 17:15:31 +00:00
|
|
|
searchStore.state.playables = factory('song', 3)
|
|
|
|
searchStore.resetPlayableResultState()
|
|
|
|
expect(searchStore.state.playables).toEqual([])
|
2022-07-23 11:07:14 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|