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-07-22 15:03:45 +00:00
|
|
|
import { youTubeService } from '@/services'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-05-13 09:43:54 +00:00
|
|
|
import Btn from '@/components/ui/Btn.vue'
|
|
|
|
import YouTubeVideo from '@/components/ui/YouTubeVideoItem.vue'
|
2022-07-22 15:03:45 +00:00
|
|
|
import YouTubeVideoList from './YouTubeVideoList.vue'
|
2022-05-13 09:43:54 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-13 09:43:54 +00:00
|
|
|
protected test () {
|
2022-07-22 15:03:45 +00:00
|
|
|
it('functions', async () => {
|
|
|
|
const song = factory<Song>('song')
|
|
|
|
|
|
|
|
const searchMock = this.mock(youTubeService, 'searchVideosBySong').mockResolvedValueOnce({
|
|
|
|
nextPageToken: 'foo',
|
2022-09-12 15:33:41 +00:00
|
|
|
items: factory<YouTubeVideo>('video', 5)
|
2022-07-22 15:03:45 +00:00
|
|
|
}).mockResolvedValueOnce({
|
|
|
|
nextPageToken: 'bar',
|
2022-09-12 15:33:41 +00:00
|
|
|
items: factory<YouTubeVideo>('video', 3)
|
2022-05-13 09:43:54 +00:00
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(YouTubeVideoList, {
|
2022-07-22 15:03:45 +00:00
|
|
|
props: {
|
|
|
|
song
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
stubs: {
|
|
|
|
Btn,
|
|
|
|
YouTubeVideo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-05-13 09:43:54 +00:00
|
|
|
|
2022-07-22 15:03:45 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(searchMock).toHaveBeenNthCalledWith(1, song, '')
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.getAllByRole('listitem')).toHaveLength(5)
|
2022-07-22 15:03:45 +00:00
|
|
|
})
|
2022-05-13 09:43:54 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Load More' }))
|
2022-05-13 09:43:54 +00:00
|
|
|
|
2022-07-22 15:03:45 +00:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(searchMock).toHaveBeenNthCalledWith(2, song, 'foo')
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.getAllByRole('listitem')).toHaveLength(8)
|
2022-07-22 15:03:45 +00:00
|
|
|
})
|
2022-05-13 09:43:54 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|