mirror of
https://github.com/koel/koel
synced 2024-12-29 22:13:06 +00:00
29 lines
842 B
TypeScript
29 lines
842 B
TypeScript
|
import { expect, it } from 'vitest'
|
||
|
import factory from '@/__tests__/factory'
|
||
|
import { fireEvent } from '@testing-library/vue'
|
||
|
import { favoriteStore } from '@/stores'
|
||
|
import ComponentTestCase from '@/__tests__/ComponentTestCase'
|
||
|
import SongLikeButton from './SongLikeButton.vue'
|
||
|
|
||
|
new class extends ComponentTestCase {
|
||
|
protected test () {
|
||
|
it.each<[boolean, string]>([
|
||
|
[true, 'btn-like-liked'],
|
||
|
[false, 'btn-like-unliked']
|
||
|
])('likes or unlikes', async (liked: boolean, testId: string) => {
|
||
|
const mock = this.mock(favoriteStore, 'toggleOne')
|
||
|
const song = factory<Song>('song', { liked })
|
||
|
|
||
|
const { getByTestId } = this.render(SongLikeButton, {
|
||
|
props: {
|
||
|
song
|
||
|
}
|
||
|
})
|
||
|
|
||
|
await fireEvent.click(getByTestId(testId))
|
||
|
|
||
|
expect(mock).toHaveBeenCalledWith(song)
|
||
|
})
|
||
|
}
|
||
|
}
|