Skip to content
This repository
Browse code

Merge pull request #2919 from redaemn/flip-switch-improvements

Corrected some tests for the slider widget
  • Loading branch information...
commit f501712617e8e6eeca9a22f68c3d1b755d7131a1 2 parents ac8a7c7 + 0e14c98
John Bender authored November 10, 2011

Showing 1 changed file with 14 additions and 16 deletions. Show diff stats Hide diff stats

  1. 30  tests/unit/slider/slider_events.js
30  tests/unit/slider/slider_events.js
@@ -203,16 +203,16 @@
203 203
 		var integerLeft, compare, css, threshold;
204 204
 
205 205
 		css = obj.css('left');
206  
-		threshold = opts.pxThreshold || 10;
  206
+		threshold = opts.pxThreshold || 0;
207 207
 
208 208
 		if( css.indexOf( "px" ) > -1 ) {
209 209
 			// parse the actual pixel value returned by the left css value
210 210
 			// and the pixels passed in for comparison
211  
-			integerLeft = parseInt(css.replace("px", ""), 10 ),
  211
+			integerLeft = Math.round( parseFloat( css.replace("px", "") ) ),
212 212
 			compare = parseInt( opts.pixels.replace( "px", "" ), 10 );
213 213
 
214  
-			// check that the pixel value provided is within a given threshold default is 10px
215  
-			ok( compare > integerLeft - threshold && compare < integerLeft + threshold, opts.message );
  214
+			// check that the pixel value provided is within a given threshold; default is 0px
  215
+			ok( compare >= integerLeft - threshold && compare <= integerLeft + threshold, opts.message );
216 216
 		} else {
217 217
 			equal( css, opts.percent, opts.message );
218 218
 		}
@@ -235,7 +235,7 @@
235 235
 			function() {
236 236
 				assertLeftCSS(handle, {
237 237
 					percent: '100%',
238  
-					pixels: handle.css('width'),
  238
+					pixels: handle.parent().css('width'),
239 239
 					message: 'handle starts on the right side'
240 240
 				});
241 241
 
@@ -249,10 +249,9 @@
249 249
 			function() {
250 250
 				assertLeftCSS(handle, {
251 251
 					percent: '100%',
252  
-					pixels: handle.css('width'),
  252
+					pixels: handle.parent().css('width'),
253 253
 					message: 'handle ends on the right side'
254 254
 				});
255  
-				// equals(handle.css('left'), '100%', 'handle ends on the right side');
256 255
 
257 256
 				// initialize the switch
258 257
 				control.val('on').slider('refresh');
@@ -261,7 +260,7 @@
261 260
 			function() {
262 261
 				assertLeftCSS(handle, {
263 262
 					percent: '100%',
264  
-					pixels: handle.css('width'),
  263
+					pixels: handle.parent().css('width'),
265 264
 					message: 'handle starts on the right side'
266 265
 				});
267 266
 
@@ -269,7 +268,6 @@
269 268
 				offset = handle.offset();
270 269
 				slider.trigger( createEvent( "mousedown", handle[ 0 ], offset.left + 10, offset.top + 10 ) );
271 270
 				slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
272  
-				//slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - width + 20, offset.top + 10 ) );
273 271
 				slider.trigger( createEvent( "mouseup", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
274 272
 			},
275 273
 
@@ -277,7 +275,7 @@
277 275
 				assertLeftCSS(handle, {
278 276
 					percent: '0%',
279 277
 					pixels: '0px',
280  
-					message: 'handle starts on the right side'
  278
+					message: 'handle ends on the left side'
281 279
 				});
282 280
 
283 281
 				start();
@@ -302,14 +300,14 @@
302 300
 			function() {
303 301
 				assertLeftCSS(handle, {
304 302
 					percent: '100%',
305  
-					pixels: handle.css('width'),
  303
+					pixels: handle.parent().css('width'),
306 304
 					message: 'handle starts on the right side'
307 305
 				});
308 306
 
309 307
 				// simulate dragging more than a half
310 308
 				offset = handle.offset();
311 309
 				slider.trigger( createEvent( "mousedown", handle[ 0 ], offset.left + 10, offset.top + 10 ) );
312  
-				slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - width + 70, offset.top + 10 ) );
  310
+				slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
313 311
 			},
314 312
 
315 313
 			function() {
@@ -319,14 +317,14 @@
319 317
 					max = "100%";
320 318
 				} else {
321 319
 					min = "0px";
322  
-					max = handle.css( 'width' );
  320
+					max = handle.parent().css( 'width' );
323 321
 				}
324 322
 
325 323
 				notEqual(handle.css('left'), min, 'handle is not on the left side');
326 324
 				notEqual(handle.css('left'), max, 'handle is not on the right side');
327 325
 
328 326
 				// reset slider state so it is ready for other tests
329  
-				slider.trigger( createEvent( "mouseup", handle[ 0 ], offset.left - width + 20, offset.top + 10 ) );
  327
+				slider.trigger( createEvent( "mouseup", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
330 328
 
331 329
 				start();
332 330
 			}
@@ -358,8 +356,8 @@
358 356
 			function() {
359 357
 				assertLeftCSS(handle, {
360 358
 					percent: '100%',
361  
-					pixels: handle.css( 'width' ),
362  
-					message: 'handle ends on the left side'
  359
+					pixels: handle.parent().css( 'width' ),
  360
+					message: 'handle ends on the right side'
363 361
 				});
364 362
 
365 363
 				// reset slider state so it is ready for other tests

0 notes on commit f501712

Please sign in to comment.
Something went wrong with that request. Please try again.