2022-10-21 20:06:43 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2023-12-28 22:32:58 +00:00
|
|
|
import { commonStore, genreStore } from '@/stores'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-10-21 20:06:43 +00:00
|
|
|
import GenreListScreen from './GenreListScreen.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
|
|
|
it('renders the list of genres and their song counts', async () => {
|
|
|
|
// ensure there's no duplicated names
|
|
|
|
const genres = [
|
2024-06-01 18:02:27 +00:00
|
|
|
factory('genre', { name: 'Rock', song_count: 10 }),
|
|
|
|
factory('genre', { name: 'Pop', song_count: 20 }),
|
2024-10-13 17:37:01 +00:00
|
|
|
factory('genre', { name: 'Jazz', song_count: 30 }),
|
2022-10-21 20:06:43 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
const fetchMock = this.mock(genreStore, 'fetchAll').mockResolvedValue(genres)
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(GenreListScreen)
|
2022-10-21 20:06:43 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchMock).toHaveBeenCalled()
|
2022-11-29 10:18:58 +00:00
|
|
|
genres.forEach(genre => screen.getByTitle(`${genre.name}: ${genre.song_count} songs`))
|
2022-10-21 20:06:43 +00:00
|
|
|
})
|
|
|
|
})
|
2023-12-28 22:32:58 +00:00
|
|
|
|
|
|
|
it('shows a message when the library is empty', async () => {
|
|
|
|
commonStore.state.song_length = 0
|
|
|
|
const fetchMock = this.mock(genreStore, 'fetchAll')
|
|
|
|
|
|
|
|
this.render(GenreListScreen)
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(fetchMock).not.toHaveBeenCalled()
|
|
|
|
screen.getByTestId('screen-empty-state')
|
|
|
|
})
|
|
|
|
})
|
2022-10-21 20:06:43 +00:00
|
|
|
}
|
|
|
|
}
|