koel/resources/assets/js/components/screens/home/RecentlyPlayedSongs.spec.ts

32 lines
965 B
TypeScript
Raw Normal View History

2024-01-18 11:13:05 +00:00
import Router from '@/router'
2022-07-10 16:12:04 +00:00
import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import { overviewStore } from '@/stores'
import { screen } from '@testing-library/vue'
import RecentlyPlayedSongs from './RecentlyPlayedSongs.vue'
2022-07-10 16:12:04 +00:00
new class extends UnitTestCase {
protected test () {
it('displays the songs', () => {
overviewStore.state.recentlyPlayed = factory<Song>('song', 6)
expect(this.render(RecentlyPlayedSongs, {
global: {
stubs: {
SongCard: this.stub('song-card')
}
}
}).getAllByTestId('song-card')).toHaveLength(6)
2022-07-10 16:12:04 +00:00
})
it('goes to dedicated screen', async () => {
2024-01-18 11:13:05 +00:00
const mock = this.mock(Router, 'go')
this.render(RecentlyPlayedSongs)
2022-07-10 16:12:04 +00:00
await this.user.click(screen.getByRole('button', { name: 'View All' }))
2022-07-10 16:12:04 +00:00
expect(mock).toHaveBeenCalledWith('recently-played')
})
}
}