2022-05-13 09:43:54 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-13 09:43:54 +00:00
|
|
|
import YouTubeVideoList from './YouTubeVideoList.vue'
|
|
|
|
import Btn from '@/components/ui/Btn.vue'
|
|
|
|
import YouTubeVideo from '@/components/ui/YouTubeVideoItem.vue'
|
|
|
|
import { youTubeService } from '@/services'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
|
|
|
|
|
|
|
let song: Song
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-13 09:43:54 +00:00
|
|
|
private renderComponent () {
|
2022-07-07 23:15:38 +00:00
|
|
|
song = factory<Song>('song')
|
2022-05-13 09:43:54 +00:00
|
|
|
|
|
|
|
return this.render(YouTubeVideoList, {
|
|
|
|
props: {
|
|
|
|
song
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
Btn,
|
|
|
|
YouTubeVideo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('displays a list of videos', () => {
|
|
|
|
expect(this.renderComponent().getAllByTestId('youtube-search-result').length).toBe(5)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('loads more videos', async () => {
|
2022-07-07 23:15:38 +00:00
|
|
|
const mock = this.mock(youTubeService, 'searchVideosBySong').mockResolvedValue({
|
2022-05-13 09:43:54 +00:00
|
|
|
nextPageToken: 'b4r',
|
|
|
|
items: factory<YouTubeVideo>('video', 5)
|
|
|
|
})
|
|
|
|
|
|
|
|
const { getAllByTestId, getByTestId } = this.renderComponent()
|
|
|
|
|
|
|
|
await fireEvent.click(getByTestId('youtube-search-more-btn'))
|
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith(song, 'f00')
|
|
|
|
|
|
|
|
await this.tick()
|
|
|
|
expect(getAllByTestId('youtube-search-result').length).toBe(10)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|