2022-05-09 13:04:24 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-09 13:04:24 +00:00
|
|
|
import { favoriteStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2024-06-02 17:15:31 +00:00
|
|
|
import Component from './SongLikeButton.vue'
|
2022-05-09 13:04:24 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 13:04:24 +00:00
|
|
|
protected test () {
|
2024-06-02 17:15:31 +00:00
|
|
|
it.each<[string, boolean]>([['Unlike', true], ['Like', false]])('%s', async (name, liked) => {
|
2022-05-09 13:04:24 +00:00
|
|
|
const mock = this.mock(favoriteStore, 'toggleOne')
|
2024-06-02 17:15:31 +00:00
|
|
|
|
|
|
|
const playable = factory('song', {
|
2022-11-29 10:18:58 +00:00
|
|
|
liked,
|
|
|
|
title: 'Foo',
|
|
|
|
artist_name: 'Bar'
|
|
|
|
})
|
2022-05-09 13:04:24 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
this.render(Component, {
|
2022-05-09 13:04:24 +00:00
|
|
|
props: {
|
2024-06-02 17:15:31 +00:00
|
|
|
playable
|
2022-05-09 13:04:24 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name }))
|
2022-05-09 13:04:24 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
expect(mock).toHaveBeenCalledWith(playable)
|
2022-05-09 13:04:24 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|