Draggable Tests: Cleaned up core and method tests.

This commit is contained in:
Mike Sherov 2013-01-13 18:55:43 -05:00
parent 430bd68344
commit c70b3dc9e3
3 changed files with 111 additions and 91 deletions

View File

@ -44,7 +44,7 @@
<div id="draggable1" style="background: green; width: 200px; height: 100px;">Relative</div>
<div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span>Absolute</span></div>
<div style='width: 1px; height: 1000px;'></div>
<div style="width: 1px; height: 1000px;"></div>
<div style="position: absolute; width: 1px; height: 2000px;"></div>
</div>

View File

@ -4,13 +4,26 @@
(function( $ ) {
module("draggable");
var relativeElement, absoluteElement;
module( "draggable: core", {
setup: function() {
relativeElement = $("<div style='width: 200px; height: 100px;'>Relative</div>").appendTo("#qunit-fixture");
absoluteElement = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
},
teardown: function() {
relativeElement.remove();
absoluteElement.remove();
}
});
test( "element types", function() {
var typeNames = ("p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
var typeNames = (
"p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form" +
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
",acronym,code,samp,kbd,var,img,hr" +
",input,button,label,select,iframe").split(",");
",input,button,label,select,iframe"
).split(",");
expect( typeNames.length * 2 );
@ -19,7 +32,10 @@ test("element types", function() {
typeName = typeNames[ i ],
el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
(typeName === "table" && el.append("<tr><td>content</td></tr>"));
if ( typeName === "table" ) {
el.append("<tr><td>content</td></tr>");
}
el.draggable({ cancel: "" });
offsetBefore = el.offset();
el.simulate( "drag", {
@ -27,7 +43,9 @@ test("element types", function() {
dy: 50
});
offsetAfter = el.offset();
// there are some rounding errors in FF, Chrome, and IE9, so we can't say equal, we have to settle for close enough
// Support: FF, Chrome, and IE9,
// there are some rounding errors in so we can't say equal, we have to settle for close enough
closeEnough( offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
closeEnough( offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">" );
el.draggable("destroy");
@ -37,29 +55,26 @@ test("element types", function() {
test( "No options, relative", function() {
expect( 1 );
var el = $("#draggable1").draggable();
TestHelpers.draggable.shouldMove(el);
TestHelpers.draggable.shouldMove( relativeElement.draggable() );
});
test( "No options, absolute", function() {
expect( 1 );
var el = $("#draggable2").draggable();
TestHelpers.draggable.shouldMove(el);
TestHelpers.draggable.shouldMove( absoluteElement.draggable() );
});
test( "resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 );
$("#draggable1")
relativeElement
.append(
$("<div>")
.addClass("ui-resizable-handle")
.addClass("ui-resizable-w")
.addClass("ui-resizable-handle ui-resizable-w")
.append( $("<div>") )
);
var handle = $(".ui-resizable-w div"),
target = $("#draggable1").draggable().resizable({ handles: "all" });
target = relativeElement.draggable().resizable({ handles: "all" });
// todo: fix resizable so it doesn't require a mouseover
handle.simulate("mouseover").simulate( "drag", { dx: -50 } );

View File

@ -3,12 +3,21 @@
*/
(function( $ ) {
module("draggable: methods");
var element;
module( "draggable: methods", {
setup: function() {
element = $("<div style='background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;'><span>Absolute</span></div>").appendTo("#qunit-fixture");
},
teardown: function() {
element.remove();
}
});
test( "init", function() {
expect( 5 );
$("<div></div>").appendTo("body").draggable().remove();
element.draggable();
ok( true, ".draggable() called on element" );
$([]).draggable();
@ -17,25 +26,26 @@ test("init", function() {
$("<div></div>").draggable();
ok( true, ".draggable() called on disconnected DOMElement" );
$("<div></div>").draggable().draggable("option", "foo");
element.draggable( "option", "foo" );
ok( true, "arbitrary option getter after init" );
$("<div></div>").draggable().draggable("option", "foo", "bar");
element.draggable( "option", "foo", "bar" );
ok( true, "arbitrary option setter after init" );
});
test( "destroy", function() {
expect( 4 );
$("<div></div>").appendTo("body").draggable().draggable("destroy").remove();
element.draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on element" );
$([]).draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on empty collection" );
$("<div></div>").draggable().draggable("destroy");
element.draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on disconnected DOMElement" );
var expected = $("<div></div>").draggable(),
var expected = element.draggable(),
actual = expected.draggable("destroy");
equal( actual, expected, "destroy is chainable" );
});
@ -43,24 +53,22 @@ test("destroy", function() {
test( "enable", function() {
expect( 7 );
var expected, actual, el;
element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotMove( element, ".draggable({ disabled: true })" );
el = $("#draggable2").draggable({ disabled: true });
TestHelpers.draggable.shouldNotMove(el, ".draggable({ disabled: true })");
element.draggable("enable");
TestHelpers.draggable.shouldMove( element, ".draggable('enable')" );
equal( element.draggable( "option", "disabled" ), false, "disabled option getter" );
el.draggable("enable");
TestHelpers.draggable.shouldMove(el, ".draggable('enable')");
equal(el.draggable("option", "disabled"), false, "disabled option getter");
element.draggable("destroy");
element.draggable({ disabled: true });
TestHelpers.draggable.shouldNotMove( element, ".draggable({ disabled: true })" );
el.draggable("destroy");
el.draggable({ disabled: true });
TestHelpers.draggable.shouldNotMove(el, ".draggable({ disabled: true })");
element.draggable( "option", "disabled", false );
equal(element.draggable( "option", "disabled" ), false, "disabled option setter" );
TestHelpers.draggable.shouldMove( element, ".draggable('option', 'disabled', false)" );
el.draggable("option", "disabled", false);
equal(el.draggable("option", "disabled"), false, "disabled option setter");
TestHelpers.draggable.shouldMove(el, ".draggable('option', 'disabled', false)");
expected = $("<div></div>").draggable(),
var expected = element.draggable(),
actual = expected.draggable("enable");
equal( actual, expected, "enable is chainable" );
});
@ -68,25 +76,22 @@ test("enable", function() {
test( "disable", function() {
expect( 7 );
var expected, actual, el;
element = $("#draggable2").draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
el = $("#draggable2").draggable({ disabled: false });
TestHelpers.draggable.shouldMove(el, ".draggable({ disabled: false })");
element.draggable("disable");
TestHelpers.draggable.shouldNotMove( element, ".draggable('disable')" );
equal( element.draggable( "option", "disabled" ), true, "disabled option getter" );
el.draggable("disable");
TestHelpers.draggable.shouldNotMove(el, ".draggable('disable')");
equal(el.draggable("option", "disabled"), true, "disabled option getter");
element.draggable("destroy");
element.draggable({ disabled: false });
TestHelpers.draggable.shouldMove( element, ".draggable({ disabled: false })" );
el.draggable("destroy");
element.draggable( "option", "disabled", true );
equal( element.draggable( "option", "disabled" ), true, "disabled option setter" );
TestHelpers.draggable.shouldNotMove( element, ".draggable('option', 'disabled', true)" );
el.draggable({ disabled: false });
TestHelpers.draggable.shouldMove(el, ".draggable({ disabled: false })");
el.draggable("option", "disabled", true);
equal(el.draggable("option", "disabled"), true, "disabled option setter");
TestHelpers.draggable.shouldNotMove(el, ".draggable('option', 'disabled', true)");
expected = $("<div></div>").draggable(),
var expected = element.draggable(),
actual = expected.draggable("disable");
equal( actual, expected, "disable is chainable" );
});