2022-05-09 12:54:41 +00:00
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { queueStore } from '@/stores'
|
|
|
|
import { playbackService } from '@/services'
|
|
|
|
import { expect, it } from 'vitest'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-09 12:54:41 +00:00
|
|
|
import SongCard from './SongCard.vue'
|
|
|
|
|
|
|
|
let song: Song
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 12:54:41 +00:00
|
|
|
private renderComponent (playbackState: PlaybackState = 'Stopped') {
|
|
|
|
song = factory<Song>('song', {
|
2022-06-10 10:47:46 +00:00
|
|
|
playback_state: playbackState,
|
|
|
|
play_count: 10,
|
2022-05-09 12:54:41 +00:00
|
|
|
title: 'Foo bar'
|
|
|
|
})
|
|
|
|
|
|
|
|
return this.render(SongCard, {
|
|
|
|
props: {
|
|
|
|
song,
|
|
|
|
topPlayCount: 42
|
2022-10-26 12:34:32 +00:00
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
SongThumbnail: this.stub('thumbnail'),
|
|
|
|
LikeButton: this.stub('like-button')
|
|
|
|
}
|
2022-05-09 12:54:41 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-10-26 12:34:32 +00:00
|
|
|
it('has a thumbnail and a like button', () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
|
|
|
screen.getByTestId('thumbnail')
|
|
|
|
screen.getByTestId('like-button')
|
2022-10-26 12:34:32 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('queues and plays on double-click', async () => {
|
2022-05-09 12:54:41 +00:00
|
|
|
const queueMock = this.mock(queueStore, 'queueIfNotQueued')
|
|
|
|
const playMock = this.mock(playbackService, 'play')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-09 12:54:41 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.dblClick(screen.getByRole('article'))
|
2022-05-09 12:54:41 +00:00
|
|
|
|
|
|
|
expect(queueMock).toHaveBeenCalledWith(song)
|
|
|
|
expect(playMock).toHaveBeenCalledWith(song)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|