2022-07-10 17:15:56 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-07-11 17:30:51 +00:00
|
|
|
import { albumStore, preferenceStore } from '@/stores'
|
|
|
|
import { fireEvent, waitFor } from '@testing-library/vue'
|
2022-07-10 17:15:56 +00:00
|
|
|
import AlbumListScreen from './AlbumListScreen.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
2022-07-11 17:30:51 +00:00
|
|
|
protected beforeEach () {
|
2022-07-22 21:56:13 +00:00
|
|
|
super.beforeEach(() => this.mock(albumStore, '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
|
|
|
albumStore.state.albums = factory<Album>('album', 9)
|
2022-10-08 10:54:25 +00:00
|
|
|
const rendered = this.render(AlbumListScreen)
|
|
|
|
await this.router.activateRoute({ path: 'albums', screen: 'Albums' })
|
|
|
|
return rendered
|
2022-07-11 17:30:51 +00:00
|
|
|
}
|
|
|
|
|
2022-07-10 17:15:56 +00:00
|
|
|
protected test () {
|
2022-10-08 10:54:25 +00:00
|
|
|
it('renders', async () => {
|
|
|
|
const { getAllByTestId } = await this.renderComponent()
|
|
|
|
expect(getAllByTestId('album-card')).toHaveLength(9)
|
2022-07-11 17:30:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it.each<[ArtistAlbumViewMode]>([['list'], ['thumbnails']])('sets layout from preferences', async (mode) => {
|
|
|
|
preferenceStore.albumsViewMode = mode
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
const { getByTestId } = await this.renderComponent()
|
2022-07-11 17:30:51 +00:00
|
|
|
|
|
|
|
await waitFor(() => expect(getByTestId('album-list').classList.contains(`as-${mode}`)).toBe(true))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('switches layout', async () => {
|
2022-10-08 10:54:25 +00:00
|
|
|
const { getByTestId, getByTitle } = await this.renderComponent()
|
2022-07-11 17:30:51 +00:00
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('View as list'))
|
|
|
|
await waitFor(() => expect(getByTestId('album-list').classList.contains(`as-list`)).toBe(true))
|
2022-07-10 17:15:56 +00:00
|
|
|
|
2022-07-11 17:30:51 +00:00
|
|
|
await fireEvent.click(getByTitle('View as thumbnails'))
|
|
|
|
await waitFor(() => expect(getByTestId('album-list').classList.contains(`as-thumbnails`)).toBe(true))
|
2022-07-10 17:15:56 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|