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

110 lines
3 KiB
JavaScript
Raw Normal View History

2016-11-26 03:25:35 +00:00
require('chai').should()
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
import { queueStore } from '../../stores'
import artists from '../blobs/media'
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
const songs = artists[2].albums[0].songs
2015-12-13 04:42:28 +00:00
describe('stores/queue', () => {
2016-06-25 16:05:24 +00:00
beforeEach(() => {
2016-11-26 03:25:35 +00:00
queueStore.state.songs = songs
queueStore.state.current = songs[1]
})
2016-06-25 16:05:24 +00:00
describe('#all', () => {
it('correctly returns all queued songs', () => {
2016-11-26 03:25:35 +00:00
queueStore.all.should.equal(songs)
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#first', () => {
it('correctly returns the first queued song', () => {
2016-11-26 03:25:35 +00:00
queueStore.first.title.should.equal('No bravery')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#last', () => {
it('correctly returns the last queued song', () => {
2016-11-26 03:25:35 +00:00
queueStore.last.title.should.equal('Tears and rain')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#queue', () => {
2016-11-26 03:25:35 +00:00
beforeEach(() => queueStore.state.songs = songs)
2015-12-13 04:42:28 +00:00
2016-11-26 03:25:35 +00:00
const song = artists[0].albums[0].songs[0]
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly appends a song to end of the queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.queue(song)
queueStore.last.title.should.equal('I Swear')
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly prepends a song to top of the queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.queue(song, false, true)
queueStore.first.title.should.equal('I Swear')
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly replaces the whole queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.queue(song, true)
queueStore.all.length.should.equal(1)
queueStore.first.title.should.equal('I Swear')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#unqueue', () => {
2016-11-26 03:25:35 +00:00
beforeEach(() => queueStore.state.songs = songs)
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly removes a song from queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.unqueue(queueStore.state.songs[0])
2016-06-25 16:05:24 +00:00
queueStore.first.title.should.equal('So long, Jimmy'); // Oh the irony.
2016-11-26 03:25:35 +00:00
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly removes mutiple songs from queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.unqueue([queueStore.state.songs[0], queueStore.state.songs[1]])
queueStore.first.title.should.equal('Wisemen')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#clear', () => {
it('correctly clears all songs from queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.clear()
queueStore.state.songs.length.should.equal(0)
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#current', () => {
it('returns the correct current song', () => {
2016-11-26 03:25:35 +00:00
queueStore.current.title.should.equal('So long, Jimmy')
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('successfully sets the current song', () => {
2016-11-26 03:25:35 +00:00
queueStore.current = queueStore.state.songs[0]
queueStore.current.title.should.equal('No bravery')
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#getNextSong', () => {
it('correctly gets the next song in queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.next.title.should.equal('Wisemen')
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly returns null if at end of queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.current = queueStore.state.songs[queueStore.state.songs.length - 1]
var result = queueStore.next === null
result.should.be.true
})
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
describe('#getPrevSong', () => {
it('correctly gets the previous song in queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.previous.title.should.equal('No bravery')
})
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
it('correctly returns null if at end of queue', () => {
2016-11-26 03:25:35 +00:00
queueStore.current = queueStore.state.songs[0]
var result = queueStore.previous === null
result.should.be.true
})
})
})