mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 23:48:34 +02:00
more test coverage which is always good :D
This commit is contained in:
parent
4b003f057e
commit
292126437a
4 changed files with 187 additions and 27 deletions
|
@ -7882,19 +7882,44 @@ GitEngine.prototype.fakeTeamworkStarter = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var numToMake = this.generalArgs[0] || 1;
|
|
||||||
this.validateArgBounds(this.generalArgs, 0, 1);
|
this.validateArgBounds(this.generalArgs, 0, 1);
|
||||||
for (var i = 0; i < numToMake; i++) {
|
var numToMake = this.generalArgs[0] || 1;
|
||||||
|
this.fakeTeamwork(numToMake);
|
||||||
|
};
|
||||||
|
|
||||||
|
GitEngine.prototype.fakeTeamwork = function(numToMake) {
|
||||||
|
var makeOriginCommit = _.bind(function() {
|
||||||
var id = this.getUniqueID();
|
var id = this.getUniqueID();
|
||||||
this.origin.receiveTeamwork(id, this.animationQueue);
|
this.origin.receiveTeamwork(id, this.animationQueue);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
var chainStep = function() {
|
||||||
|
makeOriginCommit();
|
||||||
|
var d = Q.defer();
|
||||||
|
setTimeout(function() { d.resolve(); }, 1000);
|
||||||
|
return d.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
var deferred = Q.defer();
|
||||||
|
var chain = deferred.promise;
|
||||||
|
|
||||||
|
for (var i = 0; i < numToMake; i++) {
|
||||||
|
// here is the deal -- we dont want to make the origin receive
|
||||||
|
// teamwork all at once because then the animation of each child
|
||||||
|
// is difficult. Instead, we will generate a promise chain which will
|
||||||
|
// produce the commit right before every animation
|
||||||
|
chain = chain.then(chainStep());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deferred.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.receiveTeamwork = function(id, animationQueue) {
|
GitEngine.prototype.receiveTeamwork = function(id, animationQueue) {
|
||||||
var newCommit = this.makeCommit([this.getCommitFromRef('HEAD')], id);
|
var newCommit = this.makeCommit([this.getCommitFromRef('HEAD')], id);
|
||||||
this.setTargetLocation(this.HEAD, newCommit);
|
this.setTargetLocation(this.HEAD, newCommit);
|
||||||
|
|
||||||
this.animationFactory.genCommitBirthAnimation(animationQueue, newCommit, this.gitVisuals);
|
//this.animationFactory.genCommitBirthAnimation(animationQueue, newCommit, this.gitVisuals);
|
||||||
|
return newCommit;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.cherrypick = function(ref) {
|
GitEngine.prototype.cherrypick = function(ref) {
|
||||||
|
@ -9377,6 +9402,7 @@ exports.AnimationFactory = AnimationFactory;
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/js/visuals/animation/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
require.define("/src/js/visuals/animation/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
||||||
|
var Q = require('q');
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
var GLOBAL = require('../../util/constants').GLOBAL;
|
var GLOBAL = require('../../util/constants').GLOBAL;
|
||||||
|
|
||||||
|
@ -9472,12 +9498,11 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
if (!options.closure || !options.deferred) {
|
if (!options.closure) {
|
||||||
throw new Error('need closure and deferred');
|
throw new Error('need closure');
|
||||||
}
|
}
|
||||||
// TODO needed?
|
// TODO needed?
|
||||||
this.set('animation', options.animation);
|
this.set('deferred', options.deferred || Q.defer());
|
||||||
this.set('deferred', options.deferred);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
play: function() {
|
play: function() {
|
||||||
|
@ -9485,10 +9510,8 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
// we want to resolve a deferred when the animation finishes
|
// we want to resolve a deferred when the animation finishes
|
||||||
this.get('closure')();
|
this.get('closure')();
|
||||||
setTimeout(_.bind(function() {
|
setTimeout(_.bind(function() {
|
||||||
console.log('resolving deferred');
|
|
||||||
this.get('deferred').resolve();
|
this.get('deferred').resolve();
|
||||||
}, this), this.get('duration'));
|
}, this), this.get('duration'));
|
||||||
console.log('the duration', this.get('duration'));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
then: function(func) {
|
then: function(func) {
|
||||||
|
@ -9496,6 +9519,12 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
PromiseAnimation.fromAnimation = function(animation) {
|
||||||
|
return new PromiseAnimation({
|
||||||
|
closure: animation.get('closure'),
|
||||||
|
duration: animation.get('duration')
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.Animation = Animation;
|
exports.Animation = Animation;
|
||||||
exports.PromiseAnimation = PromiseAnimation;
|
exports.PromiseAnimation = PromiseAnimation;
|
||||||
|
@ -23731,19 +23760,44 @@ GitEngine.prototype.fakeTeamworkStarter = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var numToMake = this.generalArgs[0] || 1;
|
|
||||||
this.validateArgBounds(this.generalArgs, 0, 1);
|
this.validateArgBounds(this.generalArgs, 0, 1);
|
||||||
for (var i = 0; i < numToMake; i++) {
|
var numToMake = this.generalArgs[0] || 1;
|
||||||
|
this.fakeTeamwork(numToMake);
|
||||||
|
};
|
||||||
|
|
||||||
|
GitEngine.prototype.fakeTeamwork = function(numToMake) {
|
||||||
|
var makeOriginCommit = _.bind(function() {
|
||||||
var id = this.getUniqueID();
|
var id = this.getUniqueID();
|
||||||
this.origin.receiveTeamwork(id, this.animationQueue);
|
this.origin.receiveTeamwork(id, this.animationQueue);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
var chainStep = function() {
|
||||||
|
makeOriginCommit();
|
||||||
|
var d = Q.defer();
|
||||||
|
setTimeout(function() { d.resolve(); }, 1000);
|
||||||
|
return d.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
var deferred = Q.defer();
|
||||||
|
var chain = deferred.promise;
|
||||||
|
|
||||||
|
for (var i = 0; i < numToMake; i++) {
|
||||||
|
// here is the deal -- we dont want to make the origin receive
|
||||||
|
// teamwork all at once because then the animation of each child
|
||||||
|
// is difficult. Instead, we will generate a promise chain which will
|
||||||
|
// produce the commit right before every animation
|
||||||
|
chain = chain.then(chainStep());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deferred.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.receiveTeamwork = function(id, animationQueue) {
|
GitEngine.prototype.receiveTeamwork = function(id, animationQueue) {
|
||||||
var newCommit = this.makeCommit([this.getCommitFromRef('HEAD')], id);
|
var newCommit = this.makeCommit([this.getCommitFromRef('HEAD')], id);
|
||||||
this.setTargetLocation(this.HEAD, newCommit);
|
this.setTargetLocation(this.HEAD, newCommit);
|
||||||
|
|
||||||
this.animationFactory.genCommitBirthAnimation(animationQueue, newCommit, this.gitVisuals);
|
//this.animationFactory.genCommitBirthAnimation(animationQueue, newCommit, this.gitVisuals);
|
||||||
|
return newCommit;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.cherrypick = function(ref) {
|
GitEngine.prototype.cherrypick = function(ref) {
|
||||||
|
@ -31430,6 +31484,7 @@ exports.AnimationFactory = AnimationFactory;
|
||||||
require("/src/js/visuals/animation/animationFactory.js");
|
require("/src/js/visuals/animation/animationFactory.js");
|
||||||
|
|
||||||
require.define("/src/js/visuals/animation/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
require.define("/src/js/visuals/animation/index.js",function(require,module,exports,__dirname,__filename,process,global){var _ = require('underscore');
|
||||||
|
var Q = require('q');
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
var GLOBAL = require('../../util/constants').GLOBAL;
|
var GLOBAL = require('../../util/constants').GLOBAL;
|
||||||
|
|
||||||
|
@ -31525,12 +31580,11 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
if (!options.closure || !options.deferred) {
|
if (!options.closure) {
|
||||||
throw new Error('need closure and deferred');
|
throw new Error('need closure');
|
||||||
}
|
}
|
||||||
// TODO needed?
|
// TODO needed?
|
||||||
this.set('animation', options.animation);
|
this.set('deferred', options.deferred || Q.defer());
|
||||||
this.set('deferred', options.deferred);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
play: function() {
|
play: function() {
|
||||||
|
@ -31538,10 +31592,8 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
// we want to resolve a deferred when the animation finishes
|
// we want to resolve a deferred when the animation finishes
|
||||||
this.get('closure')();
|
this.get('closure')();
|
||||||
setTimeout(_.bind(function() {
|
setTimeout(_.bind(function() {
|
||||||
console.log('resolving deferred');
|
|
||||||
this.get('deferred').resolve();
|
this.get('deferred').resolve();
|
||||||
}, this), this.get('duration'));
|
}, this), this.get('duration'));
|
||||||
console.log('the duration', this.get('duration'));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
then: function(func) {
|
then: function(func) {
|
||||||
|
@ -31549,6 +31601,12 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
PromiseAnimation.fromAnimation = function(animation) {
|
||||||
|
return new PromiseAnimation({
|
||||||
|
closure: animation.get('closure'),
|
||||||
|
duration: animation.get('duration')
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.Animation = Animation;
|
exports.Animation = Animation;
|
||||||
exports.PromiseAnimation = PromiseAnimation;
|
exports.PromiseAnimation = PromiseAnimation;
|
||||||
|
|
73
spec/animation.spec.js
Normal file
73
spec/animation.spec.js
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
var AnimationModule = require('../src/js/visuals/animation/index');
|
||||||
|
var PromiseAnimation = AnimationModule.PromiseAnimation;
|
||||||
|
var Animation = AnimationModule.Animation;
|
||||||
|
var Q = require('q');
|
||||||
|
|
||||||
|
describe('Promise animation', function() {
|
||||||
|
it('Will execute the closure', function() {
|
||||||
|
var value = 0;
|
||||||
|
var closure = function() {
|
||||||
|
value++;
|
||||||
|
};
|
||||||
|
|
||||||
|
var animation = new PromiseAnimation({
|
||||||
|
deferred: Q.defer(),
|
||||||
|
closure: closure
|
||||||
|
});
|
||||||
|
animation.play();
|
||||||
|
expect(value).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Will resolve a deferred', function() {
|
||||||
|
var value = 0;
|
||||||
|
var closure = function() {
|
||||||
|
value++;
|
||||||
|
};
|
||||||
|
|
||||||
|
var animation = new PromiseAnimation({
|
||||||
|
closure: closure
|
||||||
|
});
|
||||||
|
animation
|
||||||
|
.then(function() {
|
||||||
|
value++;
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
if (value !== 2) {
|
||||||
|
console.log('second promise failed!!');
|
||||||
|
} else {
|
||||||
|
console.log('1 more test passed');
|
||||||
|
}
|
||||||
|
// TODO -- make this work (aka the tests keep running until
|
||||||
|
// this assertion finishes
|
||||||
|
expect(value).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
animation.play();
|
||||||
|
expect(value).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('will make one from a normal animation', function() {
|
||||||
|
// poor mans spy function
|
||||||
|
var value = 0;
|
||||||
|
var anim = new Animation({
|
||||||
|
closure: function() { value++; }
|
||||||
|
});
|
||||||
|
|
||||||
|
var animPromise = PromiseAnimation.fromAnimation(anim);
|
||||||
|
animPromise
|
||||||
|
.then(function() {
|
||||||
|
value++;
|
||||||
|
}).then(function() {
|
||||||
|
// TODO fix
|
||||||
|
expect(value).toBe(2);
|
||||||
|
if (value !== 2) {
|
||||||
|
console.log('a test failed!!');
|
||||||
|
} else {
|
||||||
|
console.log('another test passed');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
animPromise.play();
|
||||||
|
expect(value).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
|
@ -829,19 +829,44 @@ GitEngine.prototype.fakeTeamworkStarter = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var numToMake = this.generalArgs[0] || 1;
|
|
||||||
this.validateArgBounds(this.generalArgs, 0, 1);
|
this.validateArgBounds(this.generalArgs, 0, 1);
|
||||||
for (var i = 0; i < numToMake; i++) {
|
var numToMake = this.generalArgs[0] || 1;
|
||||||
|
this.fakeTeamwork(numToMake);
|
||||||
|
};
|
||||||
|
|
||||||
|
GitEngine.prototype.fakeTeamwork = function(numToMake) {
|
||||||
|
var makeOriginCommit = _.bind(function() {
|
||||||
var id = this.getUniqueID();
|
var id = this.getUniqueID();
|
||||||
this.origin.receiveTeamwork(id, this.animationQueue);
|
this.origin.receiveTeamwork(id, this.animationQueue);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
var chainStep = function() {
|
||||||
|
makeOriginCommit();
|
||||||
|
var d = Q.defer();
|
||||||
|
setTimeout(function() { d.resolve(); }, 1000);
|
||||||
|
return d.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
var deferred = Q.defer();
|
||||||
|
var chain = deferred.promise;
|
||||||
|
|
||||||
|
for (var i = 0; i < numToMake; i++) {
|
||||||
|
// here is the deal -- we dont want to make the origin receive
|
||||||
|
// teamwork all at once because then the animation of each child
|
||||||
|
// is difficult. Instead, we will generate a promise chain which will
|
||||||
|
// produce the commit right before every animation
|
||||||
|
chain = chain.then(chainStep());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deferred.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.receiveTeamwork = function(id, animationQueue) {
|
GitEngine.prototype.receiveTeamwork = function(id, animationQueue) {
|
||||||
var newCommit = this.makeCommit([this.getCommitFromRef('HEAD')], id);
|
var newCommit = this.makeCommit([this.getCommitFromRef('HEAD')], id);
|
||||||
this.setTargetLocation(this.HEAD, newCommit);
|
this.setTargetLocation(this.HEAD, newCommit);
|
||||||
|
|
||||||
this.animationFactory.genCommitBirthAnimation(animationQueue, newCommit, this.gitVisuals);
|
//this.animationFactory.genCommitBirthAnimation(animationQueue, newCommit, this.gitVisuals);
|
||||||
|
return newCommit;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.cherrypick = function(ref) {
|
GitEngine.prototype.cherrypick = function(ref) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
var Q = require('q');
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
var GLOBAL = require('../../util/constants').GLOBAL;
|
var GLOBAL = require('../../util/constants').GLOBAL;
|
||||||
|
|
||||||
|
@ -94,12 +95,11 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
if (!options.closure || !options.deferred) {
|
if (!options.closure) {
|
||||||
throw new Error('need closure and deferred');
|
throw new Error('need closure');
|
||||||
}
|
}
|
||||||
// TODO needed?
|
// TODO needed?
|
||||||
this.set('animation', options.animation);
|
this.set('deferred', options.deferred || Q.defer());
|
||||||
this.set('deferred', options.deferred);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
play: function() {
|
play: function() {
|
||||||
|
@ -107,10 +107,8 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
// we want to resolve a deferred when the animation finishes
|
// we want to resolve a deferred when the animation finishes
|
||||||
this.get('closure')();
|
this.get('closure')();
|
||||||
setTimeout(_.bind(function() {
|
setTimeout(_.bind(function() {
|
||||||
console.log('resolving deferred');
|
|
||||||
this.get('deferred').resolve();
|
this.get('deferred').resolve();
|
||||||
}, this), this.get('duration'));
|
}, this), this.get('duration'));
|
||||||
console.log('the duration', this.get('duration'));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
then: function(func) {
|
then: function(func) {
|
||||||
|
@ -118,6 +116,12 @@ var PromiseAnimation = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
PromiseAnimation.fromAnimation = function(animation) {
|
||||||
|
return new PromiseAnimation({
|
||||||
|
closure: animation.get('closure'),
|
||||||
|
duration: animation.get('duration')
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.Animation = Animation;
|
exports.Animation = Animation;
|
||||||
exports.PromiseAnimation = PromiseAnimation;
|
exports.PromiseAnimation = PromiseAnimation;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue