From 89377b2956c3f3bbff8a2586839cb079d7b6509b Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Thu, 6 Jun 2013 08:54:42 -1000 Subject: [PATCH] working on headless, some tests fail because promise does not resolve or execute --- build/bundle.js | 114 ++++++++++++++++++++++++++--------------- spec/git.spec.js | 5 ++ src/js/git/headless.js | 6 +++ src/js/git/index.js | 39 +++++++------- 4 files changed, 105 insertions(+), 59 deletions(-) diff --git a/build/bundle.js b/build/bundle.js index 7866ee84..da5f4f28 100644 --- a/build/bundle.js +++ b/build/bundle.js @@ -7082,8 +7082,9 @@ function GitEngine(options) { this.eventBaton.stealBaton('processGitCommand', this.dispatch, this); // poor man's dependency injection - this.animationFactory = options.animationFactory || - AnimationFactory; + if (options.animationFactory) { + AnimationFactory = options.animationFactory; + } // global variable to keep track of the options given // along with the command call. @@ -7314,7 +7315,7 @@ GitEngine.prototype.makeOrigin = function(treeString) { // and then here is the crazy part -- we need the ORIGIN to refresh // itself in a separate animation. @_____@ this.origin.externalRefresh(); - this.animationFactory.playRefreshAnimationAndFinish(this.gitVisuals, this.animationQueue); + AnimationFactory.playRefreshAnimationAndFinish(this.gitVisuals, this.animationQueue); }, this); // TODO handle the case where the master target on origin is not present @@ -7661,7 +7662,7 @@ GitEngine.prototype.revert = function(whichCommits) { var chain = deferred.promise; var destBranch = this.resolveID('HEAD'); - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toRevert, destBranch @@ -7680,7 +7681,7 @@ GitEngine.prototype.revert = function(whichCommits) { }); base = newCommit; - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -7696,7 +7697,7 @@ GitEngine.prototype.revert = function(whichCommits) { // done! update our location chain = chain.then(_.bind(function() { this.setTargetLocation('HEAD', base); - return this.animationFactory.playRefreshAnimation(this.gitVisuals); + return AnimationFactory.playRefreshAnimation(this.gitVisuals); }, this)); this.animationQueue.thenFinish(chain, deferred); @@ -7755,7 +7756,7 @@ GitEngine.prototype.cherrypickStarter = function() { var chain = deferred.promise; var destinationBranch = this.resolveID('HEAD'); - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toCherrypick, destinationBranch @@ -7763,7 +7764,7 @@ GitEngine.prototype.cherrypickStarter = function() { var chainStep = _.bind(function(commit) { var newCommit = this.cherrypick(commit); - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -7830,7 +7831,7 @@ GitEngine.prototype.fetch = function() { commitsToAnimate.sort(_.bind(this.idSortFunc, this)); _.each(commitsToAnimate, function(newCommit) { - this.animationFactory.genCommitBirthAnimation( + AnimationFactory.genCommitBirthAnimation( this.animationQueue, newCommit, this.gitVisuals @@ -7840,7 +7841,7 @@ GitEngine.prototype.fetch = function() { var originLocation = this.origin.exportTree().branches.master.target; // yay! now we just set o/master and do a simple refresh this.setTargetLocation(this.refs['o/master'], this.refs[originLocation]); - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); }; GitEngine.prototype.pullStarter = function() { @@ -7886,7 +7887,7 @@ GitEngine.prototype.fakeTeamwork = function(numToMake) { var chainStep = _.bind(function() { var newCommit = makeOriginCommit(); - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.origin.gitVisuals ); @@ -7959,7 +7960,7 @@ GitEngine.prototype.commitStarter = function() { newCommit.set('commitMessage', msg); } - var promise = this.animationFactory.playCommitBirthPromiseAnimation( + var promise = AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -8467,7 +8468,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource }); } - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toRebase, destinationBranch @@ -8481,7 +8482,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource var newCommit = this.makeCommit([base], newId); base = newCommit; - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -8504,7 +8505,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource this.setTargetLocation(currentLocation, base); this.checkout(currentLocation); } - return this.animationFactory.playRefreshAnimation(this.gitVisuals); + return AnimationFactory.playRefreshAnimation(this.gitVisuals); }, this)); this.animationQueue.thenFinish(chain, deferred); @@ -8517,11 +8518,11 @@ GitEngine.prototype.mergeStarter = function() { if (newCommit === undefined) { // its just a fast forwrard - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); return; } - this.animationFactory.genCommitBirthAnimation(this.animationQueue, newCommit, this.gitVisuals); + AnimationFactory.genCommitBirthAnimation(this.animationQueue, newCommit, this.gitVisuals); }; GitEngine.prototype.merge = function(targetSource) { @@ -8761,7 +8762,7 @@ GitEngine.prototype.externalRefresh = function() { this.animationQueue = new AnimationQueue({ callback: function() {} }); - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); this.animationQueue.start(); }; @@ -8796,7 +8797,7 @@ GitEngine.prototype.dispatch = function(command, deferred) { // only add the refresh if we didn't do manual animations if (!this.animationQueue.get('animations').length && !willStartAuto) { - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); } // animation queue will call the callback when its done @@ -21894,6 +21895,22 @@ var Command = require('../models/commandModel').Command; var mock = require('../util/mock').mock; var util = require('../util'); +function getMockFactory() { + var mockFactory = {}; + for (var key in AnimationFactory) { + mockFactory[key] = function() { + return Q.defer().promise; + }; + } + // special method that does stuff + mockFactory.playRefreshAnimationAndFinish = function(gitVisuals, aQueue) { + console.log('trying to finish'); + aQueue.thenFinish(Q.defer().promise); + }; + + return mockFactory; +} + var HeadlessGit = function() { this.init(); }; @@ -21905,7 +21922,7 @@ HeadlessGit.prototype.init = function() { // here we mock visuals and animation factory so the git engine // is headless - var animationFactory = mock(AnimationFactory); + var animationFactory = getMockFactory(); var gitVisuals = mock(GitVisuals); this.gitEngine = new GitEngine({ @@ -22808,6 +22825,22 @@ var Command = require('../models/commandModel').Command; var mock = require('../util/mock').mock; var util = require('../util'); +function getMockFactory() { + var mockFactory = {}; + for (var key in AnimationFactory) { + mockFactory[key] = function() { + return Q.defer().promise; + }; + } + // special method that does stuff + mockFactory.playRefreshAnimationAndFinish = function(gitVisuals, aQueue) { + console.log('trying to finish'); + aQueue.thenFinish(Q.defer().promise); + }; + + return mockFactory; +} + var HeadlessGit = function() { this.init(); }; @@ -22819,7 +22852,7 @@ HeadlessGit.prototype.init = function() { // here we mock visuals and animation factory so the git engine // is headless - var animationFactory = mock(AnimationFactory); + var animationFactory = getMockFactory(); var gitVisuals = mock(GitVisuals); this.gitEngine = new GitEngine({ @@ -22878,8 +22911,9 @@ function GitEngine(options) { this.eventBaton.stealBaton('processGitCommand', this.dispatch, this); // poor man's dependency injection - this.animationFactory = options.animationFactory || - AnimationFactory; + if (options.animationFactory) { + AnimationFactory = options.animationFactory; + } // global variable to keep track of the options given // along with the command call. @@ -23110,7 +23144,7 @@ GitEngine.prototype.makeOrigin = function(treeString) { // and then here is the crazy part -- we need the ORIGIN to refresh // itself in a separate animation. @_____@ this.origin.externalRefresh(); - this.animationFactory.playRefreshAnimationAndFinish(this.gitVisuals, this.animationQueue); + AnimationFactory.playRefreshAnimationAndFinish(this.gitVisuals, this.animationQueue); }, this); // TODO handle the case where the master target on origin is not present @@ -23457,7 +23491,7 @@ GitEngine.prototype.revert = function(whichCommits) { var chain = deferred.promise; var destBranch = this.resolveID('HEAD'); - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toRevert, destBranch @@ -23476,7 +23510,7 @@ GitEngine.prototype.revert = function(whichCommits) { }); base = newCommit; - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -23492,7 +23526,7 @@ GitEngine.prototype.revert = function(whichCommits) { // done! update our location chain = chain.then(_.bind(function() { this.setTargetLocation('HEAD', base); - return this.animationFactory.playRefreshAnimation(this.gitVisuals); + return AnimationFactory.playRefreshAnimation(this.gitVisuals); }, this)); this.animationQueue.thenFinish(chain, deferred); @@ -23551,7 +23585,7 @@ GitEngine.prototype.cherrypickStarter = function() { var chain = deferred.promise; var destinationBranch = this.resolveID('HEAD'); - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toCherrypick, destinationBranch @@ -23559,7 +23593,7 @@ GitEngine.prototype.cherrypickStarter = function() { var chainStep = _.bind(function(commit) { var newCommit = this.cherrypick(commit); - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -23626,7 +23660,7 @@ GitEngine.prototype.fetch = function() { commitsToAnimate.sort(_.bind(this.idSortFunc, this)); _.each(commitsToAnimate, function(newCommit) { - this.animationFactory.genCommitBirthAnimation( + AnimationFactory.genCommitBirthAnimation( this.animationQueue, newCommit, this.gitVisuals @@ -23636,7 +23670,7 @@ GitEngine.prototype.fetch = function() { var originLocation = this.origin.exportTree().branches.master.target; // yay! now we just set o/master and do a simple refresh this.setTargetLocation(this.refs['o/master'], this.refs[originLocation]); - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); }; GitEngine.prototype.pullStarter = function() { @@ -23682,7 +23716,7 @@ GitEngine.prototype.fakeTeamwork = function(numToMake) { var chainStep = _.bind(function() { var newCommit = makeOriginCommit(); - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.origin.gitVisuals ); @@ -23755,7 +23789,7 @@ GitEngine.prototype.commitStarter = function() { newCommit.set('commitMessage', msg); } - var promise = this.animationFactory.playCommitBirthPromiseAnimation( + var promise = AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -24263,7 +24297,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource }); } - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toRebase, destinationBranch @@ -24277,7 +24311,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource var newCommit = this.makeCommit([base], newId); base = newCommit; - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -24300,7 +24334,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource this.setTargetLocation(currentLocation, base); this.checkout(currentLocation); } - return this.animationFactory.playRefreshAnimation(this.gitVisuals); + return AnimationFactory.playRefreshAnimation(this.gitVisuals); }, this)); this.animationQueue.thenFinish(chain, deferred); @@ -24313,11 +24347,11 @@ GitEngine.prototype.mergeStarter = function() { if (newCommit === undefined) { // its just a fast forwrard - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); return; } - this.animationFactory.genCommitBirthAnimation(this.animationQueue, newCommit, this.gitVisuals); + AnimationFactory.genCommitBirthAnimation(this.animationQueue, newCommit, this.gitVisuals); }; GitEngine.prototype.merge = function(targetSource) { @@ -24557,7 +24591,7 @@ GitEngine.prototype.externalRefresh = function() { this.animationQueue = new AnimationQueue({ callback: function() {} }); - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); this.animationQueue.start(); }; @@ -24592,7 +24626,7 @@ GitEngine.prototype.dispatch = function(command, deferred) { // only add the refresh if we didn't do manual animations if (!this.animationQueue.get('animations').length && !willStartAuto) { - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); } // animation queue will call the callback when its done diff --git a/spec/git.spec.js b/spec/git.spec.js index 13c29060..a7bcdac9 100644 --- a/spec/git.spec.js +++ b/spec/git.spec.js @@ -11,6 +11,11 @@ var compareAnswer = function(headless, expectedJSON) { var actualTree = headless.gitEngine.exportTree(); var equal = treeCompare.compareTrees(expectedTree, actualTree); + if (!equal) { + console.log('tree1', expectedTree); + console.log('tree2', actualTree); + console.log('~~~~~~~~~~~~~~~~~~~~~'); + } expect(equal).toBe(true); }; diff --git a/src/js/git/headless.js b/src/js/git/headless.js index e23db297..cceb91bd 100644 --- a/src/js/git/headless.js +++ b/src/js/git/headless.js @@ -23,6 +23,12 @@ function getMockFactory() { return Q.defer().promise; }; } + // special method that does stuff + mockFactory.playRefreshAnimationAndFinish = function(gitVisuals, aQueue) { + console.log('trying to finish'); + aQueue.thenFinish(Q.defer().promise); + }; + return mockFactory; } diff --git a/src/js/git/index.js b/src/js/git/index.js index 40ffcd5d..519989e1 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -29,8 +29,9 @@ function GitEngine(options) { this.eventBaton.stealBaton('processGitCommand', this.dispatch, this); // poor man's dependency injection - this.animationFactory = options.animationFactory || - AnimationFactory; + if (options.animationFactory) { + AnimationFactory = options.animationFactory; + } // global variable to keep track of the options given // along with the command call. @@ -261,7 +262,7 @@ GitEngine.prototype.makeOrigin = function(treeString) { // and then here is the crazy part -- we need the ORIGIN to refresh // itself in a separate animation. @_____@ this.origin.externalRefresh(); - this.animationFactory.playRefreshAnimationAndFinish(this.gitVisuals, this.animationQueue); + AnimationFactory.playRefreshAnimationAndFinish(this.gitVisuals, this.animationQueue); }, this); // TODO handle the case where the master target on origin is not present @@ -608,7 +609,7 @@ GitEngine.prototype.revert = function(whichCommits) { var chain = deferred.promise; var destBranch = this.resolveID('HEAD'); - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toRevert, destBranch @@ -627,7 +628,7 @@ GitEngine.prototype.revert = function(whichCommits) { }); base = newCommit; - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -643,7 +644,7 @@ GitEngine.prototype.revert = function(whichCommits) { // done! update our location chain = chain.then(_.bind(function() { this.setTargetLocation('HEAD', base); - return this.animationFactory.playRefreshAnimation(this.gitVisuals); + return AnimationFactory.playRefreshAnimation(this.gitVisuals); }, this)); this.animationQueue.thenFinish(chain, deferred); @@ -702,7 +703,7 @@ GitEngine.prototype.cherrypickStarter = function() { var chain = deferred.promise; var destinationBranch = this.resolveID('HEAD'); - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toCherrypick, destinationBranch @@ -710,7 +711,7 @@ GitEngine.prototype.cherrypickStarter = function() { var chainStep = _.bind(function(commit) { var newCommit = this.cherrypick(commit); - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -777,7 +778,7 @@ GitEngine.prototype.fetch = function() { commitsToAnimate.sort(_.bind(this.idSortFunc, this)); _.each(commitsToAnimate, function(newCommit) { - this.animationFactory.genCommitBirthAnimation( + AnimationFactory.genCommitBirthAnimation( this.animationQueue, newCommit, this.gitVisuals @@ -787,7 +788,7 @@ GitEngine.prototype.fetch = function() { var originLocation = this.origin.exportTree().branches.master.target; // yay! now we just set o/master and do a simple refresh this.setTargetLocation(this.refs['o/master'], this.refs[originLocation]); - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); }; GitEngine.prototype.pullStarter = function() { @@ -833,7 +834,7 @@ GitEngine.prototype.fakeTeamwork = function(numToMake) { var chainStep = _.bind(function() { var newCommit = makeOriginCommit(); - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.origin.gitVisuals ); @@ -906,7 +907,7 @@ GitEngine.prototype.commitStarter = function() { newCommit.set('commitMessage', msg); } - var promise = this.animationFactory.playCommitBirthPromiseAnimation( + var promise = AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -1414,7 +1415,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource }); } - chain = this.animationFactory.highlightEachWithPromise( + chain = AnimationFactory.highlightEachWithPromise( chain, toRebase, destinationBranch @@ -1428,7 +1429,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource var newCommit = this.makeCommit([base], newId); base = newCommit; - return this.animationFactory.playCommitBirthPromiseAnimation( + return AnimationFactory.playCommitBirthPromiseAnimation( newCommit, this.gitVisuals ); @@ -1451,7 +1452,7 @@ GitEngine.prototype.rebaseFinish = function(toRebaseRough, stopSet, targetSource this.setTargetLocation(currentLocation, base); this.checkout(currentLocation); } - return this.animationFactory.playRefreshAnimation(this.gitVisuals); + return AnimationFactory.playRefreshAnimation(this.gitVisuals); }, this)); this.animationQueue.thenFinish(chain, deferred); @@ -1464,11 +1465,11 @@ GitEngine.prototype.mergeStarter = function() { if (newCommit === undefined) { // its just a fast forwrard - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); return; } - this.animationFactory.genCommitBirthAnimation(this.animationQueue, newCommit, this.gitVisuals); + AnimationFactory.genCommitBirthAnimation(this.animationQueue, newCommit, this.gitVisuals); }; GitEngine.prototype.merge = function(targetSource) { @@ -1708,7 +1709,7 @@ GitEngine.prototype.externalRefresh = function() { this.animationQueue = new AnimationQueue({ callback: function() {} }); - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); this.animationQueue.start(); }; @@ -1743,7 +1744,7 @@ GitEngine.prototype.dispatch = function(command, deferred) { // only add the refresh if we didn't do manual animations if (!this.animationQueue.get('animations').length && !willStartAuto) { - this.animationFactory.refreshTree(this.animationQueue, this.gitVisuals); + AnimationFactory.refreshTree(this.animationQueue, this.gitVisuals); } // animation queue will call the callback when its done