2022-05-09 09:59:31 +00:00
|
|
|
import { fireEvent } from '@testing-library/vue'
|
|
|
|
import { expect, it } from 'vitest'
|
2022-05-03 17:39:46 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-09 09:59:31 +00:00
|
|
|
import { queueStore, songStore } from '@/stores'
|
2022-05-03 17:39:46 +00:00
|
|
|
import { playbackService } from '@/services'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-03 17:39:46 +00:00
|
|
|
import AlbumTrackListItem from './AlbumTrackListItem.vue'
|
|
|
|
|
|
|
|
let song: Song
|
|
|
|
|
|
|
|
const track = {
|
|
|
|
title: 'Fahrstuhl to Heaven',
|
2022-07-08 21:16:08 +00:00
|
|
|
length: '42'
|
2022-05-03 17:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const album = factory<Album>('album', { id: 42 })
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 09:59:31 +00:00
|
|
|
protected beforeEach () {
|
|
|
|
super.beforeEach(() => (song = factory<Song>('song')))
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => {
|
|
|
|
const { html } = this.render(AlbumTrackListItem, {
|
|
|
|
props: {
|
|
|
|
album,
|
|
|
|
track
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('plays', async () => {
|
2022-07-08 21:16:08 +00:00
|
|
|
const matchMock = this.mock(songStore, 'match', song)
|
2022-05-09 09:59:31 +00:00
|
|
|
const queueMock = this.mock(queueStore, 'queueIfNotQueued')
|
|
|
|
const playMock = this.mock(playbackService, 'play')
|
|
|
|
|
|
|
|
const { getByTitle } = this.render(AlbumTrackListItem, {
|
|
|
|
props: {
|
|
|
|
album,
|
|
|
|
track
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.click(getByTitle('Click to play'))
|
|
|
|
|
2022-07-08 21:16:08 +00:00
|
|
|
expect(matchMock).toHaveBeenCalled()
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(queueMock).toHaveBeenNthCalledWith(1, song)
|
|
|
|
expect(playMock).toHaveBeenNthCalledWith(1, song)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|