mirror of
https://github.com/koel/koel
synced 2024-11-28 06:50:27 +00:00
feat(test): add ArtistContextMenu tests
This commit is contained in:
parent
5a184c0cd0
commit
4f6bda8637
4 changed files with 115 additions and 2 deletions
|
@ -19,7 +19,7 @@ new class extends UnitTestCase {
|
||||||
})
|
})
|
||||||
|
|
||||||
const rendered = this.render(AlbumContextMenu)
|
const rendered = this.render(AlbumContextMenu)
|
||||||
eventBus.emit('ALBUM_CONTEXT_MENU_REQUESTED', {}, album)
|
eventBus.emit('ALBUM_CONTEXT_MENU_REQUESTED', { pageX: 420, pageY: 69 }, album)
|
||||||
await this.tick(2)
|
await this.tick(2)
|
||||||
|
|
||||||
return rendered
|
return rendered
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Vitest Snapshot v1
|
// Vitest Snapshot v1
|
||||||
|
|
||||||
exports[`renders 1`] = `
|
exports[`renders 1`] = `
|
||||||
<nav class="album-menu menu context-menu" style="top: 0px; left: 0px;" tabindex="0" data-testid="album-context-menu">
|
<nav class="album-menu menu context-menu" style="top: 69px; left: 420px;" tabindex="0" data-testid="album-context-menu">
|
||||||
<ul>
|
<ul>
|
||||||
<li data-testid="play">Play All</li>
|
<li data-testid="play">Play All</li>
|
||||||
<li data-testid="shuffle">Shuffle All</li>
|
<li data-testid="shuffle">Shuffle All</li>
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
import { expect, it } from 'vitest'
|
||||||
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||||
|
import factory from '@/__tests__/factory'
|
||||||
|
import { eventBus } from '@/utils'
|
||||||
|
import { downloadService, playbackService } from '@/services'
|
||||||
|
import { commonStore, songStore } from '@/stores'
|
||||||
|
import router from '@/router'
|
||||||
|
import ArtistContextMenu from './ArtistContextMenu.vue'
|
||||||
|
|
||||||
|
let artist: Artist
|
||||||
|
|
||||||
|
new class extends UnitTestCase {
|
||||||
|
private async renderComponent (_artist?: Artist) {
|
||||||
|
artist = _artist || factory<Artist>('artist', {
|
||||||
|
name: 'Accept',
|
||||||
|
play_count: 30,
|
||||||
|
song_count: 10,
|
||||||
|
length: 123
|
||||||
|
})
|
||||||
|
|
||||||
|
const rendered = this.render(ArtistContextMenu)
|
||||||
|
eventBus.emit('ARTIST_CONTEXT_MENU_REQUESTED', { pageX: 420, pageY: 69 }, artist)
|
||||||
|
await this.tick(2)
|
||||||
|
|
||||||
|
return rendered
|
||||||
|
}
|
||||||
|
|
||||||
|
protected test () {
|
||||||
|
it('renders', async () => {
|
||||||
|
const { html } = await this.renderComponent()
|
||||||
|
expect(html()).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('plays all', async () => {
|
||||||
|
const songs = factory<Song[]>('song', 10)
|
||||||
|
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
|
||||||
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
||||||
|
|
||||||
|
const { getByText } = await this.renderComponent()
|
||||||
|
await getByText('Play All').click()
|
||||||
|
await this.tick()
|
||||||
|
|
||||||
|
expect(fetchMock).toHaveBeenCalledWith(artist)
|
||||||
|
expect(playMock).toHaveBeenCalledWith(songs)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shuffles all', async () => {
|
||||||
|
const songs = factory<Song[]>('song', 10)
|
||||||
|
const fetchMock = this.mock(songStore, 'fetchForArtist').mockResolvedValue(songs)
|
||||||
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
||||||
|
|
||||||
|
const { getByText } = await this.renderComponent()
|
||||||
|
await getByText('Shuffle All').click()
|
||||||
|
await this.tick()
|
||||||
|
|
||||||
|
expect(fetchMock).toHaveBeenCalledWith(artist)
|
||||||
|
expect(playMock).toHaveBeenCalledWith(songs, true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('downloads', async () => {
|
||||||
|
const mock = this.mock(downloadService, 'fromArtist')
|
||||||
|
|
||||||
|
const { getByText } = await this.renderComponent()
|
||||||
|
await getByText('Download').click()
|
||||||
|
|
||||||
|
expect(mock).toHaveBeenCalledWith(artist)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not have an option to download if downloading is disabled', async () => {
|
||||||
|
commonStore.state.allow_download = false
|
||||||
|
const { queryByText } = await this.renderComponent()
|
||||||
|
|
||||||
|
expect(queryByText('Download')).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('goes to artist', async () => {
|
||||||
|
const mock = this.mock(router, 'go')
|
||||||
|
const { getByText } = await this.renderComponent()
|
||||||
|
|
||||||
|
await getByText('Go to Artist').click()
|
||||||
|
|
||||||
|
expect(mock).toHaveBeenCalledWith(`artist/${artist.id}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not have an option to download or go to Unknown Artist', async () => {
|
||||||
|
const { queryByTestId } = await this.renderComponent(factory.states('unknown')<Artist>('artist'))
|
||||||
|
|
||||||
|
expect(queryByTestId('view-artist')).toBeNull()
|
||||||
|
expect(queryByTestId('download')).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not have an option to download or go to Various Artist', async () => {
|
||||||
|
const { queryByTestId } = await this.renderComponent(factory.states('various')<Artist>('artist'))
|
||||||
|
|
||||||
|
expect(queryByTestId('view-artist')).toBeNull()
|
||||||
|
expect(queryByTestId('download')).toBeNull()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Vitest Snapshot v1
|
||||||
|
|
||||||
|
exports[`renders 1`] = `
|
||||||
|
<nav class="artist-menu menu context-menu" style="top: 69px; left: 420px;" tabindex="0" data-testid="artist-context-menu">
|
||||||
|
<ul>
|
||||||
|
<li data-testid="play">Play All</li>
|
||||||
|
<li data-testid="shuffle">Shuffle All</li>
|
||||||
|
<li class="separator"></li>
|
||||||
|
<li data-testid="view-artist">Go to Artist</li>
|
||||||
|
<li class="separator"></li>
|
||||||
|
<li data-testid="download">Download</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
`;
|
Loading…
Reference in a new issue