Add tests for favorites

This commit is contained in:
Phan An 2017-12-13 00:21:15 +01:00
parent 5b691d6214
commit 353cd4accd
2 changed files with 44 additions and 2 deletions

View file

@ -10,7 +10,7 @@
{{ meta.totalLength }}
<template v-if="sharedState.allowDownload && state.songs.length">
<a href @click.prevent="download" title="Download all songs in playlist">
<a href @click.prevent="download" class="download" title="Download all songs in playlist">
Download All
</a>
</template>
@ -28,7 +28,7 @@
<song-list v-show="state.songs.length" :items="state.songs" type="favorites"/>
<div v-show="!state.songs.length" class="none">
<div v-if="!state.songs.length" class="none">
Start loving!
Click the <i style="margin: 0 5px" class="fa fa-heart"></i> icon when a song is playing to add it
to this list.

View file

@ -0,0 +1,42 @@
import Component from '@/components/main-wrapper/main-content/favorites.vue'
import SongList from '@/components/shared/song-list.vue'
import SongListControls from '@/components/shared/song-list-controls.vue'
import factory from '@/tests/factory'
describe('components/main-wrapper/main-content/favorites', () => {
it('displays the song list if there are favorites', () => {
const wrapper = shallow(Component)
wrapper.setData({
state: {
songs: factory('song', 5)
}
})
wrapper.contains(SongList).should.be.true
wrapper.contains(SongListControls).should.be.true
wrapper.findAll('div.none').should.have.lengthOf(0)
})
it('displays a fallback message if there are no favorites', () => {
const wrapper = shallow(Component)
wrapper.setData({
state: {
songs: []
}
})
wrapper.findAll('div.none').should.have.lengthOf(1)
})
it('allows downloading', () => {
const wrapper = shallow(Component)
wrapper.setData({
state: {
songs: factory('song', 5)
},
sharedState: { allowDownload: true }
})
const spy = sinon.spy()
wrapper.download = spy
wrapper.find('a.download').trigger('click')
spy.should.have.been.called
})
})