Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@johnbender johnbender authored
Showing with 14 additions and 16 deletions.
  1. +14 −16 tests/unit/slider/slider_events.js
View
30 tests/unit/slider/slider_events.js
@@ -203,16 +203,16 @@
var integerLeft, compare, css, threshold;
css = obj.css('left');
- threshold = opts.pxThreshold || 10;
+ threshold = opts.pxThreshold || 0;
if( css.indexOf( "px" ) > -1 ) {
// parse the actual pixel value returned by the left css value
// and the pixels passed in for comparison
- integerLeft = parseInt(css.replace("px", ""), 10 ),
+ integerLeft = Math.round( parseFloat( css.replace("px", "") ) ),
compare = parseInt( opts.pixels.replace( "px", "" ), 10 );
- // check that the pixel value provided is within a given threshold default is 10px
- ok( compare > integerLeft - threshold && compare < integerLeft + threshold, opts.message );
+ // check that the pixel value provided is within a given threshold; default is 0px
+ ok( compare >= integerLeft - threshold && compare <= integerLeft + threshold, opts.message );
} else {
equal( css, opts.percent, opts.message );
}
@@ -235,7 +235,7 @@
function() {
assertLeftCSS(handle, {
percent: '100%',
- pixels: handle.css('width'),
+ pixels: handle.parent().css('width'),
message: 'handle starts on the right side'
});
@@ -249,10 +249,9 @@
function() {
assertLeftCSS(handle, {
percent: '100%',
- pixels: handle.css('width'),
+ pixels: handle.parent().css('width'),
message: 'handle ends on the right side'
});
- // equals(handle.css('left'), '100%', 'handle ends on the right side');
// initialize the switch
control.val('on').slider('refresh');
@@ -261,7 +260,7 @@
function() {
assertLeftCSS(handle, {
percent: '100%',
- pixels: handle.css('width'),
+ pixels: handle.parent().css('width'),
message: 'handle starts on the right side'
});
@@ -269,7 +268,6 @@
offset = handle.offset();
slider.trigger( createEvent( "mousedown", handle[ 0 ], offset.left + 10, offset.top + 10 ) );
slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
- //slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - width + 20, offset.top + 10 ) );
slider.trigger( createEvent( "mouseup", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
},
@@ -277,7 +275,7 @@
assertLeftCSS(handle, {
percent: '0%',
pixels: '0px',
- message: 'handle starts on the right side'
+ message: 'handle ends on the left side'
});
start();
@@ -302,14 +300,14 @@
function() {
assertLeftCSS(handle, {
percent: '100%',
- pixels: handle.css('width'),
+ pixels: handle.parent().css('width'),
message: 'handle starts on the right side'
});
// simulate dragging more than a half
offset = handle.offset();
slider.trigger( createEvent( "mousedown", handle[ 0 ], offset.left + 10, offset.top + 10 ) );
- slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - width + 70, offset.top + 10 ) );
+ slider.trigger( createEvent( "mousemove", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
},
function() {
@@ -319,14 +317,14 @@
max = "100%";
} else {
min = "0px";
- max = handle.css( 'width' );
+ max = handle.parent().css( 'width' );
}
notEqual(handle.css('left'), min, 'handle is not on the left side');
notEqual(handle.css('left'), max, 'handle is not on the right side');
// reset slider state so it is ready for other tests
- slider.trigger( createEvent( "mouseup", handle[ 0 ], offset.left - width + 20, offset.top + 10 ) );
+ slider.trigger( createEvent( "mouseup", handle[ 0 ], offset.left - ( width / 2 ), offset.top + 10 ) );
start();
}
@@ -358,8 +356,8 @@
function() {
assertLeftCSS(handle, {
percent: '100%',
- pixels: handle.css( 'width' ),
- message: 'handle ends on the left side'
+ pixels: handle.parent().css( 'width' ),
+ message: 'handle ends on the right side'
});
// reset slider state so it is ready for other tests

0 comments on commit f501712

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