Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
amend(gesture): fix hold unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Jan 26, 2015
1 parent 8364fb5 commit f592f21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/core/services/gesture/gesture.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ angular.module('material.core')
// Because we prevent scroll events, this is necessary.
if (!this.state.registeredParent) return this.cancel();

this.state.pos = {x: pointer.x, y: pointer.x};
this.state.pos = {x: pointer.x, y: pointer.y};
this.state.timeout = $timeout(angular.bind(this, function holdDelayFn() {
this.dispatchEvent(ev, '$md.hold');
this.cancel(); //we're done!
Expand Down
23 changes: 6 additions & 17 deletions src/core/services/gesture/gesture.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ describe('$mdGesture', function() {

});

xdescribe('hold', function() {
describe('hold', function() {

it('should call hold after options number of ms', inject(function($mdGesture, $document, $timeout) {
var holdSpy = jasmine.createSpy('hold');
var el = angular.element('<div>');
$mdGesture.attach(el, 'hold', {
$mdGesture.register(el, 'hold', {
delay: 333
});

Expand All @@ -273,7 +273,7 @@ describe('$mdGesture', function() {
it('should reset timeout if moving > options.maxDistance', inject(function($mdGesture, $document, $timeout) {
var holdSpy = jasmine.createSpy('hold');
var el = angular.element('<div>');
$mdGesture.attach(el, 'hold', {
$mdGesture.register(el, 'hold', {
delay: 333,
maxDistance: 10
});
Expand All @@ -286,8 +286,8 @@ describe('$mdGesture', function() {
target: el[0],
touches: [{pageX: 100, pageY: 100}]
});
expect($timeout.cancel).not.toHaveBeenCalled();
expect(holdSpy).not.toHaveBeenCalled();
$timeout.cancel.reset();

$document.triggerHandler({
type: 'touchmove',
Expand All @@ -297,38 +297,27 @@ describe('$mdGesture', function() {
expect($timeout.cancel).toHaveBeenCalled();
expect(holdSpy).not.toHaveBeenCalled();

$timeout.flush(333);
expect(holdSpy).toHaveBeenCalled();
$timeout.verifyNoPendingTasks();

// Shouldn't call it twice
$document.triggerHandler({
type: 'touchmove',
target: el[0],
touches: [{pageX: 50, pageY: 50}]
});
$timeout.verifyNoPendingTasks();
}));

it('should not reset timeout if moving < options.maxDistance', inject(function($mdGesture, $document, $timeout) {
var holdSpy = jasmine.createSpy('hold');
var el = angular.element('<div>');
$mdGesture.attach(el, 'hold', {
$mdGesture.register(el, 'hold', {
delay: 333,
maxDistance: 10
});

el.on('$md.hold', holdSpy);
spyOn($timeout, 'cancel');

$document.triggerHandler({
type: 'touchstart',
target: el[0],
touches: [{pageX: 100, pageY: 100}]
});

spyOn($timeout, 'cancel');
expect(holdSpy).not.toHaveBeenCalled();
expect($timeout.cancel).not.toHaveBeenCalled();

$document.triggerHandler({
type: 'touchmove',
Expand Down

0 comments on commit f592f21

Please sign in to comment.