xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / bean / support / syn / test / qunit / mouse_test.js

6.8 KB
1module("funcunit/synthetic/mouse",{
2	setup: function() {
3		st.g("qunit-test-area").innerHTML = "<form id='outer'><div id='inner'>"+
4			"<input type='checkbox' id='checkbox'/>"+
5			"<input type='radio' name='radio' value='radio1' id='radio1'/>"+
6			"<input type='radio' name='radio' value='radio2' id='radio2'/>"+
7			"<a href='javascript:doSomething()' id='jsHref'>click me</a>"+
8			"<input type='submit' id='submit'/></div></form>"
9			
10	}
11})
12
13test("Syn basics", function(){
14
15        ok(Syn,"Syn exists")
16		
17		st.g("qunit-test-area").innerHTML = "<div id='outer'><div id='inner'></div></div>"
18		var mouseover = 0, mouseoverf = function(){
19			mouseover++;
20		};
21		st.bind(st.g("outer"),"mouseover",mouseoverf );
22		Syn("mouseover",st.g("inner"))
23		
24		st.unbinder("outer","mouseover",mouseoverf );
25		equals(mouseover, 1, "Mouseover");
26		Syn("mouseover",{},'inner')
27
28		equals(mouseover, 1, "Mouseover on no event handlers");
29		st.g("qunit-test-area").innerHTML = "";
30		
31})
32
33test("Click Forms", function(){
34	var submit = 0, submitf = function(ev){
35		submit++;
36		if ( ev.preventDefault ) {
37			ev.preventDefault();
38		}
39		ev.returnValue = false;
40		return false;
41	};
42	st.bind(st.g("outer"),"submit",submitf );
43	Syn.trigger("click",{},st.g("submit"));
44	Syn("submit",{},"outer")
45	
46	
47	equals(submit, 2, "Click on submit");
48	
49	//make sure clicking the div does not submit the form
50	var click =0, clickf = function(ev){
51		click++;
52		if ( ev.preventDefault ) {
53			ev.preventDefault();
54		}
55		return false;	
56	}
57	st.binder("inner","click",clickf );
58	
59	Syn.trigger("click",{},st.g("submit"));
60	
61	equals(submit, 2, "Submit prevented");
62	equals(click, 1, "Clicked");
63	
64	st.unbinder("outer","submit",submitf );
65	st.unbinder("inner","click",clickf );
66})
67test("Click Checkboxes", function(){
68	var checkbox =0;
69	
70	st.binder("checkbox","change",function(ev){
71		checkbox++;	
72	});
73
74	st.g("checkbox").checked = false;
75	
76	Syn.trigger("click",{},st.g("checkbox"));
77	
78	ok(st.g("checkbox").checked, "click checks on");
79	
80	Syn.trigger("click",{},st.g("checkbox"));
81	
82	ok(!st.g("checkbox").checked, "click checks off");
83})
84
85test("Checkbox is checked on click", function(){
86	var checkbox =0;
87
88	st.g("checkbox").checked = false;
89	
90	st.binder("checkbox","click",function(ev){
91		ok(st.g("checkbox").checked, "check is on during click");
92	})
93	
94	Syn.trigger("click",{},st.g("checkbox"));
95})
96
97test("Click Radio Buttons", function(){
98
99	var radio1=0,
100		radio2=0;
101		
102	st.g("radio1").checked = false;
103	//make sure changes are called
104	st.bind(st.g("radio1"),"change",function(ev){
105		radio1++;
106	} );
107	st.bind(st.g("radio2"),"change",function(ev){
108		radio2++;
109	} );
110	
111	Syn.trigger("click",{},st.g("radio1") );
112	
113	equals(radio1, 1, "radio event");
114	ok( st.g("radio1").checked, "radio checked" );
115	
116	Syn.trigger("click",{},st.g("radio2") );
117	
118	equals(radio2, 1, "radio event");
119	ok( st.g("radio2").checked, "radio checked" );
120	
121	
122	ok( !st.g("radio1").checked, "radio unchecked" );
123	
124});
125
126test("Click! Event Order", 4, function(){
127	var order = 0;
128	st.g("qunit-test-area").innerHTML = "<input id='focusme'/>";
129	
130	
131	st.binder("focusme","mousedown",function(){
132		equals(++order,1,"mousedown")
133	});
134	
135	st.binder("focusme","focus",function(){
136		equals(++order, 2,"focus")
137	});
138	
139	st.binder("focusme","mouseup",function(){
140		equals(++order,3,"mouseup")
141	});
142	st.binder("focusme","click",function(ev){
143		equals(++order,4,"click")
144		if(ev.preventDefault)
145			ev.preventDefault();
146		ev.returnValue = false;
147	});
148	
149	stop();
150	Syn.click({},"focusme", function(){
151		start();
152	})
153	
154})
155
156test("Click Anchor Runs HREF JavaScript", function(){
157	var didSomething = false,
158		doSomething = window.doSomething;
159	window.doSomething = function(){
160		didSomething = true;
161	}
162
163	
164	Syn.trigger("click",{},st.g("jsHref"))
165	
166	ok( didSomething, "link href JS run" );
167	
168	window.doSomething = doSomething;
169})
170test("Click! Anchor Focuses", 2, function(){
171	st.g("qunit-test-area").innerHTML = "<a href='#abc' id='focusme'>I am visible</a>";
172	
173	st.binder("focusme","focus",function(ev){
174		ok(true,"focused");
175	});
176	
177	st.binder("focusme","click",function(ev){
178		ok(true,"clicked");
179		st.g("qunit-test-area").innerHTML ="";
180		if(ev.preventDefault)
181			ev.preventDefault();
182		ev.returnValue = false;
183		return false;
184	});
185	stop();
186	//need to give browsers a second to show element
187	
188	Syn.click({},"focusme", function(){
189		start();
190	})
191	
192	
193
194})
195test("Click away causes Blur Change", function(){
196	st.g("qunit-test-area").innerHTML = "<input id='one'/><input id='two'/>";
197	
198	var change = 0, blur = 0;
199	
200	st.binder("one","blur",function(){
201		blur++;
202	} );
203	st.binder("one","change",function(){
204		change++;
205	} );
206	
207	stop();
208	Syn.click({},"one")
209		.key("a")
210		.click({},"two", function(){
211			start()
212			equals(change, 1 , "Change called once");
213			equals(blur, 1 , "Blur called once");
214		})
215	
216});
217
218test("Click HTML causes blur  change", function(){
219	st.g("qunit-test-area").innerHTML = "<input id='one'/><input id='two'/>";
220	
221	var change = 0;
222	st.binder("one","change",function(){
223		change++;
224	} );
225	
226	stop();
227	Syn.click({},"one")
228		.key("a")
229		.click({},document.documentElement, function(){
230			start()
231			equals(change, 1 , "Change called once");
232		})
233})
234test("Right Click", function(){
235	st.g("qunit-test-area").innerHTML = "<div id='one'>right click me</div>";
236	stop()
237	var context = 0;
238	st.binder("one","contextmenu",function(){
239		context++;
240	});
241	
242	Syn.rightClick({},"one", function(){
243		if(Syn.mouse.browser.contextmenu){
244			equals(1, context, "context was called")
245		}else{
246			ok(true,"context shouldn't be called in this browser")
247		}
248		start();
249	})
250})
251
252test("Double Click", function(){
253	st.g("qunit-test-area").innerHTML = "<div id='dblclickme'>double click me</div>";
254	stop()
255	var eventSequence = [];
256	st.binder("dblclickme","dblclick",function(){
257		eventSequence.push('dblclick');
258	});
259	st.binder("dblclickme","click",function(){
260		eventSequence.push('click');
261	});
262
263	Syn.dblclick({},"dblclickme", function(){
264		equals(eventSequence.join(', '), 'click, click, dblclick', 'expected event sequence for doubleclick');
265		start();
266	})
267});
268
269// tests against IE9's weirdness where popup windows don't have dispatchEvent
270test("h3 click in popup", 1,function(){
271	st.g("qunit-test-area").innerHTML = "";
272
273	
274	stop();
275	/*var page1 = st.rootJoin("funcunit/syn/test/qunit/h3.html"),
276		iframe = document.createElement('iframe'),
277		calls = 0;
278	
279	st.bind(iframe,"load",function(){
280		var el = iframe.contentWindow.document.getElementById('strange')
281		st.bind(el,"click",function(){
282			ok(true, "h3 was clicked");
283			
284		});
285		Syn.click( el ,{}, function(){
286			start();
287		})
288
289			
290			
291	});
292	iframe.src = page1
293	st.g("qunit-test-area").appendChild(iframe);*/
294	
295	
296	var popup = window.open( st.rootJoin("funcunit/syn/test/qunit/h3.html"), "synthing")
297	
298	setTimeout(function(){
299		var el = popup.document.getElementById('strange')
300		st.bind(el,"click",function(){
301			ok(true, "h3 was clicked");
302			
303		});
304		Syn.click( el ,{}, function(){
305			start();
306			popup.close()
307		})
308
309			
310			
311	},500);
312});