2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-09 09:59:31 +00:00
|
|
|
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'
|
2024-05-19 05:49:42 +00:00
|
|
|
import { PlayablesKey } from '@/symbols'
|
2022-07-22 17:14:33 +00:00
|
|
|
import { ref } from 'vue'
|
2022-07-22 17:27:24 +00:00
|
|
|
import AlbumTrackListItem from './AlbumTrackListItem.vue'
|
2022-05-03 17:39:46 +00:00
|
|
|
|
2022-07-22 17:14:33 +00:00
|
|
|
new class extends UnitTestCase {
|
2024-04-23 21:01:27 +00:00
|
|
|
protected test () {
|
|
|
|
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
|
|
|
|
|
|
|
it('plays', async () => {
|
|
|
|
const matchedSong = factory<Song>('song')
|
|
|
|
const queueMock = this.mock(queueStore, 'queueIfNotQueued')
|
|
|
|
const playMock = this.mock(playbackService, 'play')
|
|
|
|
|
|
|
|
this.renderComponent(matchedSong)
|
|
|
|
|
|
|
|
await this.user.click(screen.getByTitle('Click to play'))
|
|
|
|
|
|
|
|
expect(queueMock).toHaveBeenNthCalledWith(1, matchedSong)
|
|
|
|
expect(playMock).toHaveBeenNthCalledWith(1, matchedSong)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-22 17:14:33 +00:00
|
|
|
private renderComponent (matchedSong?: Song) {
|
2022-09-12 15:33:41 +00:00
|
|
|
const songsToMatchAgainst = factory<Song>('song', 10)
|
2022-07-22 17:14:33 +00:00
|
|
|
const album = factory<Album>('album')
|
2022-05-03 17:39:46 +00:00
|
|
|
|
2022-07-22 17:14:33 +00:00
|
|
|
const track = factory<AlbumTrack>('album-track', {
|
|
|
|
title: 'Fahrstuhl to Heaven',
|
|
|
|
length: 280
|
|
|
|
})
|
2022-05-03 17:39:46 +00:00
|
|
|
|
2022-07-22 17:14:33 +00:00
|
|
|
const matchMock = this.mock(songStore, 'match', matchedSong)
|
2022-05-03 17:39:46 +00:00
|
|
|
|
2022-07-22 17:14:33 +00:00
|
|
|
const rendered = this.render(AlbumTrackListItem, {
|
|
|
|
props: {
|
|
|
|
album,
|
|
|
|
track
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
provide: {
|
2024-05-19 05:49:42 +00:00
|
|
|
[<symbol>PlayablesKey]: ref(songsToMatchAgainst)
|
2022-07-22 17:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(matchMock).toHaveBeenCalledWith('Fahrstuhl to Heaven', songsToMatchAgainst)
|
|
|
|
|
|
|
|
return rendered
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
|
|
|
}
|