2022-09-12 15:33:41 +00:00
|
|
|
import { ref } from 'vue'
|
2022-07-12 08:37:11 +00:00
|
|
|
import { waitFor } from '@testing-library/vue'
|
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { favoriteStore } from '@/stores'
|
2022-09-12 15:33:41 +00:00
|
|
|
import { ActiveScreenKey } from '@/symbols'
|
2022-07-12 08:37:11 +00:00
|
|
|
import FavoritesScreen from './FavoritesScreen.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private async renderComponent () {
|
|
|
|
const fetchMock = this.mock(favoriteStore, 'fetch')
|
2022-09-12 15:33:41 +00:00
|
|
|
const rendered = this.render(FavoritesScreen, {
|
|
|
|
global: {
|
|
|
|
provide: {
|
|
|
|
[<symbol>ActiveScreenKey]: ref('Favorites')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-07-12 08:37:11 +00:00
|
|
|
|
|
|
|
await waitFor(() => expect(fetchMock).toHaveBeenCalled())
|
|
|
|
|
|
|
|
return rendered
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07-12 08:37:11 +00:00
|
|
|
const { queryByTestId } = await this.renderComponent()
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(queryByTestId('screen-empty-state')).toBeNull()
|
|
|
|
expect(queryByTestId('song-list')).not.toBeNull()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows empty state', async () => {
|
|
|
|
favoriteStore.state.songs = []
|
|
|
|
const { queryByTestId } = await this.renderComponent()
|
|
|
|
|
|
|
|
expect(queryByTestId('screen-empty-state')).not.toBeNull()
|
|
|
|
expect(queryByTestId('song-list')).toBeNull()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|