Add tests for YouTube video sidebar

This commit is contained in:
Phan An 2017-12-11 21:49:34 +01:00
parent aeefa21752
commit 282fd2cd15
3 changed files with 57 additions and 3 deletions

View file

@ -53,9 +53,13 @@ export default {
*/
async loadMore () {
this.loading = true
await youtubeService.searchVideosRelatedToSong(this.song)
this.videos = this.song.youtube.items
this.loading = false
try {
await youtubeService.searchVideosRelatedToSong(this.song)
this.videos = this.song.youtube.items
this.loading = false
} catch (e) {
this.loading = false
}
}
}
}

View file

@ -0,0 +1,26 @@
export default [
{
id: { videoId: 'foo' },
snippet: {
title: 'Koel YouTube video #1',
description: 'Description for Koel YouTube video #1',
thumbnails: {
default: {
url: 'http://youtube/thumb-1.png'
}
}
}
},
{
id: { videoId: 'bar' },
snippet: {
title: 'Koel YouTube video #2',
description: 'Description for Koel YouTube video #2',
thumbnails: {
default: {
url: 'http://youtube/thumb-2.png'
}
}
}
}
]

View file

@ -0,0 +1,24 @@
import YouTube from '@/components/main-wrapper/extra/youtube.vue'
import song from '@/tests/blobs/song'
import videos from '@/tests/blobs/youtube-videos'
describe('components/main-wrapper/extra/youtube', () => {
let wrapper
beforeEach(() => {
wrapper = shallow(YouTube, {
propsData: { song }
})
wrapper.setData({ videos })
})
it('displays a list of videos', () => {
wrapper.findAll('a.video').should.have.lengthOf(2)
})
it('loads more videos on demand', () => {
const spy = sinon.spy()
wrapper.vm.loadMore = spy
wrapper.find('button.more').trigger('click')
spy.should.have.been.called
})
})