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

49 lines
1.2 KiB
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
import factory from '@/__tests__/factory'
import { screen } from '@testing-library/vue'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import SongListItem from './SongListItem.vue'
2024-05-19 05:49:42 +00:00
let row: PlayableRow
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
protected test () {
it('renders', async () => {
const song = factory('song', {
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',
liked: true
})
const { html } = this.renderComponent(song)
expect(html()).toMatchSnapshot()
})
2024-03-25 22:59:38 +00:00
it('emits play event on double click', async () => {
const { emitted } = this.renderComponent()
await this.user.dblClick(screen.getByTestId('song-item'))
2024-03-25 22:59:38 +00:00
expect(emitted().play).toBeTruthy()
})
}
2024-04-23 21:01:27 +00:00
private renderComponent (playable?: Playable) {
playable = playable ?? factory('song')
2024-04-23 21:01:27 +00:00
row = {
playable,
2024-04-23 21:01:27 +00:00
selected: false
}
return this.render(SongListItem, {
props: {
item: row
}
})
}
}