Skip to content

Commit

Permalink
Animation: move loopFunction to extended
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jul 15, 2016
1 parent bd66691 commit 7d687d1
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 136 deletions.
136 changes: 0 additions & 136 deletions test/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,142 +660,6 @@ exports["Animation"] = {
this.animation.play();
},

loopFunction: function(test) {
test.expect(34);

this.animation = new Animation(this.chain);
this.animation.playLoop = {
stop: this.sandbox.spy(),
};
this.progress = 1;
this.clock = this.sandbox.useFakeTimers();
this.stop = this.sandbox.stub(this.animation, "stop");
this.next = this.sandbox.stub(this.animation, "next");
this.normalizeKeyframes = this.sandbox.stub(this.animation, "normalizeKeyframes");
this.calculateProgress = this.sandbox.stub(this.animation, "calculateProgress", function() {
this.animation.progress = this.progress;
this.animation.loopback = this.progress;
return 0.5;
}.bind(this));
this.findIndices = this.sandbox.stub(this.animation, "findIndices").returns({ left: 2, right: 3});
this.tweenedValue = this.sandbox.stub(this.animation, "tweenedValue").returns([145]);

this.animation.onloop = this.sandbox.spy();
this.animation.target = {};
this.animation.target["@@render"] = this.sandbox.spy();

this.animation.fallBackTime = 0;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 1);
test.equal(this.findIndices.callCount, 1);
test.equal(this.tweenedValue.callCount, 1);

this.animation.playLoop = null;
this.animation.fallBackTime = 0;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 2);
test.equal(this.findIndices.callCount, 2);
test.equal(this.tweenedValue.callCount, 2);

this.animation.playLoop = null;
this.animation.fallBackTime = 2;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 3);
test.equal(this.findIndices.callCount, 3);
test.equal(this.tweenedValue.callCount, 3);

this.animation.progress = 0.5;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 4);
test.equal(this.findIndices.callCount, 4);
test.equal(this.tweenedValue.callCount, 4);

this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.reverse = true;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 5);
test.equal(this.findIndices.callCount, 5);
test.equal(this.tweenedValue.callCount, 5);


this.animation.loop = true;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 6);
test.equal(this.findIndices.callCount, 6);
test.equal(this.tweenedValue.callCount, 6);

this.animation.loop = true;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = true;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 7);
test.equal(this.findIndices.callCount, 7);
test.equal(this.tweenedValue.callCount, 7);

this.animation.onloop = null;
this.animation.loop = true;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 8);
test.equal(this.findIndices.callCount, 8);
test.equal(this.tweenedValue.callCount, 8);

this.stop.reset();
this.animation.loop = false;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.stop.callCount, 1);
test.equal(this.calculateProgress.callCount, 9);
test.equal(this.findIndices.callCount, 9);
test.equal(this.tweenedValue.callCount, 9);

this.stop.reset();
this.animation.loop = false;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.segments.push(1, 2, 3);
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.stop.callCount, 1);
test.equal(this.next.callCount, 1);
test.equal(this.calculateProgress.callCount, 10);
test.equal(this.findIndices.callCount, 10);
test.equal(this.tweenedValue.callCount, 10);

this.animation.oncomplete = function() {
test.done();
};

this.animation.loopFunction({ calledAt: 1 });

test.equal(this.animation.target["@@render"].callCount, 11);
},

};

exports["Animation.Segment"] = {
Expand Down
173 changes: 173 additions & 0 deletions test/extended/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,176 @@ exports["Animation"] = {
}

};


exports["Animation"] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();

this.play = this.sandbox.stub(Animation.prototype, "play");

this.animation = new Animation({});
this.chain = {
result: [],
"@@render": function(args) {
this.result = this.result.concat(args);
},
"@@normalize": function(keyFrames) {
var last = [50, 0, -20];

// If user passes null as the first element in keyFrames use current position
if (keyFrames[0] === null) {
keyFrames[0] = {
position: last
};
}

return keyFrames;
}
};

done();
},

tearDown: function(done) {
this.sandbox.restore();
done();
},

loopFunction: function(test) {
test.expect(34);

this.animation = new Animation(this.chain);
this.animation.playLoop = {
stop: this.sandbox.spy(),
};
this.progress = 1;
this.clock = this.sandbox.useFakeTimers();
this.stop = this.sandbox.stub(this.animation, "stop");
this.next = this.sandbox.stub(this.animation, "next");
this.normalizeKeyframes = this.sandbox.stub(this.animation, "normalizeKeyframes");
this.calculateProgress = this.sandbox.stub(this.animation, "calculateProgress", function() {
this.animation.progress = this.progress;
this.animation.loopback = this.progress;
return this.progress;
}.bind(this));
this.findIndices = this.sandbox.stub(this.animation, "findIndices").returns({ left: 2, right: 3});
this.tweenedValue = this.sandbox.stub(this.animation, "tweenedValue").returns([145]);

this.animation.onloop = this.sandbox.spy();
this.animation.target = {};
this.animation.target["@@render"] = this.sandbox.spy();

this.animation.fallBackTime = 0;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 1);
test.equal(this.findIndices.callCount, 1);
test.equal(this.tweenedValue.callCount, 1);

this.animation.playLoop = null;
this.animation.fallBackTime = 0;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 2);
test.equal(this.findIndices.callCount, 2);
test.equal(this.tweenedValue.callCount, 2);

this.animation.playLoop = null;
this.animation.fallBackTime = 2;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 3);
test.equal(this.findIndices.callCount, 3);
test.equal(this.tweenedValue.callCount, 3);

this.animation.progress = 0.5;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 4);
test.equal(this.findIndices.callCount, 4);
test.equal(this.tweenedValue.callCount, 4);

this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.reverse = true;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 5);
test.equal(this.findIndices.callCount, 5);
test.equal(this.tweenedValue.callCount, 5);


this.animation.loop = true;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 6);
test.equal(this.findIndices.callCount, 6);
test.equal(this.tweenedValue.callCount, 6);

this.animation.loop = true;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = true;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 7);
test.equal(this.findIndices.callCount, 7);
test.equal(this.tweenedValue.callCount, 7);

this.animation.onloop = null;
this.animation.loop = true;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.calculateProgress.callCount, 8);
test.equal(this.findIndices.callCount, 8);
test.equal(this.tweenedValue.callCount, 8);

this.stop.reset();
this.animation.loop = false;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.stop.callCount, 1);
test.equal(this.calculateProgress.callCount, 9);
test.equal(this.findIndices.callCount, 9);
test.equal(this.tweenedValue.callCount, 9);

this.stop.reset();
this.animation.loop = false;
this.animation.progress = 1;
this.animation.loopback = 1;
this.animation.metronomic = false;
this.animation.reverse = false;
this.animation.segments.push(1, 2, 3);
this.animation.loopFunction({ calledAt: 1 });

test.equal(this.stop.callCount, 1);
test.equal(this.next.callCount, 1);
test.equal(this.calculateProgress.callCount, 10);
test.equal(this.findIndices.callCount, 10);
test.equal(this.tweenedValue.callCount, 10);

this.animation.oncomplete = function() {
test.done();
};

this.animation.loopFunction({ calledAt: 1 });

test.equal(this.animation.target["@@render"].callCount, 11);
},

};

0 comments on commit 7d687d1

Please sign in to comment.