koel/resources/assets/js/tests/stores/artistTest.js

74 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-11-26 03:25:35 +00:00
require('chai').should()
import { cloneDeep, last } from 'lodash'
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
import { artistStore } from '../../stores'
import { default as artists, singleAlbum, singleArtist } from '../blobs/media'
2015-12-13 04:42:28 +00:00
describe('stores/artist', () => {
2016-11-26 03:25:35 +00:00
beforeEach(() => artistStore.init(cloneDeep(artists)))
afterEach(() => artistStore.state.artists = [])
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#init', () => {
it('correctly gathers artists', () => {
2016-11-26 03:25:35 +00:00
artistStore.state.artists.length.should.equal(3)
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly gets artist images', () => {
2016-11-26 03:25:35 +00:00
artistStore.state.artists[0].image.should.equal('/public/img/covers/565c0f7067425.jpeg')
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly counts songs by artists', () => {
2016-11-26 03:25:35 +00:00
artistStore.state.artists[0].songCount = 3
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#getImage', () => {
it('correctly gets an artists image', () => {
2016-11-26 03:25:35 +00:00
artistStore.getImage(artistStore.state.artists[0]).should.equal('/public/img/covers/565c0f7067425.jpeg')
})
})
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
describe('#add', () => {
2016-11-26 03:25:35 +00:00
beforeEach(() => artistStore.add(cloneDeep(singleArtist)))
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
it('correctly adds an artist', () => {
2016-11-26 03:25:35 +00:00
last(artistStore.state.artists).name.should.equal('John Cena')
})
})
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
describe('#remove', () => {
2016-11-26 03:25:35 +00:00
beforeEach(() => artistStore.remove(artistStore.state.artists[0]))
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
it('correctly removes an artist', () => {
2016-11-26 03:25:35 +00:00
artistStore.state.artists.length.should.equal(2)
artistStore.state.artists[0].name.should.equal('Bob Dylan')
})
})
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
describe('#addAlbumsIntoArtist', () => {
beforeEach(() => {
2016-11-26 03:25:35 +00:00
artistStore.addAlbumsIntoArtist(artistStore.state.artists[0], cloneDeep(singleAlbum))
})
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
it('correctly adds albums into an artist', () => {
2016-11-26 03:25:35 +00:00
artistStore.state.artists[0].albums.length.should.equal(4)
})
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
it('correctly sets the album artist', () => {
2016-11-26 03:25:35 +00:00
const addedAlbum = last(artistStore.state.artists[0].albums)
addedAlbum.artist.should.equal(artistStore.state.artists[0])
addedAlbum.artist_id.should.equal(artistStore.state.artists[0].id)
})
})
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
describe('#removeAlbumsFromArtist', () => {
beforeEach(() => {
2016-11-26 03:25:35 +00:00
artistStore.removeAlbumsFromArtist(artistStore.state.artists[0], artistStore.state.artists[0].albums[0])
})
2016-03-05 09:01:12 +00:00
2016-06-25 16:05:24 +00:00
it('correctly removes an album from an artist', () => {
2016-11-26 03:25:35 +00:00
artistStore.state.artists[0].albums.length.should.equal(2)
})
})
})