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

78 lines
2.4 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
import { songStore, albumStore, artistStore, preferenceStore } from '../../stores'
2017-04-25 14:09:32 +00:00
import data from '../blobs/data'
const { songs, artists, albums, interactions } = data
2015-12-13 04:42:28 +00:00
describe('stores/song', () => {
2016-06-25 16:05:24 +00:00
beforeEach(() => {
2016-11-26 03:25:35 +00:00
artistStore.init(artists)
2017-04-25 14:09:32 +00:00
albumStore.init(albums)
songStore.init(songs)
2016-11-26 03:25:35 +00:00
})
2016-06-25 16:05:24 +00:00
describe('#init', () => {
it('correctly gathers all songs', () => {
2016-11-26 03:25:35 +00:00
songStore.state.songs.length.should.equal(14)
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it ('coverts lengths to formatted lengths', () => {
2016-11-26 03:25:35 +00:00
songStore.state.songs[0].fmtLength.should.be.a.string
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly sets albums', () => {
2016-11-26 03:25:35 +00:00
songStore.state.songs[0].album.id.should.equal(1193)
})
})
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
songStore.all.length.should.equal(14)
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#byId', () => {
it('correctly gets a song by ID', () => {
2016-11-26 03:25:35 +00:00
songStore.byId('e6d3977f3ffa147801ca5d1fdf6fa55e').title.should.equal('Like a rolling stone')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#byIds', () => {
it('correctly gets multiple songs by IDs', () => {
2016-11-26 03:25:35 +00:00
const songs = songStore.byIds(['e6d3977f3ffa147801ca5d1fdf6fa55e', 'aa16bbef6a9710eb9a0f41ecc534fad5'])
songs[0].title.should.equal('Like a rolling stone')
songs[1].title.should.equal("Knockin' on heaven's door")
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#initInteractions', () => {
2016-11-26 03:25:35 +00:00
beforeEach(() => songStore.initInteractions(interactions))
2016-06-25 16:05:24 +00:00
it('correctly sets interaction status', () => {
2016-11-26 03:25:35 +00:00
const song = songStore.byId('cb7edeac1f097143e65b1b2cde102482')
song.liked.should.be.true
song.playCount.should.equal(3)
})
})
2016-06-25 16:05:24 +00:00
describe('#addRecentlyPlayed', () => {
it('correctly adds a recently played song', () => {
songStore.addRecentlyPlayed(songStore.byId('cb7edeac1f097143e65b1b2cde102482'))
songStore.recentlyPlayed[0].id.should.equal('cb7edeac1f097143e65b1b2cde102482')
preferenceStore.get('recent-songs')[0].should.equal('cb7edeac1f097143e65b1b2cde102482')
})
it('correctly gathers the songs from local storage', () => {
songStore.gatherRecentlyPlayedFromLocalStorage()[0].id.should.equal('cb7edeac1f097143e65b1b2cde102482')
})
})
2017-04-25 14:16:33 +00:00
describe('#guess', () => {
it('correcty guesses a song', () => {
songStore.guess('i swear', albumStore.byId(1193)).id.should.equal('39189f4545f9d5671fb3dc964f0080a0')
})
})
2016-11-26 03:25:35 +00:00
})