]> git.proxmox.com Git - extjs.git/blame - extjs/packages/core/test/specs/GlobalEvents.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / core / test / specs / GlobalEvents.js
CommitLineData
6527f429
DM
1describe("Ext.GlobalEvents", function() {\r
2 describe('idle event', function() {\r
3 var delay = Ext.isIE ? 50 : 10,\r
4 idleFired, done;\r
5\r
6 function onIdle() {\r
7 idleFired = true;\r
8 }\r
9\r
10 beforeEach(function() {\r
11 idleFired = false;\r
12 done = false;\r
13 Ext.on('idle', onIdle);\r
14 });\r
15\r
16 afterEach(function() {\r
17 Ext.un('idle', onIdle);\r
18 });\r
19\r
20 it("should fire after DOM event handler are invoked, but before control is returned to the browser", function() {\r
21 var element = Ext.getBody().createChild(),\r
22 handledCount = 0;\r
23\r
24 function expectFalse() {\r
25 expect(idleFired).toBe(false);\r
26 handledCount ++;\r
27 }\r
28\r
29 // attach a couple mousedown listeners, the idle event should fire after both\r
30 // handlers have fired\r
31 element.on('mousedown', expectFalse);\r
32 element.on('mousedown', function() {\r
33 expectFalse();\r
34 });\r
35\r
36 jasmine.fireMouseEvent(element, 'mousedown');\r
37\r
38 expect(handledCount).toBe(2);\r
39 expect(idleFired).toBe(true);\r
40\r
41 element.destroy();\r
42 });\r
43\r
44 it("should fire after a JsonPProxy processes a return packet", function() {\r
45 var store = Ext.create('Ext.data.Store', {\r
46 proxy: {\r
47 type: 'jsonp',\r
48 reader: {\r
49 rootProperty: 'topics',\r
50 totalProperty: 'totalCount'\r
51 },\r
52 url: 'http://www.sencha.com/forum/remote_topics/index.php'\r
53 },\r
54 fields: ['title'],\r
55 listeners: {\r
56 load: function() {\r
57 done = true;\r
58 }\r
59 }\r
60 });\r
61 store.loadPage(1);\r
62 waitsFor(function() {\r
63 return done === true;\r
64 });\r
65 runs(function() {\r
66 waits(delay);\r
67 runs(function() {\r
68 expect(idleFired).toBe(true);\r
69 store.destroy();\r
70 });\r
71 });\r
72 });\r
73\r
74 it("should fire after a JsonP request is processed", function() {\r
75 Ext.data.JsonP.request({\r
76 url: 'http://www.sencha.com/forum/remote_topics/index.php?page=1&start=0&limit=100',\r
77 callback: function() {\r
78 done = true;\r
79 }\r
80 });\r
81 waitsFor(function() {\r
82 return done === true;\r
83 });\r
84 runs(function() {\r
85 waits(delay);\r
86 runs(function() {\r
87 expect(idleFired).toBe(true);\r
88 });\r
89 });\r
90 });\r
91 \r
92 it("should fire after an Ajax request is processed", function() {\r
93 Ext.Ajax.request({\r
94 url: 'resources/foo.json',\r
95 callback: function() {\r
96 done = true;\r
97 }\r
98 });\r
99 waitsFor(function() {\r
100 return done === true;\r
101 });\r
102 runs(function() {\r
103 waits(delay);\r
104 runs(function() {\r
105 expect(idleFired).toBe(true);\r
106 });\r
107 });\r
108 });\r
109\r
110 it("should fire after a scheduled Task is run", function() {\r
111 Ext.TaskManager.newTask({\r
112 run: function(){\r
113 done = true;\r
114 }, \r
115 repeat: 1, \r
116 interval: 1\r
117 }).start();\r
118 waitsFor(function() {\r
119 return done === true;\r
120 });\r
121 runs(function() {\r
122 waits(delay);\r
123 runs(function() {\r
124 expect(idleFired).toBe(true);\r
125 });\r
126 });\r
127 });\r
128 });\r
129 \r
130 describe('scroll event', function() {\r
131 var stretcher,\r
132 scrollingPanel,\r
133 scrolledElements = [],\r
134 runIt = Ext.supports.touchScroll ? xit : it;\r
135\r
136 afterEach(function() {\r
137 stretcher.destroy();\r
138 scrollingPanel.destroy();\r
139 });\r
140\r
141 function onGlobalScroll(scroller) {\r
142 scrolledElements.push(scroller.getElement());\r
143 }\r
144\r
145 runIt('should fire the global scroll event whenever anything scrolls', function() {\r
146 stretcher = Ext.getBody().createChild({\r
147 style: 'height:10000px'\r
148 });\r
149 \r
150 // Use Ext.Panel class - it will work in Classic and Modern\r
151 scrollingPanel = new Ext.Panel({\r
152 renderTo: document.body,\r
153 floating: true,\r
154 x: 0,\r
155 y: 0,\r
156 width: 300,\r
157 height: 300,\r
158 \r
159 // Modern defaults to 'card', so explicitly use 'auto'\r
160 layout: 'auto',\r
161 scrollable: true,\r
162 items: {\r
163 xtype: 'component',\r
164 style: 'height:1000px'\r
165 }\r
166 });\r
167\r
168 // Record all scroll events\r
169 Ext.on({\r
170 scroll: onGlobalScroll\r
171 });\r
172 Ext.scroll.DomScroller.document.scrollBy(null, 100);\r
173\r
174 // Wait for scroll events to fire (may be async)\r
175 waitsFor(function() {\r
176 return scrolledElements.length === 1 &&\r
177 scrolledElements[0] === Ext.scroll.DomScroller.document.getElement();\r
178 });\r
179 \r
180 runs(function() {\r
181 scrollingPanel.getScrollable().scrollBy(null, 100);\r
182 });\r
183 \r
184 // Wait for scroll events to fire (may be async)\r
185 waitsFor(function() {\r
186 return scrolledElements.length === 2 &&\r
187 scrolledElements[1] === scrollingPanel.getScrollable().getElement();\r
188 });\r
189 });\r
190 });\r
191});\r