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

58 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-07-12 14:04:57 +00:00
import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
import { commonStore, overviewStore } from '@/stores'
2022-11-19 19:55:15 +00:00
import { Events } from '@/config'
import { eventBus } from '@/utils'
import { screen } from '@testing-library/vue'
import HomeScreen from './HomeScreen.vue'
2022-07-12 14:04:57 +00:00
new class extends UnitTestCase {
protected test () {
it('renders an empty state if no songs found', async () => {
2022-07-12 14:04:57 +00:00
commonStore.state.song_length = 0
this.mock(overviewStore, 'init')
await this.render(HomeScreen)
screen.getByTestId('screen-empty-state')
2022-07-12 14:04:57 +00:00
})
it('renders overview components if applicable', async () => {
2022-07-12 14:04:57 +00:00
commonStore.state.song_length = 100
const initMock = this.mock(overviewStore, 'init')
await this.renderComponent()
2022-07-12 14:04:57 +00:00
expect(initMock).toHaveBeenCalled()
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'
].forEach(id => screen.getByTestId(id))
2022-07-12 14:04:57 +00:00
expect(screen.queryByTestId('screen-empty-state')).toBeNull()
2022-07-12 14:04:57 +00:00
})
2022-11-19 19:55:15 +00:00
it.each<[keyof Events]>([['SONGS_UPDATED'], ['SONGS_DELETED']])
('refreshes the overviews on %s event', async eventName => {
const initMock = this.mock(overviewStore, 'init')
const refreshMock = this.mock(overviewStore, 'refresh')
await this.renderComponent()
eventBus.emit(eventName)
expect(initMock).toHaveBeenCalled()
expect(refreshMock).toHaveBeenCalled()
})
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
}