1
1
( function ( ) {
2
+ var IE8Check = window . attachEvent && ! window . addEventListener ,
3
+ key = jQuery . simulate . keyCode ,
4
+ clickOptions ,
5
+ keyEvents ,
6
+ keyOptions ;
2
7
3
8
module ( "mouse events" ) ;
4
9
10
+ clickOptions = [ "ctrlKey" , "altKey" , "shiftKey" , "metaKey" ] ;
11
+
5
12
test ( "click on checkbox triggers change" , function ( ) {
6
13
var input = $ ( "#radiocheckbox-3" ) ,
7
14
checked = input . prop ( "checked" ) ;
@@ -25,28 +32,107 @@ test( "click on radio triggers change", function() {
25
32
notEqual ( checked , firstRadio . prop ( "checked" ) , "radio state changed" ) ;
26
33
} ) ;
27
34
28
- var key = jQuery . simulate . keyCode ,
29
- keyEvents = [ "keydown" , "keyup" , "keypress" ] ,
30
- i = 0 ;
35
+ test ( "click" , function ( ) {
36
+ expect ( 6 ) ;
37
+ jQuery ( "<div></div>" ) . bind ( "click" , function ( event ) {
38
+ var value = IE8Check ? 1 : 0 ;
39
+
40
+ ok ( true , "click event fired" ) ;
41
+ equal ( event . button , value , "click event was fired with left mouse button" ) ;
42
+ equal ( event . ctrlKey , false , "click event was fired without control key" ) ;
43
+ equal ( event . metaKey , false , "click event was fired without meta key" ) ;
44
+ equal ( event . shiftKey , false , "click event was fired without shift key" ) ;
45
+ equal ( event . altKey , false , "click event was fired without alt key" ) ;
46
+ } ) . appendTo ( "#qunit-fixture" ) . simulate ( "click" ) ;
47
+ } ) ;
48
+
49
+ test ( "click with middle mouse button" , function ( ) {
50
+ expect ( 2 ) ;
51
+ jQuery ( "<div></div>" ) . bind ( "click" , function ( event ) {
52
+ var value = IE8Check ? 4 : 1 ;
53
+
54
+ ok ( true , "click event fired" ) ;
55
+ equal ( event . button , value , "click event was fired with middle mouse button" ) ;
56
+ } ) . appendTo ( "#qunit-fixture" ) . simulate ( "click" , {
57
+ button : 1
58
+ } ) ;
59
+ } ) ;
60
+
61
+ test ( "click with right mouse button" , function ( ) {
62
+ expect ( 2 ) ;
63
+ jQuery ( "<div></div>" ) . bind ( "click" , function ( event ) {
64
+ ok ( true , "click event fired" ) ;
65
+ equal ( event . button , 2 , "click event was fired with right mouse button" ) ;
66
+ } ) . appendTo ( "#qunit-fixture" ) . simulate ( "click" , {
67
+ button : 2
68
+ } ) ;
69
+ } ) ;
70
+
71
+ function testClickEvent ( clickOption ) {
72
+ var options = { } ;
73
+ options [ clickOption ] = true ;
74
+
75
+ test ( "click with " + clickOption , function ( ) {
76
+ expect ( 2 ) ;
77
+ jQuery ( "<div></div>" ) . bind ( "click" , function ( event ) {
78
+ ok ( true , "click event fired" ) ;
79
+ equal ( event [ clickOption ] , true , "click event was fired with " + clickOption ) ;
80
+ } ) . appendTo ( "#qunit-fixture" ) . simulate ( "click" , options ) ;
81
+ } ) ;
82
+ }
83
+
84
+ jQuery . each ( clickOptions , function ( index , clickOption ) {
85
+ testClickEvent ( clickOption ) ;
86
+ } ) ;
31
87
32
88
module ( "key events" ) ;
33
89
90
+ keyEvents = [ "keydown" , "keyup" , "keypress" ] ;
91
+ keyOptions = [ "ctrlKey" , "altKey" , "shiftKey" , "metaKey" ] ;
92
+
34
93
function testKeyEvent ( keyEvent ) {
35
94
test ( keyEvent , function ( ) {
36
- expect ( 2 ) ;
95
+ expect ( 2 + keyOptions . length ) ;
37
96
jQuery ( "<div></div>" ) . bind ( keyEvent , function ( event ) {
97
+ var i = 0 ;
98
+
38
99
ok ( true , keyEvent + " event fired" ) ;
39
100
equal ( event . keyCode , key . PAGE_UP , keyEvent + " event has correct keyCode" ) ;
101
+
102
+ for ( i ; i < keyOptions . length ; i ++ ) {
103
+ equal ( event [ keyOptions [ i ] ] , false , keyEvent + " event fired without " + keyOptions [ i ] ) ;
104
+ }
40
105
} ) . appendTo ( "#qunit-fixture" ) . simulate ( keyEvent , {
41
106
keyCode : key . PAGE_UP
42
107
} ) ;
43
108
} ) ;
44
109
}
45
110
46
- for ( ; i < keyEvents . length ; i ++ ) {
47
- testKeyEvent ( keyEvents [ i ] ) ;
111
+ function testKeyEventOption ( keyEvent , keyOption ) {
112
+ test ( keyEvent + " with " + keyOption , function ( ) {
113
+ var options = {
114
+ keyCode : key . PAGE_UP
115
+ } ;
116
+ options [ keyOption ] = true ;
117
+
118
+ expect ( 3 ) ;
119
+ jQuery ( "<div></div>" ) . bind ( keyEvent , function ( event ) {
120
+ ok ( true , keyEvent + " event fired" ) ;
121
+ equal ( event . keyCode , key . PAGE_UP , keyEvent + " event has correct keyCode" ) ;
122
+ equal ( event [ keyOption ] , true , keyEvent + " event fired with " + keyOption ) ;
123
+ } ) . appendTo ( "#qunit-fixture" ) . simulate ( keyEvent , options ) ;
124
+ } ) ;
48
125
}
49
126
127
+ jQuery . each ( keyEvents , function ( index , keyEvent ) {
128
+ testKeyEvent ( keyEvent ) ;
129
+
130
+ jQuery . each ( keyOptions , function ( index , keyOption ) {
131
+ testKeyEventOption ( keyEvent , keyOption ) ;
132
+ } ) ;
133
+ } ) ;
134
+
135
+
50
136
module ( "complex events" ) ;
51
137
52
138
asyncTest ( "drag moves option" , function ( ) {
@@ -98,4 +184,4 @@ asyncTest( "drag moves option", function() {
98
184
} ) ;
99
185
} ) ;
100
186
101
- } ) ( ) ;
187
+ } ) ( ) ;
0 commit comments