koel/resources/assets/js/components/song/SongCard.spec.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

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