2022-05-10 12:09:31 +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-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-11-12 21:38:31 +00:00
|
|
|
import SongListItem from './SongListItem.vue'
|
2022-05-10 12:09:31 +00:00
|
|
|
|
2024-05-19 05:49:42 +00:00
|
|
|
let row: PlayableRow
|
2022-05-10 12:09:31 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-10 12:09:31 +00:00
|
|
|
protected test () {
|
2022-11-12 21:38:31 +00:00
|
|
|
it('renders', async () => {
|
2024-06-01 18:02:27 +00:00
|
|
|
const song = factory('song', {
|
2022-11-12 21:38:31 +00:00
|
|
|
title: 'Test Song',
|
|
|
|
album_name: 'Test Album',
|
|
|
|
artist_name: 'Test Artist',
|
|
|
|
length: 1000,
|
|
|
|
playback_state: 'Playing',
|
|
|
|
track: 12,
|
|
|
|
album_cover: 'https://example.com/cover.jpg',
|
2024-10-13 17:37:01 +00:00
|
|
|
liked: true,
|
2022-11-12 21:38:31 +00:00
|
|
|
})
|
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
const { html } = this.renderComponent(song)
|
2022-11-12 21:38:31 +00:00
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
2024-03-25 22:59:38 +00:00
|
|
|
it('emits play event on double click', async () => {
|
|
|
|
const { emitted } = this.renderComponent()
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.dblClick(screen.getByTestId('song-item'))
|
2024-03-25 22:59:38 +00:00
|
|
|
expect(emitted().play).toBeTruthy()
|
2022-05-10 12:09:31 +00:00
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
2024-06-02 17:15:31 +00:00
|
|
|
private renderComponent (playable?: Playable) {
|
|
|
|
playable = playable ?? factory('song')
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
row = {
|
2024-06-02 17:15:31 +00:00
|
|
|
playable,
|
2024-10-13 17:37:01 +00:00
|
|
|
selected: false,
|
2024-04-23 21:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.render(SongListItem, {
|
|
|
|
props: {
|
2024-10-13 17:37:01 +00:00
|
|
|
item: row,
|
|
|
|
},
|
2024-04-23 21:01:27 +00:00
|
|
|
})
|
|
|
|
}
|
2022-05-10 12:09:31 +00:00
|
|
|
}
|