2022-05-09 13:04:24 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
|
|
|
import { favoriteStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-09 13:04:24 +00:00
|
|
|
import SongLikeButton from './SongLikeButton.vue'
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 13:04:24 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|