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

103 lines
3.2 KiB
JavaScript
Raw Normal View History

2015-12-13 04:42:28 +00:00
require('chai').should();
import { cloneDeep, last } from 'lodash';
2015-12-13 04:42:28 +00:00
2016-06-25 10:15:57 +00:00
import { albumStore, artistStore } from '../../stores';
2016-03-05 09:01:12 +00:00
import { default as artists, singleAlbum, singleSong } from '../blobs/media';
2015-12-13 04:42:28 +00:00
describe('stores/album', () => {
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 albums 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', () => {
last(albumStore.state.albums).id.should.equal(9999);
2016-03-05 09:01:12 +00:00
});
it('correctly recalculates the length', () => {
last(albumStore.state.albums).length.should.equal(300);
2016-03-05 09:01:12 +00:00
});
it('correctly recalculates the play count', () => {
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(() => {
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
});