2022-05-10 12:09:31 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { queueStore } from '@/stores'
|
|
|
|
import { playbackService } from '@/services'
|
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
|
|
|
|
|
|
|
let row: SongRow
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-11-12 21:38:31 +00:00
|
|
|
private renderComponent (song?: Song) {
|
|
|
|
song = song ?? factory<Song>('song')
|
|
|
|
|
2022-05-10 12:09:31 +00:00
|
|
|
row = {
|
2022-11-12 21:38:31 +00:00
|
|
|
song,
|
2022-05-10 12:09:31 +00:00
|
|
|
selected: false
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.render(SongListItem, {
|
|
|
|
props: {
|
2022-11-12 21:38:31 +00:00
|
|
|
item: row
|
2022-05-10 12:09:31 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
2022-11-12 21:38:31 +00:00
|
|
|
it('renders', async () => {
|
|
|
|
const song = factory<Song>('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 } = await this.renderComponent(song)
|
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
})
|
|
|
|
|
2022-05-10 12:09:31 +00:00
|
|
|
it('plays on double click', async () => {
|
|
|
|
const queueMock = this.mock(queueStore, 'queueIfNotQueued')
|
|
|
|
const playMock = this.mock(playbackService, 'play')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-10 12:09:31 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.dblClick(screen.getByTestId('song-item'))
|
2022-05-10 12:09:31 +00:00
|
|
|
|
|
|
|
expect(queueMock).toHaveBeenCalledWith(row.song)
|
|
|
|
expect(playMock).toHaveBeenCalledWith(row.song)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|