Skip to content
Permalink
Browse files

tests: cleanup and consistency with defaults tests

  • Loading branch information...
rdworth committed Nov 12, 2008
1 parent 7d946ec commit e47820f6ea7810569684464c3a3b02eda5d9604d
Showing with 356 additions and 225 deletions.
  1. +58 −58 tests/dialog.js
  2. +47 −46 tests/draggable.js
  3. +10 −10 tests/droppable.js
  4. +24 −13 tests/progressbar.js
  5. +25 −25 tests/resizable.js
  6. +18 −15 tests/selectable.js
  7. +78 −1 tests/slider.js
  8. +33 −26 tests/sortable.js
  9. +31 −2 tests/spinner.js
  10. +32 −29 tests/tabs.js

Large diffs are not rendered by default.

@@ -5,6 +5,37 @@
//
// Draggable Test Helper Functions
//

var defaults = {
appendTo: "parent",
axis: false,
cancel: ":input",
connectToSortable: false,
containment: false,
cursor: "default",
cursorAt: null,
delay: 0,
disabled: false,
distance: 1,
grid: false,
handle: false,
helper: "original",
iframeFix: false,
opacity: 1.0,
refreshPositions: false,
revert: false,
revertDuration: 500,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 20,
scope: "default",
snap: false,
snapMode: "both",
snapTolerance: 20,
stack: false,
zIndex: null
};

var el, offsetBefore, offsetAfter, dragged;

var drag = function(handle, dx, dy) {
@@ -45,44 +76,44 @@ module("draggable");
test("init", function() {
expect(6);

el = $("#draggable1").draggable();
$("<div></div>").appendTo('body').draggable().remove();
ok(true, '.draggable() called on element');

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

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

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

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

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

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

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

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

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

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

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

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

@@ -138,42 +169,12 @@ test("element types", function() {
});

test("defaults", function() {

var expected = {
appendTo: "parent",
axis: false,
cancel: ":input",
connectToSortable: false,
containment: false,
cursor: "default",
cursorAt: null,
delay: 0,
disabled: false,
distance: 1,
grid: false,
handle: false,
helper: "original",
iframeFix: false,
opacity: 1.0,
refreshPositions: false,
revert: false,
revertDuration: 500,
scroll: false,
scrollSensitivity: 20,
scrollSpeed: 20,
scope: "default",
snap: false,
snapMode: "both",
snapTolerance: 20,
stack: false,
zIndex: null
};

el = $("#draggable1").draggable();

for (var optionName in expected)
equals(el.data(optionName + ".draggable"), expected[optionName], optionName);

el = $('<div></div>').draggable();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".draggable"), expected = val;
same(actual, expected, key);
});
el.remove();
});

test("No options, relative", function() {
@@ -33,44 +33,44 @@ module("droppable");
test("init", function() {
expect(6);

el = $("#droppable1").droppable();
$("<div></div>").appendTo('body').droppable().remove();
ok(true, '.droppable() called on element');

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

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

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

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

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

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

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

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

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

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

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

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

@@ -2,36 +2,47 @@
* progressbar unit tests
*/
(function($) {

// Spinner Tests
//
// Progressbar Test Helper Functions
//

var defaults = {
disabled: false,
duration: 1000,
increment: 1,
interval: 1000,
range: true,
width: 300
};

var el;

// Progressbar Tests
module("progressbar");

test("init", function() {
expect(1);

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

});

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

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

});

test("defaults", function() {
expect(5);
el = $("#progressbar").progressbar();

equals(el.data("width.progressbar"), 300, "width");
equals(el.data("duration.progressbar"), 1000, "duration");
equals(el.data("interval.progressbar"), 1000, "interval");
equals(el.data("increment.progressbar"), 1, "increment");
equals(el.data("range.progressbar"), true, "range");

el = $('<div></div>').progressbar();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".progressbar"), expected = val;
same(actual, expected, key);
});
el.remove();
});

test("set defaults on init", function() {
@@ -6,20 +6,6 @@
// Resizable Test Helper Functions
//

var drag = function(el, dx, dy, complete) {

// speed = sync -> Drag syncrhonously.
// speed = fast|slow -> Drag asyncrhonously - animated.

//this mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used
$(el).simulate("mouseover");

return $(el).simulate("drag", {
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
});
};

var defaults = {
animate: false,
animateDuration: 'slow',
@@ -48,54 +34,68 @@ var defaults = {
transparent: false
};

var drag = function(el, dx, dy, complete) {

// speed = sync -> Drag syncrhonously.
// speed = fast|slow -> Drag asyncrhonously - animated.

//this mouseover is to work around a limitation in resizable
//TODO: fix resizable so handle doesn't require mouseover in order to be used
$(el).simulate("mouseover");

return $(el).simulate("drag", {
dx: dx||0, dy: dy||0, speed: 'sync', complete: complete
});
};

// Resizable Tests
module("resizable");

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

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

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

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

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

el = $('<div/>').resizable()
el = $('<div></div>').resizable()
var foo = el.data("foo.resizable");
el.remove();
ok(true, 'arbitrary option getter after init');

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

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

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

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

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

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

el = $('<div/>').resizable();
el = $('<div></div>').resizable();
var foo = el.resizable("destroy").data("foo.resizable");
el.remove();
ok(true, 'arbitrary option getter after destroy');

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

@@ -117,7 +117,7 @@ test("element types", function() {
});

test("defaults", function() {
el = $('<div/>').resizable();
el = $('<div></div>').resizable();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".resizable"), expected = val;
same(actual, expected, key);

0 comments on commit e47820f

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