Skip to content
Permalink
Browse files

sortable unit tests: split tests into individual files

  • Loading branch information
rdworth committed Feb 3, 2009
1 parent d7090f6 commit 66976a932693bf9903fcdd28dd05838a84571c71
@@ -12,7 +12,12 @@
<script type="text/javascript" src="../../../external/qunit/testrunner.js"></script>
<script type="text/javascript" src="../../../external/simulate/jquery.simulate.js"></script>

<script type="text/javascript" src="sortable.js"></script>
<script type="text/javascript" src="sortable_core.js"></script>
<script type="text/javascript" src="sortable_defaults.js"></script>
<script type="text/javascript" src="sortable_events.js"></script>
<script type="text/javascript" src="sortable_methods.js"></script>
<script type="text/javascript" src="sortable_options.js"></script>
<script type="text/javascript" src="sortable_tickets.js"></script>
</head>
<body>

This file was deleted.

@@ -1,6 +1,27 @@
/*
* sortable_core.js
*/

var el, offsetBefore, offsetAfter, dragged;

var drag = function(handle, dx, dy) {
offsetBefore = $(handle).offset();
$(handle).simulate("drag", {
dx: dx || 0,
dy: dy || 0
});
dragged = { dx: dx, dy: dy };
offsetAfter = $(handle).offset();
}

var sort = function(handle, dx, dy, index, msg) {
drag(handle, dx, dy);
equals($(handle).parent().children().index(handle), index, msg);
}

var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); }
var margin = function(el, side) { return parseInt(el.css('margin-' + side)); }

(function($) {

module("sortable: core");
@@ -3,7 +3,30 @@
*/

var sortable_defaults = {
disabled: false
appendTo: "parent",
cancel: ":input,option",
connectWith: false,
cssNamespace: "ui",
cursor: 'default',
cursorAt: false,
delay: 0,
disabled: false,
distance: 1,
dropOnEmpty: true,
forcePlaceholderSize: false,
forceHelperSize: false,
handle: false,
helper: "original",
items: "> *",
opacity: false,
placeholder: false,
scope: "default",
scroll: true,
scrollSensitivity: 20,
scrollSpeed: 20,
sortIndicator: "???",
tolerance: "intersect",
zIndex: 1000
};

commonWidgetTests('sortable', { defaults: sortable_defaults });
@@ -5,7 +5,51 @@

module("sortable: events");

test("testname", function() {
test("start", function() {
ok(false, "missing test - untested code is broken code.");
});

test("sort", function() {
ok(false, "missing test - untested code is broken code.");
});

test("change", function() {
ok(false, "missing test - untested code is broken code.");
});

test("beforeStop", function() {
ok(false, "missing test - untested code is broken code.");
});

test("stop", function() {
ok(false, "missing test - untested code is broken code.");
});

test("update", function() {
ok(false, "missing test - untested code is broken code.");
});

test("receive", function() {
ok(false, "missing test - untested code is broken code.");
});

test("remove", function() {
ok(false, "missing test - untested code is broken code.");
});

test("over", function() {
ok(false, "missing test - untested code is broken code.");
});

test("out", function() {
ok(false, "missing test - untested code is broken code.");
});

test("activate", function() {
ok(false, "missing test - untested code is broken code.");
});

test("deactivate", function() {
ok(false, "missing test - untested code is broken code.");
});

@@ -5,8 +5,82 @@

module("sortable: methods");

test("testname", function() {
ok(false, "missing test - untested code is broken code.");
test("init", function() {
expect(6);

$("<div></div>").appendTo('body').sortable().remove();
ok(true, '.sortable() called on element');

$([]).sortable();
ok(true, '.sortable() called on empty collection');

$("<div></div>").sortable();
ok(true, '.sortable() called on disconnected DOMElement');

$("<div></div>").sortable().sortable("foo");
ok(true, 'arbitrary method called after init');

$("<div></div>").sortable().data("foo.sortable");
ok(true, 'arbitrary option getter after init');

$("<div></div>").sortable().data("foo.sortable", "bar");
ok(true, 'arbitrary option setter after init');
});

test("destroy", function() {
expect(6);

$("<div></div>").appendTo('body').sortable().sortable("destroy").remove();
ok(true, '.sortable("destroy") called on element');

$([]).sortable().sortable("destroy");
ok(true, '.sortable("destroy") called on empty collection');

$("<div></div>").sortable().sortable("destroy");
ok(true, '.sortable("destroy") called on disconnected DOMElement');

$("<div></div>").sortable().sortable("destroy").sortable("foo");
ok(true, 'arbitrary method called after destroy');

$("<div></div>").sortable().sortable("destroy").data("foo.sortable");
ok(true, 'arbitrary option getter after destroy');

$("<div></div>").sortable().sortable("destroy").data("foo.sortable", "bar");
ok(true, 'arbitrary option setter after destroy');
});

test("enable", function() {
expect(4);
el = $("#sortable").sortable({ disabled: true });

sort($("li", el)[0], 0, 40, 0, '.sortable({ disabled: true })');

el.sortable("enable");
equals(el.data("disabled.sortable"), false, "disabled.sortable getter");

el.sortable("destroy");
el.sortable({ disabled: true });
el.data("disabled.sortable", false);
equals(el.data("disabled.sortable"), false, "disabled.sortable setter");

sort($("li", el)[0], 0, 40, 2, '.data("disabled.sortable", false)');
});

test("disable", function() {
expect(5);
el = $("#sortable").sortable({ disabled: false });
sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');

el.sortable("disable");
sort($("li", el)[0], 0, 40, 0, 'disabled.sortable getter');

el.sortable("destroy");

el.sortable({ disabled: false });
sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })');
el.data("disabled.sortable", true);
equals(el.data("disabled.sortable"), true, "disabled.sortable setter");
sort($("li", el)[0], 0, 40, 0, '.data("disabled.sortable", true)');
});

})(jQuery);

0 comments on commit 66976a9

Please sign in to comment.
You can’t perform that action at this time.