mirror of
https://github.com/koel/koel
synced 2024-11-10 14:44:13 +00:00
feat(test): add RecentlyPlayed tests
This commit is contained in:
parent
b4754e0428
commit
c7d7ae6efe
6 changed files with 48 additions and 12 deletions
|
@ -27,7 +27,7 @@ new class extends UnitTestCase {
|
|||
},
|
||||
global: {
|
||||
stubs: {
|
||||
'TrackList': this.stub()
|
||||
TrackList: this.stub()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { expect, it } from 'vitest'
|
||||
import factory from '@/__tests__/factory'
|
||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||
import AllSongsScreen from './AllSongsScreen.vue'
|
||||
import { commonStore, queueStore, songStore } from '@/stores'
|
||||
import { fireEvent, waitFor } from '@testing-library/vue'
|
||||
import { eventBus } from '@/utils'
|
||||
import { playbackService } from '@/services'
|
||||
import router from '@/router'
|
||||
import AllSongsScreen from './AllSongsScreen.vue'
|
||||
|
||||
new class extends UnitTestCase {
|
||||
private async renderComponent () {
|
||||
|
|
|
@ -2,9 +2,9 @@ import { expect, it } from 'vitest'
|
|||
import factory from '@/__tests__/factory'
|
||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||
import { artistStore, preferenceStore } from '@/stores'
|
||||
import ArtistListScreen from './ArtistListScreen.vue'
|
||||
import { eventBus } from '@/utils'
|
||||
import { fireEvent, waitFor } from '@testing-library/vue'
|
||||
import ArtistListScreen from './ArtistListScreen.vue'
|
||||
|
||||
new class extends UnitTestCase {
|
||||
protected beforeEach () {
|
||||
|
|
|
@ -2,9 +2,9 @@ import { expect, it } from 'vitest'
|
|||
import factory from '@/__tests__/factory'
|
||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||
import { commonStore, queueStore } from '@/stores'
|
||||
import QueueScreen from './QueueScreen.vue'
|
||||
import { fireEvent, waitFor } from '@testing-library/vue'
|
||||
import { playbackService } from '@/services'
|
||||
import QueueScreen from './QueueScreen.vue'
|
||||
|
||||
new class extends UnitTestCase {
|
||||
private renderComponent (songs: Song[]) {
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import { expect, it } from 'vitest'
|
||||
import factory from '@/__tests__/factory'
|
||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||
import { recentlyPlayedStore } from '@/stores'
|
||||
import { eventBus } from '@/utils'
|
||||
import { waitFor } from '@testing-library/vue'
|
||||
import RecentlyPlayedScreen from './RecentlyPlayedScreen.vue'
|
||||
|
||||
new class extends UnitTestCase {
|
||||
private async renderComponent (songs: Song[]) {
|
||||
recentlyPlayedStore.state.songs = songs
|
||||
const fetchMock = this.mock(recentlyPlayedStore, 'fetch')
|
||||
|
||||
const rendered = this.render(RecentlyPlayedScreen, {
|
||||
global: {
|
||||
stubs: {
|
||||
SongList: this.stub('song-list')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
eventBus.emit('LOAD_MAIN_CONTENT', 'RecentlyPlayed')
|
||||
|
||||
await waitFor(() => expect(fetchMock).toHaveBeenCalled())
|
||||
|
||||
return rendered
|
||||
}
|
||||
|
||||
protected test () {
|
||||
it('displays the songs', async () => {
|
||||
const { queryByTestId } = await this.renderComponent(factory<Song[]>('song', 3))
|
||||
|
||||
expect(queryByTestId('song-list')).toBeTruthy()
|
||||
expect(queryByTestId('screen-empty-state')).toBeNull()
|
||||
})
|
||||
|
||||
it('displays the empty state', async () => {
|
||||
const { queryByTestId } = await this.renderComponent([])
|
||||
|
||||
expect(queryByTestId('song-list')).toBeNull()
|
||||
expect(queryByTestId('screen-empty-state')).toBeTruthy()
|
||||
})
|
||||
}
|
||||
}
|
|
@ -65,11 +65,3 @@ eventBus.on({
|
|||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
#recentlyPlayedWrapper {
|
||||
.none {
|
||||
padding: 16px 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Reference in a new issue