From 9ef8fe573334e5679808e860cb43c6b66bee2b08 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 27 Jun 2016 23:37:26 +0200 Subject: [PATCH] Fix MockInteractions.track to provide correct step values --- mock-interactions.js | 4 ++-- test/mock-interactions.html | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/mock-interactions.js b/mock-interactions.js index 9f717f9..42489db 100644 --- a/mock-interactions.js +++ b/mock-interactions.js @@ -151,8 +151,8 @@ */ function move(node, fromXY, toXY, steps) { steps = steps || 5; - var dx = Math.round((fromXY.x - toXY.x) / steps); - var dy = Math.round((fromXY.y - toXY.y) / steps); + var dx = Math.round((toXY.x - fromXY.x) / steps); + var dy = Math.round((toXY.y - fromXY.y) / steps); var xy = { x: fromXY.x, y: fromXY.y diff --git a/test/mock-interactions.html b/test/mock-interactions.html index 92aa96a..d4be619 100644 --- a/test/mock-interactions.html +++ b/test/mock-interactions.html @@ -36,11 +36,8 @@ button = fixture('TrivialButton'); }); - teardown(function(done) { - // TODO(cdata): Remove when polymer/polymer#3540 is resolved - window.setTimeout(function() { - done(); - }, 2500); + teardown(function() { + Polymer.Gestures.resetMouseCanceller(); }); suite('simulating tap', function() { @@ -86,6 +83,21 @@ }); }); }); + + suite('simulating track', function() { + test('dispatches events with correct steps', function() { + var spy = sinon.spy(); + button.handleTrack = spy; + button.listen(button, 'track', 'handleTrack'); + MockInteractions.track(button, 50, 50, 5); + + var steps = [10, 20, 30, 40, 50, 50]; + for (var i = 0, l = steps.length; i < l; i++) { + expect(spy.getCall(i).args[0].detail.dx).to.be.eql(steps[i]); + expect(spy.getCall(i).args[0].detail.dy).to.be.eql(steps[i]); + } + }); + }); });