Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
"predef": [ | ||
"angular", | ||
"module", | ||
"inject" | ||
"inject", | ||
"FastClick" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
}); |