Permalink
Browse files

Altered gallery tests to use done(fn) syntax.

  • Loading branch information...
1 parent 8afaf6e commit 9767e964f4c8d42c5c133ef378e4cad992df03c4 @lightsofapollo lightsofapollo committed May 25, 2012
@@ -55,39 +55,43 @@ suite('GestureDetector', function() {
test('tap', function(done) {
SyntheticGestures.tap(element, function() {
- assert.length(events, 1);
- assert.equal(events[0].type, 'tap');
- assert.equal(events[0].detail.clientX, 100);
- assert.equal(events[0].detail.clientY, 200);
- done();
+ done(function() {
+ assert.length(events, 1);
+ assert.equal(events[0].type, 'tap');
+ assert.equal(events[0].detail.clientX, 100);
+ assert.equal(events[0].detail.clientY, 200);
+ });
}, 100, 200);
});
test('mousetap', function(done) {
SyntheticGestures.mousetap(element, function() {
- assert.length(events, 1);
- assert.equal(events[0].type, 'tap');
- assert.equal(events[0].detail.clientX, 100);
- assert.equal(events[0].detail.clientY, 200);
- done();
+ done(function() {
+ assert.length(events, 1);
+ assert.equal(events[0].type, 'tap');
+ assert.equal(events[0].detail.clientX, 100);
+ assert.equal(events[0].detail.clientY, 200);
+ });
}, 100, 200);
});
test('dbltap', function(done) {
SyntheticGestures.dbltap(element, function() {
- assert.equal(eventseq(), 'tap tap dbltap');
- assert.equal(events[2].detail.clientX, 100);
- assert.equal(events[2].detail.clientY, 200);
- done();
+ done(function() {
+ assert.equal(eventseq(), 'tap tap dbltap');
+ assert.equal(events[2].detail.clientX, 100);
+ assert.equal(events[2].detail.clientY, 200);
+ });
}, 100, 200);
});
test('mousedbltap', function(done) {
SyntheticGestures.mousedbltap(element, function() {
- assert.equal(eventseq(), 'tap tap dbltap');
- assert.equal(events[2].detail.clientX, 100);
- assert.equal(events[2].detail.clientY, 200);
- done();
+ done(function() {
+ assert.equal(eventseq(), 'tap tap dbltap');
+ assert.equal(events[2].detail.clientX, 100);
+ assert.equal(events[2].detail.clientY, 200);
+ });
}, 100, 200);
});
@@ -117,39 +121,39 @@ suite('GestureDetector', function() {
SyntheticGestures.swipe(element, s.x0, s.y0, s.x1, s.y1,
200, checkswipe);
function checkswipe() {
- assert.match(eventseq(), /(pan )+swipe/);
- var e = events[events.length - 1];
- assert.equal(e.detail.start.clientX, s.x0);
- assert.equal(e.detail.start.clientY, s.y0);
- assert.equal(e.detail.end.clientX, s.x1);
- assert.equal(e.detail.end.clientY, s.y1);
- assert.equal(e.detail.dx, s.x1 - s.x0);
- assert.equal(e.detail.dy, s.y1 - s.y0);
-
- assert.equal(e.detail.direction, s.direction);
-
- var angle = Math.atan2(s.y1 - s.y0, s.x1 - s.x0) * 180 / Math.PI;
- if (angle < 0)
- angle += 360;
- between(e.detail.angle, angle - 1, angle + 1);
-
- var lastpan = events[events.length - 2];
- assert.equal(lastpan.detail.absolute.dx, s.x1 - s.x0);
- assert.equal(lastpan.detail.absolute.dy, s.y1 - s.y0);
- // Add up the relative deltas for all pans
- var dx = 0, dy = 0;
- events.forEach(function(e) {
- if (e.type === 'pan') {
- dx += e.detail.relative.dx;
- dy += e.detail.relative.dy;
- assert.equal(dx, e.detail.absolute.dx);
- assert.equal(dy, e.detail.absolute.dy);
- }
+ done(function() {
+ assert.match(eventseq(), /(pan )+swipe/);
+ var e = events[events.length - 1];
+ assert.equal(e.detail.start.clientX, s.x0);
+ assert.equal(e.detail.start.clientY, s.y0);
+ assert.equal(e.detail.end.clientX, s.x1);
+ assert.equal(e.detail.end.clientY, s.y1);
+ assert.equal(e.detail.dx, s.x1 - s.x0);
+ assert.equal(e.detail.dy, s.y1 - s.y0);
+
+ assert.equal(e.detail.direction, s.direction);
+
+ var angle = Math.atan2(s.y1 - s.y0, s.x1 - s.x0) * 180 / Math.PI;
+ if (angle < 0)
+ angle += 360;
+ between(e.detail.angle, angle - 1, angle + 1);
+
+ var lastpan = events[events.length - 2];
+ assert.equal(lastpan.detail.absolute.dx, s.x1 - s.x0);
+ assert.equal(lastpan.detail.absolute.dy, s.y1 - s.y0);
+ // Add up the relative deltas for all pans
+ var dx = 0, dy = 0;
+ events.forEach(function(e) {
+ if (e.type === 'pan') {
+ dx += e.detail.relative.dx;
+ dy += e.detail.relative.dy;
+ assert.equal(dx, e.detail.absolute.dx);
+ assert.equal(dy, e.detail.absolute.dy);
+ }
+ });
+ assert.equal(dx, s.x1 - s.x0);
+ assert.equal(dy, s.y1 - s.y0);
});
- assert.equal(dx, s.x1 - s.x0);
- assert.equal(dy, s.y1 - s.y0);
-
- done();
}
});
});
@@ -159,39 +163,39 @@ suite('GestureDetector', function() {
SyntheticGestures.mouseswipe(element, s.x0, s.y0, s.x1, s.y1,
200, checkswipe);
function checkswipe() {
- assert.match(eventseq(), /(pan )+swipe/);
- var e = events[events.length - 1];
- assert.equal(e.detail.start.clientX, s.x0);
- assert.equal(e.detail.start.clientY, s.y0);
- assert.equal(e.detail.end.clientX, s.x1);
- assert.equal(e.detail.end.clientY, s.y1);
- assert.equal(e.detail.dx, s.x1 - s.x0);
- assert.equal(e.detail.dy, s.y1 - s.y0);
-
- assert.equal(e.detail.direction, s.direction);
-
- var angle = Math.atan2(s.y1 - s.y0, s.x1 - s.x0) * 180 / Math.PI;
- if (angle < 0)
- angle += 360;
- between(e.detail.angle, angle - 1, angle + 1);
-
- var lastpan = events[events.length - 2];
- assert.equal(lastpan.detail.absolute.dx, s.x1 - s.x0);
- assert.equal(lastpan.detail.absolute.dy, s.y1 - s.y0);
- // Add up the relative deltas for all pans
- var dx = 0, dy = 0;
- events.forEach(function(e) {
- if (e.type === 'pan') {
- dx += e.detail.relative.dx;
- dy += e.detail.relative.dy;
- assert.equal(dx, e.detail.absolute.dx);
- assert.equal(dy, e.detail.absolute.dy);
- }
+ done(function() {
+ assert.match(eventseq(), /(pan )+swipe/);
+ var e = events[events.length - 1];
+ assert.equal(e.detail.start.clientX, s.x0);
+ assert.equal(e.detail.start.clientY, s.y0);
+ assert.equal(e.detail.end.clientX, s.x1);
+ assert.equal(e.detail.end.clientY, s.y1);
+ assert.equal(e.detail.dx, s.x1 - s.x0);
+ assert.equal(e.detail.dy, s.y1 - s.y0);
+
+ assert.equal(e.detail.direction, s.direction);
+
+ var angle = Math.atan2(s.y1 - s.y0, s.x1 - s.x0) * 180 / Math.PI;
+ if (angle < 0)
+ angle += 360;
+ between(e.detail.angle, angle - 1, angle + 1);
+
+ var lastpan = events[events.length - 2];
+ assert.equal(lastpan.detail.absolute.dx, s.x1 - s.x0);
+ assert.equal(lastpan.detail.absolute.dy, s.y1 - s.y0);
+ // Add up the relative deltas for all pans
+ var dx = 0, dy = 0;
+ events.forEach(function(e) {
+ if (e.type === 'pan') {
+ dx += e.detail.relative.dx;
+ dy += e.detail.relative.dy;
+ assert.equal(dx, e.detail.absolute.dx);
+ assert.equal(dy, e.detail.absolute.dy);
+ }
+ });
+ assert.equal(dx, s.x1 - s.x0);
+ assert.equal(dy, s.y1 - s.y0);
});
- assert.equal(dx, s.x1 - s.x0);
- assert.equal(dy, s.y1 - s.y0);
-
- done();
}
});
});
@@ -207,29 +211,30 @@ suite('GestureDetector', function() {
{ x0: 200, y0: 200, x1: 0, y1: 200, scale: 3, duration: 150 },
{ x0: 200, y0: 200, x1: 0, y1: 200, scale: .3, duration: 150 }
];
-
+
pinches.forEach(function(p, index) {
var testname = 'Pinch ' + index +
- ': (' + p.x0 + ',' + p.y0 + ')' +
- ' & (' + p.x1 + ',' + p.y1 + ')' +
+ ': (' + p.x0 + ',' + p.y0 + ')' +
+ ' & (' + p.x1 + ',' + p.y1 + ')' +
' scale: ' + p.scale;
test(testname, function(done) {
SyntheticGestures.pinch(element, p.x0, p.y0, p.x1, p.y1,
p.scale, p.duration, checkpinch);
function checkpinch() {
- assert.match(eventseq(), /(transform )*transform/);
- var e = events[events.length - 1];
- var d = e.detail;
- between(d.absolute.scale, 0.95 * p.scale, 1.05 * p.scale);
- assert.equal(d.absolute.rotate, 0);
- assert.equal(d.relative.rotate, 0);
-
- // compute the product of all the relative scales
- var s = 1.0;
- events.forEach(function(e) { s *= e.detail.relative.scale; });
- between(s, 0.95 * p.scale, 1.05 * p.scale);
- done();
+ done(function() {
+ assert.match(eventseq(), /(transform )*transform/);
+ var e = events[events.length - 1];
+ var d = e.detail;
+ between(d.absolute.scale, 0.95 * p.scale, 1.05 * p.scale);
+ assert.equal(d.absolute.rotate, 0);
+ assert.equal(d.relative.rotate, 0);
+
+ // compute the product of all the relative scales
+ var s = 1.0;
+ events.forEach(function(e) { s *= e.detail.relative.scale; });
+ between(s, 0.95 * p.scale, 1.05 * p.scale);
+ });
}
});
});
@@ -245,37 +250,37 @@ suite('GestureDetector', function() {
SyntheticGestures.hold(element, 1250, s.x0, s.y0, s.x1, s.y1,
200, checkhold);
function checkhold() {
- assert.match(eventseq(), /holdstart (holdmove )*holdend/);
-
- // Check start details
- var d = events[0].detail;
-
- assert.equal(d.clientX, s.x0);
- assert.equal(d.clientY, s.y0);
-
- // Check end details
- d = events[events.length - 1].detail;
- assert.equal(d.start.clientX, s.x0);
- assert.equal(d.start.clientY, s.y0);
- assert.equal(d.end.clientX, s.x1);
- assert.equal(d.end.clientY, s.y1);
- assert.equal(d.dx, s.x1 - s.x0);
- assert.equal(d.dy, s.y1 - s.y0);
-
- // Check relative vs absolute for all the holdmove events
- var dx = 0, dy = 0;
- events.forEach(function(e) {
- if (e.type === 'holdmove') {
- dx += e.detail.relative.dx;
- dy += e.detail.relative.dy;
- assert.equal(dx, e.detail.absolute.dx);
- assert.equal(dy, e.detail.absolute.dy);
- }
+ done(function() {
+ assert.match(eventseq(), /holdstart (holdmove )*holdend/);
+
+ // Check start details
+ var d = events[0].detail;
+
+ assert.equal(d.clientX, s.x0);
+ assert.equal(d.clientY, s.y0);
+
+ // Check end details
+ d = events[events.length - 1].detail;
+ assert.equal(d.start.clientX, s.x0);
+ assert.equal(d.start.clientY, s.y0);
+ assert.equal(d.end.clientX, s.x1);
+ assert.equal(d.end.clientY, s.y1);
+ assert.equal(d.dx, s.x1 - s.x0);
+ assert.equal(d.dy, s.y1 - s.y0);
+
+ // Check relative vs absolute for all the holdmove events
+ var dx = 0, dy = 0;
+ events.forEach(function(e) {
+ if (e.type === 'holdmove') {
+ dx += e.detail.relative.dx;
+ dy += e.detail.relative.dy;
+ assert.equal(dx, e.detail.absolute.dx);
+ assert.equal(dy, e.detail.absolute.dy);
+ }
+ });
+ assert.equal(dx, s.x1 - s.x0);
+ assert.equal(dy, s.y1 - s.y0);
});
- assert.equal(dx, s.x1 - s.x0);
- assert.equal(dy, s.y1 - s.y0);
-
- done();
}
});
});
@@ -286,35 +291,36 @@ suite('GestureDetector', function() {
SyntheticGestures.mousehold(element, 1250, s.x0, s.y0, s.x1, s.y1,
100, checkhold);
function checkhold() {
- assert.match(eventseq(), /holdstart (holdmove )*holdend/);
-
- // Check start details
- var d = events[0].detail;
- assert.equal(d.clientX, s.x0);
- assert.equal(d.clientY, s.y0);
-
- // Check end details
- var d = events[events.length - 1].detail;
- assert.equal(d.start.clientX, s.x0);
- assert.equal(d.start.clientY, s.y0);
- assert.equal(d.end.clientX, s.x1);
- assert.equal(d.end.clientY, s.y1);
- assert.equal(d.dx, s.x1 - s.x0);
- assert.equal(d.dy, s.y1 - s.y0);
-
- // Check relative vs absolute for all the holdmove events
- var dx = 0, dy = 0;
- events.forEach(function(e) {
- if (e.type === 'holdmove') {
- dx += e.detail.relative.dx;
- dy += e.detail.relative.dy;
- assert.equal(dx, e.detail.absolute.dx);
- assert.equal(dy, e.detail.absolute.dy);
- }
+ done(function() {
+ assert.match(eventseq(), /holdstart (holdmove )*holdend/);
+
+ // Check start details
+ var d = events[0].detail;
+ assert.equal(d.clientX, s.x0);
+ assert.equal(d.clientY, s.y0);
+
+ // Check end details
+ var d = events[events.length - 1].detail;
+ assert.equal(d.start.clientX, s.x0);
+ assert.equal(d.start.clientY, s.y0);
+ assert.equal(d.end.clientX, s.x1);
+ assert.equal(d.end.clientY, s.y1);
+ assert.equal(d.dx, s.x1 - s.x0);
+ assert.equal(d.dy, s.y1 - s.y0);
+
+ // Check relative vs absolute for all the holdmove events
+ var dx = 0, dy = 0;
+ events.forEach(function(e) {
+ if (e.type === 'holdmove') {
+ dx += e.detail.relative.dx;
+ dy += e.detail.relative.dy;
+ assert.equal(dx, e.detail.absolute.dx);
+ assert.equal(dy, e.detail.absolute.dy);
+ }
+ });
+ assert.equal(dx, s.x1 - s.x0);
+ assert.equal(dy, s.y1 - s.y0);
});
- assert.equal(dx, s.x1 - s.x0);
- assert.equal(dy, s.y1 - s.y0);
- done();
}
});
});
Oops, something went wrong.

0 comments on commit 9767e96

Please sign in to comment.