2022-07-12 14:04:57 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-09-15 09:07:25 +00:00
|
|
|
import { commonStore, overviewStore } from '@/stores'
|
2024-10-13 17:37:01 +00:00
|
|
|
import type { Events } from '@/config'
|
2022-09-15 09:07:25 +00:00
|
|
|
import { eventBus } from '@/utils'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-09-12 15:33:41 +00:00
|
|
|
import HomeScreen from './HomeScreen.vue'
|
2022-07-12 14:04:57 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
2022-10-08 10:54:25 +00:00
|
|
|
it('renders an empty state if no songs found', async () => {
|
2022-07-12 14:04:57 +00:00
|
|
|
commonStore.state.song_length = 0
|
2024-04-29 19:31:54 +00:00
|
|
|
this.mock(overviewStore, 'fetch')
|
2022-10-22 09:27:03 +00:00
|
|
|
|
2024-04-29 19:31:54 +00:00
|
|
|
this.render(HomeScreen)
|
2022-10-22 09:27:03 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
screen.getByTestId('screen-empty-state')
|
2022-07-12 14:04:57 +00:00
|
|
|
})
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
it('renders overview components if applicable', async () => {
|
2022-07-12 14:04:57 +00:00
|
|
|
commonStore.state.song_length = 100
|
2024-04-29 19:31:54 +00:00
|
|
|
const fetchOverviewMock = this.mock(overviewStore, 'fetch')
|
2022-09-12 15:33:41 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-12 14:04:57 +00:00
|
|
|
|
2024-04-29 19:31:54 +00:00
|
|
|
expect(fetchOverviewMock).toHaveBeenCalled()
|
2022-10-09 10:53:10 +00:00
|
|
|
|
2022-07-12 14:04:57 +00:00
|
|
|
;[
|
|
|
|
'most-played-songs',
|
|
|
|
'recently-played-songs',
|
|
|
|
'recently-added-albums',
|
|
|
|
'recently-added-songs',
|
|
|
|
'most-played-artists',
|
2024-10-13 17:37:01 +00:00
|
|
|
'most-played-albums',
|
2022-11-29 10:18:58 +00:00
|
|
|
].forEach(id => screen.getByTestId(id))
|
2022-07-12 14:04:57 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('screen-empty-state')).toBeNull()
|
2022-07-12 14:04:57 +00:00
|
|
|
})
|
2022-09-15 09:07:25 +00:00
|
|
|
|
2024-04-29 19:31:54 +00:00
|
|
|
it.each<[keyof Events]>([['SONGS_UPDATED'], ['SONGS_DELETED'], ['SONG_UPLOADED']])
|
2024-10-13 17:37:01 +00:00
|
|
|
('refreshes the overviews on %s event', async eventName => { // eslint-disable-line no-unexpected-multiline
|
2024-04-29 19:31:54 +00:00
|
|
|
const fetchOverviewMock = this.mock(overviewStore, 'fetch')
|
2022-10-08 10:54:25 +00:00
|
|
|
await this.renderComponent()
|
2022-09-15 09:07:25 +00:00
|
|
|
|
|
|
|
eventBus.emit(eventName)
|
|
|
|
|
2024-04-29 19:31:54 +00:00
|
|
|
expect(fetchOverviewMock).toHaveBeenCalled()
|
2022-09-15 09:07:25 +00:00
|
|
|
})
|
2022-07-12 14:04:57 +00:00
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private async renderComponent () {
|
|
|
|
this.render(HomeScreen)
|
|
|
|
await this.router.activateRoute({ path: 'home', screen: 'Home' })
|
|
|
|
}
|
2022-07-12 14:04:57 +00:00
|
|
|
}
|