koel/resources/assets/js/components/screens/ArtistListScreen.spec.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

import { ref } from 'vue'
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'
import { fireEvent, waitFor } from '@testing-library/vue'
import { ActiveScreenKey } from '@/symbols'
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
}
private renderComponent () {
artistStore.state.artists = factory<Artist>('artist', 9)
return this.render(ArtistListScreen, {
global: {
provide: {
[<symbol>ActiveScreenKey]: ref('Artists')
}
}
})
2022-07-11 17:30:51 +00:00
}
protected test () {
it('renders', () => {
expect(this.renderComponent().getAllByTestId('artist-card')).toHaveLength(9)
})
it.each<[ArtistAlbumViewMode]>([['list'], ['thumbnails']])('sets layout:%s from preferences', async (mode) => {
2022-07-11 17:30:51 +00:00
preferenceStore.artistsViewMode = mode
2022-09-14 16:45:08 +00:00
const { getByTestId } = this.renderComponent()
2022-07-11 17:30:51 +00:00
await waitFor(() => expect(getByTestId('artist-list').classList.contains(`as-${mode}`)).toBe(true))
})
it('switches layout', async () => {
const { getByTestId, getByTitle } = this.renderComponent()
await fireEvent.click(getByTitle('View as list'))
await waitFor(() => expect(getByTestId('artist-list').classList.contains(`as-list`)).toBe(true))
await fireEvent.click(getByTitle('View as thumbnails'))
await waitFor(() => expect(getByTestId('artist-list').classList.contains(`as-thumbnails`)).toBe(true))
})
}
}