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

@ -40,12 +40,12 @@
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<div id="main"></div>
<div id="main"></div>
<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="position: absolute; width: 1px; height: 2000px;"></div>
<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="position: absolute; width: 1px; height: 2000px;"></div>
</div>

View File

@ -2,24 +2,40 @@
* draggable_core.js
*/
(function($) {
(function( $ ) {
module("draggable");
var relativeElement, absoluteElement;
test("element types", function() {
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(",");
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" +
",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr" +
",acronym,code,samp,kbd,var,img,hr" +
",input,button,label,select,iframe"
).split(",");
expect( typeNames.length * 2 );
$.each(typeNames, function(i) {
$.each( typeNames, function( i ) {
var offsetBefore, offsetAfter,
typeName = typeNames[i],
el = $(document.createElement(typeName)).appendTo("#qunit-fixture");
typeName = typeNames[ i ],
el = $( document.createElement( typeName ) ).appendTo("#qunit-fixture");
if ( typeName === "table" ) {
el.append("<tr><td>content</td></tr>");
}
(typeName === "table" && el.append("<tr><td>content</td></tr>"));
el.draggable({ cancel: "" });
offsetBefore = el.offset();
el.simulate( "drag", {
@ -27,39 +43,38 @@ 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
closeEnough(offsetBefore.left, offsetAfter.left - 50, 1, "dragged[50, 50] " + "<" + typeName + ">");
closeEnough(offsetBefore.top, offsetAfter.top - 50, 1, "dragged[50, 50] " + "<" + typeName + ">");
// 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");
el.remove();
});
});
test("No options, relative", 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() {
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() {
test( "resizable handle with complex markup (#8756 / #8757)", function() {
expect( 2 );
$("#draggable1")
relativeElement
.append(
$("<div>")
.addClass("ui-resizable-handle")
.addClass("ui-resizable-w")
.append($("<div>"))
.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 } );
@ -70,4 +85,4 @@ test("resizable handle with complex markup (#8756 / #8757)", function() {
equal( target.width(), 200, "compare width" );
});
})(jQuery);
})( jQuery );

View File

@ -1,94 +1,99 @@
/*
* draggable_methods.js
*/
(function($) {
(function( $ ) {
module("draggable: methods");
var element;
test("init", function() {
expect(5);
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();
}
});
$("<div></div>").appendTo("body").draggable().remove();
ok(true, ".draggable() called on element");
test( "init", function() {
expect( 5 );
element.draggable();
ok( true, ".draggable() called on element" );
$([]).draggable();
ok(true, ".draggable() called on empty collection");
ok( true, ".draggable() called on empty collection" );
$("<div></div>").draggable();
ok(true, ".draggable() called on disconnected DOMElement");
ok( true, ".draggable() called on disconnected DOMElement" );
$("<div></div>").draggable().draggable("option", "foo");
ok(true, "arbitrary option getter after init");
element.draggable( "option", "foo" );
ok( true, "arbitrary option getter after init" );
$("<div></div>").draggable().draggable("option", "foo", "bar");
ok(true, "arbitrary option setter after init");
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();
ok(true, ".draggable('destroy') called on element");
test( "destroy", function() {
expect( 4 );
element.draggable().draggable("destroy");
ok( true, ".draggable('destroy') called on element" );
$([]).draggable().draggable("destroy");
ok(true, ".draggable('destroy') called on empty collection");
ok( true, ".draggable('destroy') called on empty collection" );
$("<div></div>").draggable().draggable("destroy");
ok(true, ".draggable('destroy') called on disconnected DOMElement");
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");
equal( actual, expected, "destroy is chainable" );
});
test("enable", function() {
expect(7);
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(),
actual = expected.draggable("enable");
equal(actual, expected, "enable is chainable");
var expected = element.draggable(),
actual = expected.draggable("enable");
equal( actual, expected, "enable is chainable" );
});
test("disable", function() {
expect(7);
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(),
actual = expected.draggable("disable");
equal(actual, expected, "disable is chainable");
var expected = element.draggable(),
actual = expected.draggable("disable");
equal( actual, expected, "disable is chainable" );
});
})(jQuery);
})( jQuery );