mirror of
https://github.com/koel/koel
synced 2024-12-25 20:13:06 +00:00
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { expect, it } from 'vitest'
|
|
import factory from '@/__tests__/factory'
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
import { youTubeService } from '@/services'
|
|
import { fireEvent, waitFor } from '@testing-library/vue'
|
|
import Btn from '@/components/ui/Btn.vue'
|
|
import YouTubeVideo from '@/components/ui/YouTubeVideoItem.vue'
|
|
import YouTubeVideoList from './YouTubeVideoList.vue'
|
|
|
|
new class extends UnitTestCase {
|
|
protected test () {
|
|
it('functions', async () => {
|
|
const song = factory<Song>('song')
|
|
|
|
const searchMock = this.mock(youTubeService, 'searchVideosBySong').mockResolvedValueOnce({
|
|
nextPageToken: 'foo',
|
|
items: factory<YouTubeVideo>('video', 5)
|
|
}).mockResolvedValueOnce({
|
|
nextPageToken: 'bar',
|
|
items: factory<YouTubeVideo>('video', 3)
|
|
})
|
|
|
|
const { getAllByTestId, getByRole } = this.render(YouTubeVideoList, {
|
|
props: {
|
|
song
|
|
},
|
|
global: {
|
|
stubs: {
|
|
Btn,
|
|
YouTubeVideo
|
|
}
|
|
}
|
|
})
|
|
|
|
await waitFor(() => {
|
|
expect(searchMock).toHaveBeenNthCalledWith(1, song, '')
|
|
expect(getAllByTestId('youtube-video')).toHaveLength(5)
|
|
})
|
|
|
|
await fireEvent.click(getByRole('button', { name: 'Load More' }))
|
|
|
|
await waitFor(() => {
|
|
expect(searchMock).toHaveBeenNthCalledWith(2, song, 'foo')
|
|
expect(getAllByTestId('youtube-video')).toHaveLength(8)
|
|
})
|
|
})
|
|
}
|
|
}
|