2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-12 08:37:11 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { favoriteStore } from '@/stores'
|
|
|
|
import FavoritesScreen from './FavoritesScreen.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
|
|
|
it('renders a list of favorites', async () => {
|
2022-09-12 11:11:56 +00:00
|
|
|
favoriteStore.state.songs = factory<Song>('song', 13)
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-12 08:37:11 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('screen-empty-state')).toBeNull()
|
|
|
|
screen.getByTestId('song-list')
|
2022-07-12 08:37:11 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows empty state', async () => {
|
|
|
|
favoriteStore.state.songs = []
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-12 08:37:11 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
screen.getByTestId('screen-empty-state')
|
|
|
|
expect(screen.queryByTestId('song-list')).toBeNull()
|
2022-07-12 08:37:11 +00:00
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private async renderComponent () {
|
|
|
|
const fetchMock = this.mock(favoriteStore, 'fetch')
|
|
|
|
this.render(FavoritesScreen)
|
|
|
|
|
|
|
|
await this.router.activateRoute({ path: 'favorites', screen: 'Favorites' })
|
|
|
|
|
|
|
|
await waitFor(() => expect(fetchMock).toHaveBeenCalled())
|
|
|
|
}
|
2022-07-12 08:37:11 +00:00
|
|
|
}
|