]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/event/gesture/Tap.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / event / gesture / Tap.js
CommitLineData
6527f429
DM
1describe("Ext.event.gesture.Tap", function() {\r
2 var helper = Ext.testHelper,\r
3 tapRecognizer = Ext.event.gesture.Tap.instance,\r
4 moveDistance = tapRecognizer.getMoveDistance(),\r
5 targetEl, tapHandler, tapCancelHandler, e, recognizer;\r
6\r
7 function start(cfg) {\r
8 helper.touchStart(targetEl, cfg);\r
9 }\r
10\r
11 function move(cfg) {\r
12 helper.touchMove(targetEl, cfg);\r
13 }\r
14\r
15 function end(cfg) {\r
16 helper.touchEnd(targetEl, cfg);\r
17 }\r
18\r
19 function cancel(cfg) {\r
20 helper.touchCancel(targetEl, cfg);\r
21 }\r
22\r
23 beforeEach(function() {\r
24 targetEl = Ext.getBody().createChild();\r
25 tapHandler = jasmine.createSpy();\r
26 tapCancelHandler = jasmine.createSpy();\r
27\r
28 tapHandler.andCallFake(function(event) {\r
29 e = event;\r
30 });\r
31\r
32 tapCancelHandler.andCallFake(function(event) {\r
33 e = event;\r
34 });\r
35\r
36 targetEl.on('tap', tapHandler);\r
37 targetEl.on('tapcancel', tapCancelHandler);\r
38 });\r
39\r
40 afterEach(function() {\r
41 targetEl.destroy();\r
42 });\r
43\r
44 it("should fire tap when there is no movement", function() {\r
45 waits(100);\r
46 runs(function() {\r
47 start({ id: 1, x: 10, y: 10 });\r
48 end({ id: 1, x: 10, y: 10 });\r
49 });\r
50 waitsForAnimation();\r
51 runs(function() {\r
52 expect(tapHandler).toHaveBeenCalled();\r
53 expect(e.type).toBe('tap');\r
54 expect(e.getX()).toBe(10);\r
55 expect(e.getY()).toBe(10);\r
56 });\r
57 });\r
58\r
59 it("should fire tap if movement is within moveDistance", function() {\r
60 waits(100);\r
61 runs(function() {\r
62 start({ id: 1, x: 10, y: 10 });\r
63 move({ id: 1, x: 9 + moveDistance, y: 10 });\r
64 end({ id: 1, x: 9 + moveDistance, y: 10 });\r
65 });\r
66 waitsForAnimation();\r
67 runs(function() {\r
68 expect(tapHandler).toHaveBeenCalled();\r
69 expect(e.type).toBe('tap');\r
70 expect(e.getX()).toBe(9 + moveDistance);\r
71 expect(e.getY()).toBe(10);\r
72 });\r
73 });\r
74\r
75 it("should not fire tap, and should fire tapcancel if movement is greater than or equal to moveDistance", function() {\r
76 waits(100);\r
77 runs(function() {\r
78 start({ id: 1, x: 10, y: 10 });\r
79 move({ id: 1, x: 10, y: 10 + moveDistance });\r
80 end({ id: 1, x: 10, y: 10 + moveDistance });\r
81 });\r
82 waitsForAnimation();\r
83 runs(function() {\r
84 expect(tapHandler).not.toHaveBeenCalled();\r
85 expect(tapCancelHandler).toHaveBeenCalled();\r
86 expect(e.type).toBe('tapcancel');\r
87 });\r
88 });\r
89\r
90 if (Ext.supports.Touch) {\r
91 it("should not fire tap if a second touch is initiated", function() {\r
92 runs(function() {\r
93 start({ id: 1, x: 10, y: 10 });\r
94 start({ id: 2, x: 30, y: 30 });\r
95 end({ id: 1, x: 10, y: 10 });\r
96 });\r
97 waitsForAnimation();\r
98 runs(function() {\r
99 end({ id: 2, x: 30, y: 30 });\r
100 });\r
101 waitsForAnimation();\r
102 runs(function() {\r
103 expect(tapHandler).not.toHaveBeenCalled();\r
104 });\r
105 });\r
106\r
107 it("should not fire tap and should fire tapcancel if a cancel event is received", function() {\r
108 runs(function() {\r
109 start({ id: 1, x: 10, y: 10 });\r
110 });\r
111 waitsForAnimation();\r
112 runs(function() {\r
113 cancel({ id: 1, x: 10, y: 10 });\r
114 });\r
115 waitsForAnimation();\r
116 runs(function() {\r
117 expect(tapHandler).not.toHaveBeenCalled();\r
118 expect(tapCancelHandler).toHaveBeenCalled();\r
119 expect(e.type).toBe('tapcancel');\r
120 });\r
121 });\r
122 }\r
123\r
124 it("should not fire tap and should fire tapcancel if movement exceeds moveDistance, but the pointer is moved back within the moveDistance before touchend", function() {\r
125 runs(function() {\r
126 start({ id: 1, x: 10, y: 10 });\r
127 move({ id: 1, x: 10, y: 11 + moveDistance });\r
128 });\r
129 waitsForAnimation();\r
130 runs(function() {\r
131 move({ id: 1, x: 10, y: 10 });\r
132 end({ id: 1, x: 10, y: 10 });\r
133 });\r
134 waitsForAnimation();\r
135 runs(function() {\r
136 expect(tapHandler).not.toHaveBeenCalled();\r
137 expect(tapCancelHandler).toHaveBeenCalled();\r
138 expect(e.type).toBe('tapcancel');\r
139 });\r
140 });\r
141});\r