Skip to content

Commit

Permalink
unit test fastclick
Browse files Browse the repository at this point in the history
  • Loading branch information
mcasimir committed Mar 20, 2016
1 parent ee3ec4f commit c3378b2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Expand Up @@ -9,6 +9,7 @@
"predef": [
"angular",
"module",
"inject"
"inject",
"FastClick"
]
}
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -5,4 +5,6 @@ env:
global:
- secure: gaEfbACVQEtdXK2cJgNphqxYCJzNgKBZuE9EgD6TsxKKPtLgBvpk/yA2VGX9j1ppn+QUmYsQEc+yXyPXaY3cVPAUDoYpJRS3gq3dz++pQrNQjxYsG2j9rCoN5TGAUau3w8GVMdLpUXxfVx5hvocP4nc9e/UKjva4H+LRzi5h3uk=
- secure: MFZuzAYhk8Y4HBCpczi8pK0Xy2TvzO7/SGt/FbyRBvGWOzRNW70L+Yf//sGMDhMfXki6gGPGJE/L32P6Wma2aPdk3T2+7s7y4LIngcgTa0XhpdUt3IyRx/P8MgyEya0rEAL+uMPp0qCywS9syl6TtFHOnxUn+R9fkdz+hRwZAIU=
script: node_modules/.bin/gulp test:ci
script:
- node_modules/.bin/gulp test:ci
- node_modules/.bin/codecov
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -23,6 +23,7 @@
"angular": "1.4.9",
"angular-mocks": "1.4.9",
"bootstrap": "3.3.6",
"codecov": "1.0.1",
"del": "2.2.0",
"fastclick": "1.0.6",
"fg-overthrow": "0.7.1",
Expand Down
78 changes: 78 additions & 0 deletions test/unit/core/fastClick.spec.js
@@ -0,0 +1,78 @@
'use strict';

describe('core', function() {
describe('fastclick', function() {
var scope;
var compile;
var fastclickOnTouchEnd;

beforeEach(function() {
FastClick.notNeeded = function() {
return false;
};

spyOn(FastClick, 'attach').and.callThrough();
spyOn(FastClick.prototype, 'onTouchEnd').and.callThrough();
fastclickOnTouchEnd = FastClick.prototype.onTouchEnd;

module('mobile-angular-ui.core');

inject(function($rootScope, $compile) {
scope = $rootScope.$new();
compile = $compile;
});
});

it('should attach to document.body on run', function() {
expect(FastClick.attach).toHaveBeenCalledWith(document.body);
});

it('forwards touchend events to original handler', function() {
var event = new Event('touchend');
event.changedTouches = [{}];
document.body.dispatchEvent(event);
expect(fastclickOnTouchEnd).toHaveBeenCalled();
});

it('adapts touchend events if missing event.changedTouches', function() {
var event = new Event('touchend');
document.body.dispatchEvent(event);
expect(fastclickOnTouchEnd).toHaveBeenCalledWith(jasmine.objectContaining({
changedTouches: [{}]
}));
});

it('should add needsclick to input', function() {
var elem = angular.element(
'<input type="text">'
);

elem = compile(elem)(scope);
scope.$digest();

expect(elem.attr('class')).toContain('needsclick');
});

it('should add needsclick to select', function() {
var elem = angular.element(
'<select></select>'
);

elem = compile(elem)(scope);
scope.$digest();

expect(elem.attr('class')).toContain('needsclick');
});

it('should add needsclick to textarea', function() {
var elem = angular.element(
'<textarea></textarea>'
);

elem = compile(elem)(scope);
scope.$digest();

expect(elem.attr('class')).toContain('needsclick');
});
});
});

0 comments on commit c3378b2

Please sign in to comment.