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