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'
|
|
|
|
import { EventName } from '@/config'
|
|
|
|
import { eventBus } from '@/utils'
|
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 {
|
2022-10-08 10:54:25 +00:00
|
|
|
private async renderComponent () {
|
|
|
|
const rendered = this.render(HomeScreen)
|
|
|
|
await this.router.activateRoute({ path: 'home', screen: 'Home' })
|
|
|
|
return rendered
|
2022-09-12 15:33:41 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 14:04:57 +00:00
|
|
|
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
|
2022-10-08 10:54:25 +00:00
|
|
|
const { getByTestId } = await this.render(HomeScreen)
|
|
|
|
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
|
2022-09-12 15:33:41 +00:00
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
const { getByTestId, queryByTestId } = await this.renderComponent()
|
2022-07-12 14:04:57 +00:00
|
|
|
|
|
|
|
;[
|
|
|
|
'most-played-songs',
|
|
|
|
'recently-played-songs',
|
|
|
|
'recently-added-albums',
|
|
|
|
'recently-added-songs',
|
|
|
|
'most-played-artists',
|
|
|
|
'most-played-albums'
|
2022-09-12 15:33:41 +00:00
|
|
|
].forEach(id => getByTestId(id))
|
2022-07-12 14:04:57 +00:00
|
|
|
|
|
|
|
expect(queryByTestId('screen-empty-state')).toBeNull()
|
|
|
|
})
|
2022-09-15 09:07:25 +00:00
|
|
|
|
|
|
|
it.each<[EventName]>([['SONGS_UPDATED'], ['SONGS_DELETED']])
|
2022-10-08 10:54:25 +00:00
|
|
|
('refreshes the overviews on %s event', async (eventName) => {
|
2022-09-15 09:07:25 +00:00
|
|
|
const refreshMock = this.mock(overviewStore, 'refresh')
|
2022-10-08 10:54:25 +00:00
|
|
|
await this.renderComponent()
|
2022-09-15 09:07:25 +00:00
|
|
|
|
|
|
|
eventBus.emit(eventName)
|
|
|
|
|
|
|
|
expect(refreshMock).toHaveBeenCalled()
|
|
|
|
})
|
2022-07-12 14:04:57 +00:00
|
|
|
}
|
|
|
|
}
|