2022-09-12 15:33:41 +00:00
|
|
|
import { ref } from 'vue'
|
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'
|
2022-09-12 15:33:41 +00:00
|
|
|
import { ActiveScreenKey } from '@/symbols'
|
2022-09-15 09:07:25 +00:00
|
|
|
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-09-12 15:33:41 +00:00
|
|
|
private renderComponent () {
|
|
|
|
return this.render(HomeScreen, {
|
|
|
|
global: {
|
|
|
|
provide: {
|
|
|
|
[<symbol>ActiveScreenKey]: ref('Home')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-12 14:04:57 +00:00
|
|
|
protected test () {
|
|
|
|
it('renders an empty state if no songs found', () => {
|
|
|
|
commonStore.state.song_length = 0
|
2022-09-12 15:33:41 +00:00
|
|
|
this.renderComponent().getByTestId('screen-empty-state')
|
2022-07-12 14:04:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders overview components if applicable', () => {
|
|
|
|
commonStore.state.song_length = 100
|
2022-09-12 15:33:41 +00:00
|
|
|
|
|
|
|
const { getByTestId, queryByTestId } = 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']])
|
|
|
|
('refreshes the overviews on %s event', (eventName) => {
|
|
|
|
const refreshMock = this.mock(overviewStore, 'refresh')
|
|
|
|
this.renderComponent()
|
|
|
|
|
|
|
|
eventBus.emit(eventName)
|
|
|
|
|
|
|
|
expect(refreshMock).toHaveBeenCalled()
|
|
|
|
})
|
2022-07-12 14:04:57 +00:00
|
|
|
}
|
|
|
|
}
|