From 94ec84e7b9c89358dc00e4039009af9e287bbd05 Mon Sep 17 00:00:00 2001
From: Brian Ford
Date: Fri, 9 Aug 2013 10:02:48 -0700
Subject: chore(ngMobile): rename module ngTouch and file to angular-touch.js
BREAKING CHANGE: since all the code in the ngMobile module is touch related,
we are renaming the module to ngTouch.
To migrate, please replace all references to "ngMobile" with "ngTouch" and
"angular-mobile.js" to "angular-touch.js".
Closes #3526
---
test/ngTouch/directive/ngClickSpec.js | 380 ++++++++++++++++++++++++++++++++++
1 file changed, 380 insertions(+)
create mode 100644 test/ngTouch/directive/ngClickSpec.js
(limited to 'test/ngTouch/directive/ngClickSpec.js')
diff --git a/test/ngTouch/directive/ngClickSpec.js b/test/ngTouch/directive/ngClickSpec.js
new file mode 100644
index 00000000..2a11adee
--- /dev/null
+++ b/test/ngTouch/directive/ngClickSpec.js
@@ -0,0 +1,380 @@
+'use strict';
+
+describe('ngClick (touch)', function() {
+ var element, time, orig_now;
+
+ // TODO(braden): Once we have other touch-friendly browsers on CI, allow them here.
+ // Currently Firefox and IE refuse to fire touch events.
+ var chrome = /chrome/.test(navigator.userAgent.toLowerCase());
+ if (!chrome) {
+ return;
+ }
+
+ function mockTime() {
+ return time;
+ }
+
+
+ beforeEach(function() {
+ module('ngTouch');
+ orig_now = Date.now;
+ time = 0;
+ Date.now = mockTime;
+ });
+
+ afterEach(function() {
+ dealoc(element);
+ Date.now = orig_now;
+ });
+
+
+ it('should get called on a tap', inject(function($rootScope, $compile) {
+ element = $compile('
')($rootScope);
+ $rootScope.$digest();
+ expect($rootScope.tapped).toBeUndefined();
+
+ browserTrigger(element, 'touchstart');
+ browserTrigger(element, 'touchend');
+ expect($rootScope.tapped).toEqual(true);
+ }));
+
+
+ it('should pass event object', inject(function($rootScope, $compile) {
+ element = $compile('')($rootScope);
+ $rootScope.$digest();
+
+ browserTrigger(element, 'touchstart');
+ browserTrigger(element, 'touchend');
+ expect($rootScope.event).toBeDefined();
+ }));
+
+
+ it('should not click if the touch is held too long', inject(function($rootScope, $compile, $rootElement) {
+ element = $compile('')($rootScope);
+ $rootElement.append(element);
+ $rootScope.count = 0;
+ $rootScope.$digest();
+
+ expect($rootScope.count).toBe(0);
+
+ time = 10;
+ browserTrigger(element, 'touchstart', [], 10, 10);
+
+ time = 900;
+ browserTrigger(element, 'touchend', [], 10, 10);
+
+ expect($rootScope.count).toBe(0);
+ }));
+
+
+ it('should not click if the touchend is too far away', inject(function($rootScope, $compile, $rootElement) {
+ element = $compile('')($rootScope);
+ $rootElement.append(element);
+ $rootScope.$digest();
+
+ expect($rootScope.tapped).toBeUndefined();
+
+ browserTrigger(element, 'touchstart', [], 10, 10);
+ browserTrigger(element, 'touchend', [], 400, 400);
+
+ expect($rootScope.tapped).toBeUndefined();
+ }));
+
+
+ it('should not click if a touchmove comes before touchend', inject(function($rootScope, $compile, $rootElement) {
+ element = $compile('')($rootScope);
+ $rootElement.append(element);
+ $rootScope.$digest();
+
+ expect($rootScope.tapped).toBeUndefined();
+
+ browserTrigger(element, 'touchstart', [], 10, 10);
+ browserTrigger(element, 'touchmove');
+ browserTrigger(element, 'touchend', [], 400, 400);
+
+ expect($rootScope.tapped).toBeUndefined();
+ }));
+
+ it('should add the CSS class while the element is held down, and then remove it', inject(function($rootScope, $compile, $rootElement) {
+ element = $compile('')($rootScope);
+ $rootElement.append(element);
+ $rootScope.$digest();
+ expect($rootScope.tapped).toBeUndefined();
+
+ var CSS_CLASS = 'ng-click-active';
+
+ expect(element.hasClass(CSS_CLASS)).toBe(false);
+ browserTrigger(element, 'touchstart', 10, 10);
+ expect(element.hasClass(CSS_CLASS)).toBe(true);
+ browserTrigger(element, 'touchend', 10, 10);
+ expect(element.hasClass(CSS_CLASS)).toBe(false);
+ expect($rootScope.tapped).toBe(true);
+ }));
+
+
+ describe('the clickbuster', function() {
+ var element1, element2;
+
+ beforeEach(inject(function($rootElement, $document) {
+ $document.find('body').append($rootElement);
+ }));
+
+ afterEach(inject(function($document) {
+ $document.find('body').html('');
+ }));
+
+
+ it('should cancel the following click event', inject(function($rootScope, $compile, $rootElement, $document) {
+ element = $compile('')($rootScope);
+ $rootElement.append(element);
+
+ $rootScope.count = 0;
+ $rootScope.$digest();
+
+ expect($rootScope.count).toBe(0);
+
+ // Fire touchstart at 10ms, touchend at 50ms, the click at 300ms.
+ time = 10;
+ browserTrigger(element, 'touchstart', [], 10, 10);
+
+ time = 50;
+ browserTrigger(element, 'touchend', [], 10, 10);
+
+ expect($rootScope.count).toBe(1);
+
+ time = 100;
+ browserTrigger(element, 'click', [], 10, 10);
+
+ expect($rootScope.count).toBe(1);
+ }));
+
+
+ it('should cancel the following click event even when the element has changed', inject(
+ function($rootScope, $compile, $rootElement) {
+ $rootElement.append(
+ '