koel/resources/assets/js/components/album/AlbumTrackListItem.spec.ts

55 lines
1.4 KiB
TypeScript
Raw Normal View History

import { screen } from '@testing-library/vue'
import { expect, it } from 'vitest'
2022-05-03 17:39:46 +00:00
import factory from '@/__tests__/factory'
import { songStore } from '@/stores'
2022-05-03 17:39:46 +00:00
import { playbackService } from '@/services'
2022-05-13 17:58:38 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
2024-05-19 05:49:42 +00:00
import { PlayablesKey } from '@/symbols'
2022-07-22 17:14:33 +00:00
import { ref } from 'vue'
2022-07-22 17:27:24 +00:00
import AlbumTrackListItem from './AlbumTrackListItem.vue'
2022-05-03 17:39:46 +00:00
2022-07-22 17:14:33 +00:00
new class extends UnitTestCase {
2024-04-23 21:01:27 +00:00
protected test () {
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
it('plays', async () => {
const matchedSong = factory('song')
2024-04-23 21:01:27 +00:00
const playMock = this.mock(playbackService, 'play')
this.renderComponent(matchedSong)
await this.user.click(screen.getByTitle('Click to play'))
expect(playMock).toHaveBeenCalledWith(matchedSong)
2024-04-23 21:01:27 +00:00
})
}
2022-07-22 17:14:33 +00:00
private renderComponent (matchedSong?: Song) {
const songsToMatchAgainst = factory('song', 10)
const album = factory('album')
2022-05-03 17:39:46 +00:00
const track = factory('album-track', {
2022-07-22 17:14:33 +00:00
title: 'Fahrstuhl to Heaven',
length: 280
})
2022-05-03 17:39:46 +00:00
2022-07-22 17:14:33 +00:00
const matchMock = this.mock(songStore, 'match', matchedSong)
2022-05-03 17:39:46 +00:00
2022-07-22 17:14:33 +00:00
const rendered = this.render(AlbumTrackListItem, {
props: {
album,
track
},
global: {
provide: {
2024-05-19 05:49:42 +00:00
[<symbol>PlayablesKey]: ref(songsToMatchAgainst)
2022-07-22 17:14:33 +00:00
}
}
})
expect(matchMock).toHaveBeenCalledWith('Fahrstuhl to Heaven', songsToMatchAgainst)
return rendered
}
}