test_multiple_taps.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var el, hammer;
  2. var tripleTapCount = 0,
  3. doubleTapCount = 0,
  4. tapCount = 0;
  5. module('Tap delay', {
  6. setup: function() {
  7. el = utils.createHitArea();
  8. hammer = new Hammer(el, {recognizers: []});
  9. var tap = new Hammer.Tap();
  10. var doubleTap = new Hammer.Tap({event: 'doubleTap', taps: 2 });
  11. var tripleTap = new Hammer.Tap({event: 'tripleTap', taps: 3 });
  12. hammer.add([tripleTap, doubleTap, tap]);
  13. tripleTap.recognizeWith([doubleTap, tap]);
  14. doubleTap.recognizeWith(tap);
  15. doubleTap.requireFailure(tripleTap);
  16. tap.requireFailure([tripleTap, doubleTap]);
  17. tripleTapCount = 0;
  18. doubleTapCount = 0;
  19. tapCount = 0;
  20. hammer.on('tap', function() {
  21. tapCount++;
  22. });
  23. hammer.on('doubleTap', function() {
  24. doubleTapCount++;
  25. });
  26. hammer.on('tripleTap', function() {
  27. tripleTapCount++;
  28. });
  29. },
  30. teardown: function() {
  31. hammer.destroy();
  32. }
  33. });
  34. asyncTest('When a tripleTap is fired, doubleTap and Tap should not be recognized', function() {
  35. expect(3);
  36. utils.dispatchTouchEvent(el, 'start', 50, 50);
  37. utils.dispatchTouchEvent(el, 'end', 50, 50);
  38. utils.dispatchTouchEvent(el, 'start', 50, 50);
  39. utils.dispatchTouchEvent(el, 'end', 50, 50);
  40. utils.dispatchTouchEvent(el, 'start', 50, 50);
  41. utils.dispatchTouchEvent(el, 'end', 50, 50);
  42. setTimeout(function() {
  43. start();
  44. equal(tripleTapCount, 1, 'one tripletap event');
  45. equal(doubleTapCount, 0, 'no doubletap event');
  46. equal(tapCount, 0, 'no singletap event');
  47. }, 350);
  48. });
  49. asyncTest('When a doubleTap is fired, tripleTap and Tap should not be recognized', function() {
  50. expect(3);
  51. utils.dispatchTouchEvent(el, 'start', 50, 50);
  52. utils.dispatchTouchEvent(el, 'end', 50, 50);
  53. utils.dispatchTouchEvent(el, 'start', 50, 50);
  54. utils.dispatchTouchEvent(el, 'end', 50, 50);
  55. setTimeout(function() {
  56. start();
  57. equal(tripleTapCount, 0);
  58. equal(doubleTapCount, 1);
  59. equal(tapCount, 0);
  60. }, 350);
  61. });
  62. asyncTest('When a tap is fired, tripleTap and doubleTap should not be recognized', function() {
  63. expect(3);
  64. utils.dispatchTouchEvent(el, 'start', 50, 50);
  65. utils.dispatchTouchEvent(el, 'end', 50, 50);
  66. setTimeout(function() {
  67. start();
  68. equal(tripleTapCount, 0);
  69. equal(doubleTapCount, 0);
  70. equal(tapCount, 1);
  71. }, 350);
  72. });