1
1
describe ( 'uiGridHeaderCell' , function ( ) {
2
- var grid , $scope , $compile , $document , $timeout , $window , recompile , $animate , uiGridConstants , columnDefs ;
2
+ var grid , $scope , $compile , $document , $timeout , $window , recompile , $animate , uiGridConstants , gridUtil , columnDefs ;
3
+
4
+ var downEvent , upEvent , clickEvent ;
3
5
4
6
var data = [
5
7
{ "name" : "Ethel Price" , "gender" : "female" , "company" : "Enersol" } ,
@@ -23,14 +25,27 @@ describe('uiGridHeaderCell', function () {
23
25
24
26
beforeEach ( module ( 'ui.grid' ) ) ;
25
27
26
- beforeEach ( inject ( function ( _$compile_ , $rootScope , _$document_ , _$timeout_ , _$window_ , _$animate_ , _uiGridConstants_ ) {
28
+ beforeEach ( inject ( function ( _$compile_ , $rootScope , _$document_ , _$timeout_ , _$window_ , _$animate_ , _uiGridConstants_ , _gridUtil_ ) {
27
29
$scope = $rootScope ;
28
30
$compile = _$compile_ ;
29
31
$document = _$document_ ;
30
32
$timeout = _$timeout_ ;
31
33
$window = _$window_ ;
32
34
$animate = _$animate_ ;
33
35
uiGridConstants = _uiGridConstants_ ;
36
+ gridUtil = _gridUtil_ ;
37
+
38
+ // Decide whether to use mouse or touch events based on which capabilities the browser has
39
+ if ( gridUtil . isTouchEnabled ( ) ) {
40
+ downEvent = 'touchstart' ;
41
+ upEvent = 'touchend' ;
42
+ clickEvent = 'touchstart' ;
43
+ }
44
+ else {
45
+ downEvent = 'mousedown' ;
46
+ upEvent = 'mouseup' ;
47
+ clickEvent = 'click' ;
48
+ }
34
49
35
50
$scope . gridOpts = {
36
51
enableSorting : true ,
@@ -70,7 +85,7 @@ describe('uiGridHeaderCell', function () {
70
85
} ) ;
71
86
72
87
function openMenu ( ) {
73
- headerCell1 . trigger ( 'mousedown' ) ;
88
+ headerCell1 . trigger ( downEvent ) ;
74
89
$scope . $digest ( ) ;
75
90
$timeout . flush ( ) ;
76
91
$scope . $digest ( ) ;
@@ -87,7 +102,7 @@ describe('uiGridHeaderCell', function () {
87
102
it ( 'should do nothing' , inject ( function ( ) {
88
103
expect ( menu . find ( '.ui-grid-menu-inner' ) . length ) . toEqual ( 0 , 'column menu is not initially visible' ) ;
89
104
90
- headerCell1 . trigger ( { type : 'mousedown' , button : 3 } ) ;
105
+ headerCell1 . trigger ( { type : downEvent , button : 3 } ) ;
91
106
92
107
$timeout . flush ( ) ;
93
108
$scope . $digest ( ) ;
@@ -101,7 +116,7 @@ describe('uiGridHeaderCell', function () {
101
116
openMenu ( ) ;
102
117
expect ( menu . find ( '.ui-grid-menu-inner' ) . length ) . toEqual ( 1 , 'column menu is visible' ) ;
103
118
104
- $document . trigger ( 'click' ) ;
119
+ $document . trigger ( clickEvent ) ;
105
120
106
121
$timeout . flush ( ) ;
107
122
$scope . $digest ( ) ;
0 commit comments