2022-07-11 17:30:51 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { artistStore, preferenceStore } 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 ArtistListScreen from './ArtistListScreen.vue'
|
2022-07-11 17:30:51 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected beforeEach () {
|
2022-07-22 22:03:25 +00:00
|
|
|
super.beforeEach(() => this.mock(artistStore, 'paginate'))
|
2022-07-11 17:30:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
private async renderComponent () {
|
2022-09-12 15:33:41 +00:00
|
|
|
artistStore.state.artists = factory<Artist>('artist', 9)
|
2022-10-23 17:52:07 +00:00
|
|
|
|
|
|
|
const rendered = this.render(ArtistListScreen, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
ArtistCard: this.stub('artist-card')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
await this.router.activateRoute({ path: 'artists', screen: 'Artists' })
|
|
|
|
return rendered
|
2022-07-11 17:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-10-08 10:54:25 +00:00
|
|
|
it('renders', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
|
|
|
expect(screen.getAllByTestId('artist-card')).toHaveLength(9)
|
2022-07-11 17:30:51 +00:00
|
|
|
})
|
|
|
|
|
2022-09-12 15:33:41 +00:00
|
|
|
it.each<[ArtistAlbumViewMode]>([['list'], ['thumbnails']])('sets layout:%s from preferences', async (mode) => {
|
2022-07-11 17:30:51 +00:00
|
|
|
preferenceStore.artistsViewMode = mode
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-11 17:30:51 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await waitFor(() => expect(screen.getByTestId('artist-list').classList.contains(`as-${mode}`)).toBe(true))
|
2022-07-11 17:30:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('switches layout', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-11 17:30:51 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('radio', { name: 'View as list' }))
|
|
|
|
await waitFor(() => expect(screen.getByTestId('artist-list').classList.contains(`as-list`)).toBe(true))
|
2022-07-11 17:30:51 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('radio', { name: 'View as thumbnails' }))
|
|
|
|
await waitFor(() => expect(screen.getByTestId('artist-list').classList.contains(`as-thumbnails`)).toBe(true))
|
2022-07-11 17:30:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|