Add tests for album

This commit is contained in:
Phan An 2017-12-12 01:25:31 +01:00
parent ce66f06a26
commit e54aa480fb
3 changed files with 68 additions and 4 deletions

View file

@ -132,9 +132,12 @@ export default {
async showInfo () {
this.info.showing = true
if (!this.album.info) {
this.info.loading = true
await albumInfoService.fetch(this.album)
this.info.loading = false
try {
await albumInfoService.fetch(this.album)
} catch (e) {
} finally {
this.info.loading = false
}
} else {
this.info.loading = false
}

View file

@ -1,6 +1,7 @@
export default {
id: 1,
name: 'Koel Vol. 1',
cover: 'http://foo/cover.jpg',
info: {
image: 'http://foo/bar.jpg',
wiki: {
@ -12,5 +13,21 @@ export default {
{ title: 'Second song', fmtLength: '2:37' },
],
url: 'http://foo/bar'
}
},
artist: {
id: 1,
name: 'Koel Artist'
},
songs: [
{
id: 'd501d98756733e2f6d875c5de8be40eb',
title: 'Song #1',
length: 10,
},
{
id: '6d644013c2414ab07d21776ed5876ba4',
title: 'Song #2',
length: 20
}
]
}

View file

@ -0,0 +1,44 @@
import Album from '@/components/main-wrapper/main-content/album.vue'
import SongList from '@/components/shared/song-list.vue'
import SongListControls from '@/components/shared/song-list-controls.vue'
import { event } from '@/utils'
import album from '@/tests/blobs/album'
import Vue from 'vue'
describe('components/main-wrapper/main-content/album', () => {
it('renders upon receiving event', () => {
const wrapper = shallow(Album)
event.emit('main-content-view:load', 'album', album)
Vue.nextTick(() => {
const html = wrapper.html()
html.should.contain(album.name)
html.should.contain(album.artist.name)
wrapper.contains(SongList).should.be.true
wrapper.contains(SongListControls).should.be.true
})
})
it('loads info from Last.fm', () => {
const wrapper = shallow(Album)
wrapper.setData({
album,
sharedState: { useLastfm: true }
})
const spy = sinon.spy()
wrapper.showInfo = spy
wrapper.find('a.info').trigger('click')
spy.should.have.been.called
})
it('allows downloading', () => {
const wrapper = shallow(Album)
wrapper.setData({
album,
sharedState: { allowDownload: true }
})
const spy = sinon.spy()
wrapper.download = spy
wrapper.find('a.download').trigger('click')
spy.should.have.been.called
})
})