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'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-13 09:49:46 +00:00
|
|
|
import RecentlyPlayedScreen from './RecentlyPlayedScreen.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private async renderComponent (songs: Song[]) {
|
|
|
|
recentlyPlayedStore.state.songs = songs
|
|
|
|
const fetchMock = this.mock(recentlyPlayedStore, 'fetch')
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(RecentlyPlayedScreen, {
|
2022-07-13 09:49:46 +00:00
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
SongList: this.stub('song-list')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
await this.router.activateRoute({ path: 'recently-played', screen: 'RecentlyPlayed' })
|
|
|
|
|
2022-07-13 09:49:46 +00:00
|
|
|
await waitFor(() => expect(fetchMock).toHaveBeenCalled())
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('displays the songs', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent(factory<Song>('song', 3))
|
2022-07-13 09:49:46 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
screen.getByTestId('song-list')
|
|
|
|
expect(screen.queryByTestId('screen-empty-state')).toBeNull()
|
2022-07-13 09:49:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('displays the empty state', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent([])
|
2022-07-13 09:49:46 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('song-list')).toBeNull()
|
|
|
|
screen.getByTestId('screen-empty-state')
|
2022-07-13 09:49:46 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|