2022-07-10 17:15:56 +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 { albumStore, commonStore, preferenceStore } from '@/stores'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, 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-07-10 17:15:56 +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('album-card')).toHaveLength(9)
|
2022-07-11 17:30:51 +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
|
|
|
|
await this.renderComponent()
|
|
|
|
|
|
|
|
await waitFor(() => screen.getByTestId('screen-empty-state'))
|
|
|
|
})
|
|
|
|
|
2024-10-13 17:37:01 +00:00
|
|
|
it.each<[ArtistAlbumViewMode]>([['list'], ['thumbnails']])('sets layout from preferences', async mode => {
|
2024-01-23 22:50:50 +00:00
|
|
|
preferenceStore.albums_view_mode = mode
|
2022-07-11 17:30:51 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-11 17:30:51 +00:00
|
|
|
|
2024-04-22 21:04:03 +00:00
|
|
|
await waitFor(() => expect(screen.getByTestId('album-grid').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' }))
|
2024-04-22 21:04:03 +00:00
|
|
|
await waitFor(() => expect(screen.getByTestId('album-grid').classList.contains(`as-list`)).toBe(true))
|
2022-07-10 17:15:56 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('radio', { name: 'View as thumbnails' }))
|
2024-04-22 21:04:03 +00:00
|
|
|
await waitFor(() => expect(screen.getByTestId('album-grid').classList.contains(`as-thumbnails`)).toBe(true))
|
2022-07-10 17:15:56 +00:00
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private async renderComponent () {
|
2024-06-01 18:02:27 +00:00
|
|
|
albumStore.state.albums = factory('album', 9)
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
this.render(AlbumListScreen, {
|
|
|
|
global: {
|
|
|
|
stubs: {
|
2024-10-13 17:37:01 +00:00
|
|
|
AlbumCard: this.stub('album-card'),
|
|
|
|
},
|
|
|
|
},
|
2024-04-23 21:01:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
await this.router.activateRoute({ path: 'albums', screen: 'Albums' })
|
|
|
|
}
|
2022-07-10 17:15:56 +00:00
|
|
|
}
|