Skip to content

Commit

Permalink
added checkNextEntry unit tests for addition
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Raoult committed Feb 22, 2015
1 parent f3867ab commit cf76877
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"shifty": "^1.3.5"
},
"devDependencies": {
"browser-sync": "^1.9.0",
"browser-sync": "^2.2.1",
"browserify": "^8.0.2",
"gulp": "^3.8.10",
"gulp-jshint": "^1.9.0",
Expand Down
52 changes: 48 additions & 4 deletions src/test/unit/sequencerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var sequencer = require('../../main/sequencer'),
last = require('lodash/array/last'),
initial = require('lodash/array/initial'),
contains = require('lodash/collection/contains'),
pullAt = require('lodash/array/pullAt');
pullAt = require('lodash/array/pullAt'),
find = require('lodash/collection/find');


describe('A sequencer', function() {
Expand Down Expand Up @@ -397,7 +398,7 @@ describe('A sequencer', function() {
}
});

it('preloads the new next entry when checkNextEntry is called and the next entry changed', function(done) {
it('preloads the new next entry when checkNextEntry is called and the next entry was removed', function(done) {

var entries = _entries.slice(0, 3),
slots = [],
Expand All @@ -409,7 +410,7 @@ describe('A sequencer', function() {
var slot = seqDefaultCfg.playbackSlotProducer(producerCfg);
slots.push(slot);

if(slot.entry === _entries[2]) {
if (slot.entry === _entries[2]) {
defer(function() {
runChecks();
done();
Expand Down Expand Up @@ -441,6 +442,49 @@ describe('A sequencer', function() {
}
});

it('preloads the new next entry when checkNextEntry is called and the next entry was added', function(done) {

var entries = [_entries[0]],
slots = [],

seq = sequencerWithDefaults(function(seqDefaultCfg) {
return {
nextEntryProducer: buildNextEntryProducer(entries),
playbackSlotProducer: function(producerCfg) {
var slot = seqDefaultCfg.playbackSlotProducer(producerCfg);
slots.push(slot);

if (slot.entry === _entries[1]) {
defer(function() {
runChecks();
done();
});
}

return slot;
}
};
});

seq.play();
seq.skip(entries[0]);

defer(function() {
// add the next
entries.push(_entries[1]);
seq.checkNextEntry();
});

function runChecks() {
var entry0Slot = find(slots, {entry: _entries[0]});
expect(entry0Slot.load).toHaveBeenCalled();

var entry1Slot = find(slots, {entry: _entries[1]});
expect(entry1Slot.load).toHaveBeenCalled();
expect(entry1Slot.end).not.toHaveBeenCalled();
}
});

it('does nothing when checkNextEntry is called and the next entry has not changed', function(done) {

var entries = _entries.slice(0, 3),
Expand All @@ -453,7 +497,7 @@ describe('A sequencer', function() {
var slot = seqDefaultCfg.playbackSlotProducer(producerCfg);
slots.push(slot);

if(slot.entry === _entries[1]) {
if (slot.entry === _entries[1]) {
defer(function() {
runChecks();
done();
Expand Down

0 comments on commit cf76877

Please sign in to comment.