koel/resources/assets/js/components/screens/RecentlyPlayedScreen.spec.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-07-13 09:49:46 +00:00
import { expect, it } from 'vitest'
import factory from '@/__tests__/factory'
import UnitTestCase from '@/__tests__/UnitTestCase'
import { recentlyPlayedStore } from '@/stores'
import { screen, waitFor } from '@testing-library/vue'
2022-07-13 09:49:46 +00:00
import RecentlyPlayedScreen from './RecentlyPlayedScreen.vue'
new class extends UnitTestCase {
2024-04-23 21:01:27 +00:00
protected test () {
it('displays the songs', async () => {
await this.renderComponent(factory('song', 3))
2024-04-23 21:01:27 +00:00
screen.getByTestId('song-list')
expect(screen.queryByTestId('screen-empty-state')).toBeNull()
})
it('displays the empty state', async () => {
await this.renderComponent([])
expect(screen.queryByTestId('song-list')).toBeNull()
screen.getByTestId('screen-empty-state')
})
}
private async renderComponent (playables: Playable[]) {
recentlyPlayedStore.state.playables = playables
2022-07-13 09:49:46 +00:00
const fetchMock = this.mock(recentlyPlayedStore, 'fetch')
this.render(RecentlyPlayedScreen, {
2022-07-13 09:49:46 +00:00
global: {
stubs: {
SongList: this.stub('song-list')
}
}
})
await this.router.activateRoute({ path: 'recently-played', screen: 'RecentlyPlayed' })
2022-07-13 09:49:46 +00:00
await waitFor(() => expect(fetchMock).toHaveBeenCalled())
}
}