]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | // describe("Ext.event.gesture.DoubleTap", function () {});\r |
2 | // The above appeases Cmd's parser to associate spec run results with files.\r | |
3 | \r | |
4 | // Double Tap doesn't currently work in IE8 because 2 clicks in rapid succession will\r | |
5 | // fire a single mousedown, and 2 mouseups.\r | |
6 | // These specs also fail in FF, although double tap seems to work fine when triggered manually\r | |
7 | ((Ext.isIE9m || Ext.isFirefox) ? xdescribe : describe)("Ext.event.gesture.DoubleTap", function() {\r | |
8 | var helper = Ext.testHelper,\r | |
9 | recognizer = Ext.event.gesture.DoubleTap.instance,\r | |
10 | moveDistance = recognizer.getMoveDistance(),\r | |
11 | tapDistance = recognizer.getTapDistance(),\r | |
12 | maxDuration = 130,\r | |
13 | originalMaxDuration, targetEl, singleTapHandler, doubleTapHandler, e;\r | |
14 | \r | |
15 | function start(cfg) {\r | |
16 | helper.touchStart(targetEl, cfg);\r | |
17 | }\r | |
18 | \r | |
19 | function move(cfg) {\r | |
20 | helper.touchMove(targetEl, cfg);\r | |
21 | }\r | |
22 | \r | |
23 | function end(cfg) {\r | |
24 | helper.touchEnd(targetEl, cfg);\r | |
25 | }\r | |
26 | \r | |
27 | function cancel(cfg) {\r | |
28 | helper.touchCancel(targetEl, cfg);\r | |
29 | }\r | |
30 | \r | |
31 | beforeEach(function() {\r | |
32 | originalMaxDuration = recognizer.getMaxDuration();\r | |
33 | recognizer.setMaxDuration(maxDuration);\r | |
34 | targetEl = Ext.getBody().createChild({});\r | |
35 | singleTapHandler = jasmine.createSpy();\r | |
36 | doubleTapHandler = jasmine.createSpy();\r | |
37 | \r | |
38 | singleTapHandler.andCallFake(function(event) {\r | |
39 | e = event;\r | |
40 | });\r | |
41 | \r | |
42 | doubleTapHandler.andCallFake(function(event) {\r | |
43 | e = event;\r | |
44 | });\r | |
45 | \r | |
46 | targetEl.on('doubletap', doubleTapHandler);\r | |
47 | targetEl.on('singletap', singleTapHandler);\r | |
48 | });\r | |
49 | \r | |
50 | afterEach(function() {\r | |
51 | recognizer.setMaxDuration(originalMaxDuration);\r | |
52 | targetEl.destroy();\r | |
53 | });\r | |
54 | \r | |
55 | it("should fire doubletap and not singletap when a second tap occurs within maxDuration", function() {\r | |
56 | runs(function() {\r | |
57 | start({ id: 1, x: 10, y: 10 });\r | |
58 | end({ id: 1, x: 10, y: 10 });\r | |
59 | });\r | |
60 | waits(maxDuration - 30);\r | |
61 | runs(function() {\r | |
62 | start({ id: 1, x: 10, y: 10 });\r | |
63 | end({ id: 1, x: 10, y: 10 });\r | |
64 | });\r | |
65 | waitsForAnimation();\r | |
66 | runs(function() {\r | |
67 | expect(doubleTapHandler).toHaveBeenCalled();\r | |
68 | expect(singleTapHandler).not.toHaveBeenCalled();\r | |
69 | expect(e && e.type).toBe('doubletap');\r | |
70 | });\r | |
71 | });\r | |
72 | \r | |
73 | it("should fire singletap and not doubletap when a second tap does not occur within maxDuration", function() {\r | |
74 | runs(function() {\r | |
75 | start({ id: 1, x: 10, y: 10 });\r | |
76 | end({ id: 1, x: 10, y: 10 });\r | |
77 | });\r | |
78 | waits(maxDuration + 30);\r | |
79 | runs(function() {\r | |
80 | start({ id: 1, x: 10, y: 10 });\r | |
81 | end({ id: 1, x: 10, y: 10 });\r | |
82 | });\r | |
83 | waitsForAnimation();\r | |
84 | runs(function() {\r | |
85 | expect(doubleTapHandler).not.toHaveBeenCalled();\r | |
86 | expect(singleTapHandler).toHaveBeenCalled();\r | |
87 | expect(e && e.type).toBe('singletap');\r | |
88 | });\r | |
89 | });\r | |
90 | \r | |
91 | it("should not fire singletap if movement of the first pointer exceeds moveDistance", function() {\r | |
92 | runs(function() {\r | |
93 | start({ id: 1, x: 10, y: 10 });\r | |
94 | move({ id: 1, x: 10, y: 10 + moveDistance });\r | |
95 | end({ id: 1, x: 10, y: 10 + moveDistance });\r | |
96 | });\r | |
97 | waits(maxDuration + 30);\r | |
98 | runs(function() {\r | |
99 | expect(singleTapHandler).not.toHaveBeenCalled();\r | |
100 | });\r | |
101 | });\r | |
102 | \r | |
103 | it("should not fire doubletap if movement of the first pointer exceeds moveDistance", function() {\r | |
104 | runs(function() {\r | |
105 | start({ id: 1, x: 10, y: 10 });\r | |
106 | move({ id: 1, x: 10, y: 10 + moveDistance });\r | |
107 | end({ id: 1, x: 10, y: 10 + moveDistance });\r | |
108 | });\r | |
109 | waits(maxDuration - 30);\r | |
110 | runs(function() {\r | |
111 | start({ id: 1, x: 10, y: 10 });\r | |
112 | end({ id: 1, x: 10, y: 10 });\r | |
113 | });\r | |
114 | waitsForAnimation();\r | |
115 | runs(function() {\r | |
116 | expect(doubleTapHandler).not.toHaveBeenCalled();\r | |
117 | });\r | |
118 | waits(maxDuration + 30);\r | |
119 | runs(function() {\r | |
120 | // The second tap should actually trigger the single tap event\r | |
121 | expect(singleTapHandler).toHaveBeenCalled();\r | |
122 | })\r | |
123 | });\r | |
124 | \r | |
125 | it("should fire singletap if movement of the first pointer is within moveDistance", function() {\r | |
126 | runs(function() {\r | |
127 | start({ id: 1, x: 10, y: 10 });\r | |
128 | move({ id: 1, x: 10, y: 9 + moveDistance });\r | |
129 | end({ id: 1, x: 10, y: 9 + moveDistance });\r | |
130 | });\r | |
131 | waits(maxDuration + 30);\r | |
132 | runs(function() {\r | |
133 | expect(singleTapHandler).toHaveBeenCalled();\r | |
134 | });\r | |
135 | });\r | |
136 | \r | |
137 | it("should fire doubletap if movement of the first pointer is within moveDistance", function() {\r | |
138 | runs(function() {\r | |
139 | start({ id: 1, x: 10, y: 10 });\r | |
140 | move({ id: 1, x: 9 + moveDistance, y: 10 });\r | |
141 | end({ id: 1, x: 9 + moveDistance, y: 10 });\r | |
142 | });\r | |
143 | waits(maxDuration - 30);\r | |
144 | runs(function() {\r | |
145 | start({ id: 1, x: 10, y: 10 });\r | |
146 | end({ id: 1, x: 11, y: 11 });\r | |
147 | });\r | |
148 | waitsForAnimation();\r | |
149 | runs(function() {\r | |
150 | expect(doubleTapHandler).toHaveBeenCalled();\r | |
151 | });\r | |
152 | });\r | |
153 | \r | |
154 | it("should fire double tap if the second tap is within tapDistance from the first tap", function() {\r | |
155 | runs(function() {\r | |
156 | start({ id: 1, x: 10, y: 10 });\r | |
157 | end({ id: 1, x: 10, y: 10 });\r | |
158 | });\r | |
159 | waits(maxDuration - 30);\r | |
160 | runs(function() {\r | |
161 | start({ id: 1, x: 10 + tapDistance, y: 10 });\r | |
162 | end({ id: 1, x: 10 + tapDistance, y: 10 });\r | |
163 | });\r | |
164 | waitsForAnimation();\r | |
165 | runs(function() {\r | |
166 | expect(doubleTapHandler).toHaveBeenCalled();\r | |
167 | });\r | |
168 | });\r | |
169 | \r | |
170 | it("should not fire double tap if the second tap exceeds tapDistance from the first tap", function() {\r | |
171 | runs(function() {\r | |
172 | start({ id: 1, x: 10, y: 10 });\r | |
173 | end({ id: 1, x: 10, y: 10 });\r | |
174 | });\r | |
175 | waits(maxDuration - 30);\r | |
176 | runs(function() {\r | |
177 | start({ id: 1, x: 11 + tapDistance, y: 10 });\r | |
178 | end({ id: 1, x: 11 + tapDistance, y: 10 });\r | |
179 | });\r | |
180 | waitsForAnimation();\r | |
181 | runs(function() {\r | |
182 | expect(doubleTapHandler).not.toHaveBeenCalled();\r | |
183 | });\r | |
184 | });\r | |
185 | \r | |
186 | if (Ext.supports.Touch) {\r | |
187 | it("should not fire single tap if the first touch is canceled", function() {\r | |
188 | runs(function() {\r | |
189 | start({ id: 1, x: 10, y: 10 });\r | |
190 | cancel({ id: 1, x: 10, y: 10 });\r | |
191 | });\r | |
192 | waits(maxDuration + 30);\r | |
193 | runs(function() {\r | |
194 | start({ id: 1, x: 10, y: 10 });\r | |
195 | end({ id: 1, x: 10, y: 10 });\r | |
196 | });\r | |
197 | waitsForAnimation();\r | |
198 | runs(function() {\r | |
199 | expect(singleTapHandler).not.toHaveBeenCalled();\r | |
200 | });\r | |
201 | });\r | |
202 | \r | |
203 | it("should not fire double tap if the first touch is canceled", function() {\r | |
204 | runs(function() {\r | |
205 | start({ id: 1, x: 10, y: 10 });\r | |
206 | cancel({ id: 1, x: 10, y: 10 });\r | |
207 | });\r | |
208 | waits(maxDuration - 30);\r | |
209 | runs(function() {\r | |
210 | start({ id: 1, x: 10, y: 10 });\r | |
211 | end({ id: 1, x: 10, y: 10 });\r | |
212 | });\r | |
213 | waitsForAnimation();\r | |
214 | runs(function() {\r | |
215 | expect(doubleTapHandler).not.toHaveBeenCalled();\r | |
216 | });\r | |
217 | });\r | |
218 | \r | |
219 | it("should not fire double tap if the second touch is canceled", function() {\r | |
220 | runs(function() {\r | |
221 | start({ id: 1, x: 10, y: 10 });\r | |
222 | end({ id: 1, x: 10, y: 10 });\r | |
223 | });\r | |
224 | waits(maxDuration - 30);\r | |
225 | runs(function() {\r | |
226 | start({ id: 1, x: 10, y: 10 });\r | |
227 | cancel({ id: 1, x: 10, y: 10 });\r | |
228 | });\r | |
229 | waitsForAnimation();\r | |
230 | runs(function() {\r | |
231 | expect(doubleTapHandler).not.toHaveBeenCalled();\r | |
232 | });\r | |
233 | });\r | |
234 | }\r | |
235 | });\r |