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 { albumStore, artistStore } from '../../stores'
|
|
|
|
|
import { default as artists, singleAlbum, singleSong } from '../blobs/media'
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
|
|
describe('stores/album', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
beforeEach(() => albumStore.init(cloneDeep(artists)))
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-11-26 03:25:35 +00:00
|
|
|
|
afterEach(() => albumStore.state.albums = [])
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
describe('#init', () => {
|
|
|
|
|
it('correctly gathers albums', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums.length.should.equal(7)
|
|
|
|
|
})
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly sets albums length', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].length.should.equal(259.92)
|
|
|
|
|
})
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly sets album artists', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].artist.id.should.equal(1)
|
|
|
|
|
})
|
|
|
|
|
})
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
describe('#all', () => {
|
|
|
|
|
it('correctly returns all songs', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.all.length.should.equal(7)
|
|
|
|
|
})
|
|
|
|
|
})
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
describe('#getLength', () => {
|
|
|
|
|
it('correctly calculates an album’s length', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.getLength(albumStore.state.albums[6])
|
2016-06-25 16:05:24 +00:00
|
|
|
|
albumStore.state.albums[6].length.should.equal(1940.42); // I'm sorry…
|
2016-11-26 03:25:35 +00:00
|
|
|
|
})
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
describe('#add', () => {
|
|
|
|
|
beforeEach(() => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.add(cloneDeep(singleAlbum))
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly adds a new album into the state', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
last(albumStore.state.albums).id.should.equal(9999)
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly recalculates the length', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
last(albumStore.state.albums).length.should.equal(300)
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly recalculates the play count', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
last(albumStore.state.albums).playCount.should.equal(11)
|
|
|
|
|
})
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
describe('#remove', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
albumStore.remove(albumStore.state.albums[0]); // ID 1193
|
2016-11-26 03:25:35 +00:00
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly removes an album', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums.length.should.equal(6)
|
|
|
|
|
})
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
describe('#addSongsIntoAlbum', () => {
|
|
|
|
|
beforeEach(() => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.addSongsIntoAlbum(albumStore.state.albums[0], cloneDeep(singleSong))
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly adds a song into an album', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].songs.length.should.equal(2)
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly recalculates the play count', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].playCount.should.equal(4)
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it ('correctly recalculates album length', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].length.should.equal(359.92)
|
|
|
|
|
})
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
describe('#removeSongsFromAlbum', () => {
|
|
|
|
|
beforeEach(() => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.removeSongsFromAlbum(albumStore.state.albums[0], albumStore.state.albums[0].songs[0])
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly removes a song from an album', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].songs.length.should.equal(0)
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly recalculates the play count', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].playCount.should.equal(0)
|
|
|
|
|
})
|
2016-03-05 09:01:12 +00:00
|
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
|
it('correctly recalculates the length', () => {
|
2016-11-26 03:25:35 +00:00
|
|
|
|
albumStore.state.albums[0].length.should.equal(0)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|