Droppable Unit: Initial tests - they worked in interaction but not here

This commit is contained in:
Dave Stein 2013-02-24 17:43:44 -05:00
parent b21904007f
commit a8c5cf34ba
4 changed files with 115 additions and 28 deletions

View File

@ -39,9 +39,8 @@
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<div id="draggable1" style="width: 25px; height: 25px;">Draggable</div>
<div id="droppable1" style="width: 100px; height: 100px;">Droppable</div>
<div id="draggable1" style="width: 25px; height: 25px; position: absolute; top: 150px;">Draggable</div>
<div style='width:1000px;height:1000px;'>&nbsp;</div>
</div>

View File

@ -2,7 +2,6 @@ TestHelpers.commonWidgetTests( "droppable", {
defaults: {
accept: "*",
activeClass: false,
addClasses: true,
disabled: false,
greedy: false,
hoverClass: false,

View File

@ -3,39 +3,96 @@
*/
(function($) {
module("droppable: options");
/*
test("{ accept '*' }, default ", function() {
ok(false, 'missing test - untested code is broken code');
expect( 1 );
var droppable = $("#droppable1").droppable(),
draggable = $("#draggable1").draggable();
TestHelpers.droppable.shouldDrop( draggable, droppable, "Default" );
});
test("{ accept: Selector }", function() {
ok(false, 'missing test - untested code is broken code');
expect( 3 );
var target = $("#droppable1").droppable(),
source = $("#draggable1").draggable();
TestHelpers.droppable.shouldDrop( source, target, "Default" );
target.droppable( "option", "accept", "#foo" );
TestHelpers.droppable.shouldNotDrop( source, target, "Not correct selector" );
target.droppable( "option", "accept", "#draggable1" );
TestHelpers.droppable.shouldDrop( source, target, "Correct selector" );
});
test("{ accept: function(draggable) }", function() {
ok(false, 'missing test - untested code is broken code');
test("{ accept: Function }", function() {
expect( 5 );
var target = $("#droppable1").droppable(),
source = $("#draggable1").draggable(),
counter = 0;
function accept() {
++counter;
return ( counter%2 === 0 );
}
target.droppable( "option", "accept", accept );
TestHelpers.droppable.shouldNotDrop( source, target, "Function returns false" );
TestHelpers.droppable.shouldDrop( source, target, "Function returns true" );
TestHelpers.droppable.shouldNotDrop( source, target, "Function returns false" );
TestHelpers.droppable.shouldDrop( source, target, "Function returns true" );
target.droppable( "option", "accept", "*" );
TestHelpers.droppable.shouldDrop( source, target, "Reset back to *" );
});
test("activeClass", function() {
ok(false, 'missing test - untested code is broken code');
});
*/
test("{ addClasses: true }, default", function() {
expect( 1 );
var el = $("<div></div>").droppable({ addClasses: true });
ok(el.is(".ui-droppable"), "'ui-droppable' class added");
el.droppable("destroy");
expect( 6 );
var target = $("#droppable1").droppable(),
source = $("#draggable1").draggable(),
myclass = "myclass",
hasclass = false;
source.on( "drag", function() {
hasclass = target.hasClass( myclass );
});
TestHelpers.droppable.shouldDrop( source, target );
equal( hasclass, false, "Option not set yet" );
target.droppable( "option", "activeClass", myclass );
TestHelpers.droppable.shouldDrop( source, target );
equal( hasclass, true, "Option set" );
target.droppable( "option", "activeClass", false );
TestHelpers.droppable.shouldDrop( source, target );
equal( hasclass, false, "Option unset" );
});
test("{ addClasses: false }", function() {
expect( 1 );
var el = $("<div></div>").droppable({ addClasses: false });
ok(!el.is(".ui-droppable"), "'ui-droppable' class not added");
el.droppable("destroy");
});
/*
test("greedy", function() {
ok(false, 'missing test - untested code is broken code');
});

View File

@ -1,10 +1,42 @@
TestHelpers.droppable = {
shouldDrop: function() {
// todo: actually implement this
ok(true, "missing test - untested code is broken code");
shouldDrop: function( source, target, why ) {
var dropped = this.detectDropped( source, target );
why = why ? "Dropped: " + why : "";
equal( dropped, true, + why );
},
shouldNotDrop: function() {
// todo: actually implement this
shouldNotDrop: function( source, target, why ) {
var dropped = this.detectDropped( source, target );
why = why ? "Not Dropped: " + why : "";
equal( dropped, false, why );
},
detectDropped: function( source, target ) {
// TODO: Remove these lines after old tests upgraded
if ( !source || !target ){
ok(true, "missing test - untested code is broken code");
}
var targetOffset = target.offset(),
sourceOffset = source.offset(),
dropped = false;
$(target).on( "drop", function() {
dropped = true;
});
$(source).simulate( "drag", {
dx: targetOffset.left - sourceOffset.left,
dy: targetOffset.top - sourceOffset.top
});
return dropped;
}
};