2024-01-18 11:13:05 +00:00
|
|
|
import Router from '@/router'
|
2022-07-08 12:04:57 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-07-08 12:04:57 +00:00
|
|
|
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 AlbumContextMenu from './AlbumContextMenu.vue'
|
|
|
|
|
|
|
|
let album: Album
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private async renderComponent (_album?: Album) {
|
|
|
|
album = _album || factory<Album>('album', {
|
2022-10-11 15:28:43 +00:00
|
|
|
name: 'IV'
|
2022-07-08 12:04:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const rendered = this.render(AlbumContextMenu)
|
2022-11-29 10:18:58 +00:00
|
|
|
eventBus.emit('ALBUM_CONTEXT_MENU_REQUESTED', { pageX: 420, pageY: 42 } as MouseEvent, album)
|
2022-07-08 12:04:57 +00:00
|
|
|
await this.tick(2)
|
|
|
|
|
|
|
|
return rendered
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-11-29 10:18:58 +00:00
|
|
|
it('renders', async () => expect((await this.renderComponent()).html()).toMatchSnapshot())
|
2022-07-08 12:04:57 +00:00
|
|
|
|
|
|
|
it('plays all', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 10)
|
2022-07-08 12:04:57 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
|
|
|
await this.user.click(screen.getByText('Play All'))
|
2022-07-08 12:04:57 +00:00
|
|
|
await this.tick()
|
|
|
|
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(album)
|
|
|
|
expect(playMock).toHaveBeenCalledWith(songs)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shuffles all', async () => {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songs = factory<Song>('song', 10)
|
2022-07-08 12:04:57 +00:00
|
|
|
const fetchMock = this.mock(songStore, 'fetchForAlbum').mockResolvedValue(songs)
|
|
|
|
const playMock = this.mock(playbackService, 'queueAndPlay')
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
|
|
|
await this.user.click(screen.getByText('Shuffle All'))
|
2022-07-08 12:04:57 +00:00
|
|
|
await this.tick()
|
|
|
|
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(album)
|
|
|
|
expect(playMock).toHaveBeenCalledWith(songs, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('downloads', async () => {
|
2022-10-08 10:54:25 +00:00
|
|
|
const downloadMock = this.mock(downloadService, 'fromAlbum')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-08 12:04:57 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByText('Download'))
|
2022-07-08 12:04:57 +00:00
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
expect(downloadMock).toHaveBeenCalledWith(album)
|
2022-07-08 12:04:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('does not have an option to download if downloading is disabled', async () => {
|
2024-01-04 11:35:36 +00:00
|
|
|
commonStore.state.allows_download = false
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-08 12:04:57 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByText('Download')).toBeNull()
|
2022-07-08 12:04:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('goes to album', async () => {
|
2024-01-18 11:13:05 +00:00
|
|
|
const mock = this.mock(Router, 'go')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-08 12:04:57 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByText('Go to Album'))
|
2022-07-08 12:04:57 +00:00
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith(`album/${album.id}`)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not have an option to download or go to Unknown Album and Artist', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent(factory.states('unknown')<Album>('album'))
|
2022-07-08 12:04:57 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByText('Go to Album')).toBeNull()
|
|
|
|
expect(screen.queryByText('Go to Artist')).toBeNull()
|
|
|
|
expect(screen.queryByText('Download')).toBeNull()
|
2022-07-08 12:04:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('goes to artist', async () => {
|
2024-01-18 11:13:05 +00:00
|
|
|
const mock = this.mock(Router, 'go')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
2022-07-08 12:04:57 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByText('Go to Artist'))
|
2022-07-08 12:04:57 +00:00
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith(`artist/${album.artist_id}`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|