Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2919 from redaemn/flip-switch-improvements
Browse files Browse the repository at this point in the history
Corrected some tests for the slider widget
  • Loading branch information
johnbender committed Nov 10, 2011
2 parents ac8a7c7 + 0e14c98 commit f501712
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions tests/unit/slider/slider_events.js
Expand Up @@ -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 );
}
Expand All @@ -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'
});

Expand All @@ -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');
Expand All @@ -261,23 +260,22 @@
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 / 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 ) );
},

function() {
assertLeftCSS(handle, {
percent: '0%',
pixels: '0px',
message: 'handle starts on the right side'
message: 'handle ends on the left side'
});

start();
Expand All @@ -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() {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f501712

Please sign in to comment.