Updates to events and options unit tests

This commit is contained in:
Dan Wellman 2011-12-01 15:12:03 +00:00
parent a4fd5449b2
commit f381749ed7
2 changed files with 10 additions and 51 deletions

View File

@ -9,25 +9,19 @@
test("change", function () { test("change", function () {
expect(4); expect(4);
var counter = 0;
this.element.selectmenu({ this.element.selectmenu({
change: function (event, ui) { change: function (event, ui) {
counter++;
if (counter === 1) {
ok(event, "change event fired on change"); ok(event, "change event fired on change");
equals(event.type, "selectmenuchange", "event type set to selectmenuchange"); equals(event.type, "selectmenuchange", "event type set to selectmenuchange");
ok(ui, "ui object is passed as second argument to event handler"); ok(ui, "ui object is passed as second argument to event handler");
equals(ui.item.element[0].nodeName, "OPTION", "ui points to original option element"); equals(ui.item.element[0].nodeName, "OPTION", "ui points to original option element");
} }
}
}); });
var widget = this.element.selectmenu("widget"), var widget = this.element.selectmenu("widget"),
menu = widget.filter(".ui-selectmenu-menu"); menu = widget.filter(".ui-selectmenu-menu");
menu.find(".ui-menu-item").simulate("click"); menu.find(".ui-menu-item").eq(0).simulate("click");
}); });
test("close", function () { test("close", function () {
@ -85,25 +79,19 @@
test("select", function () { test("select", function () {
expect(4); expect(4);
var counter = 0;
this.element.selectmenu({ this.element.selectmenu({
select: function (event, ui) { select: function (event, ui) {
counter++;
if (counter === 1) {
ok(event, "select event fired on item select"); ok(event, "select event fired on item select");
equals(event.type, "selectmenuselect", "event type set to selectmenuselect"); equals(event.type, "selectmenuselect", "event type set to selectmenuselect");
ok(ui, "ui object is passed as second argument to event handler"); ok(ui, "ui object is passed as second argument to event handler");
equals(ui.item.element[0].nodeName, "OPTION", "ui points to original option element"); equals(ui.item.element[0].nodeName, "OPTION", "ui points to original option element");
} }
}
}); });
var widget = this.element.selectmenu("widget"), var widget = this.element.selectmenu("widget"),
menu = widget.filter(".ui-selectmenu-menu"); menu = widget.filter(".ui-selectmenu-menu");
menu.find(".ui-menu-item").simulate("click"); menu.find(".ui-menu-item").eq(0).simulate("click");
}); });
})(jQuery); })(jQuery);

View File

@ -7,47 +7,18 @@
} }
}); });
test("{ appendTo: default }", function () {
expect(1);
equals(this.element.selectmenu("option", "appendTo"), "body", "should be appended to <body> by default");
});
test("appendTo another element", function () { test("appendTo another element", function () {
expect(1); expect(1);
ok(this.element.selectmenu("option", "appendTo", "#qunit-fixture"), "appendTo accepts selector"); ok(this.element.selectmenu("option", "appendTo", "#qunit-fixture"), "appendTo accepts selector");
}); });
test("{ dropdown: default }", function () {
expect(1);
equals(this.element.selectmenu("option", "dropdown"), true, "should be true by default");
});
test("dropdown false", function () { test("dropdown false", function () {
expect(1); expect(1);
ok(this.element.selectmenu("option", "dropdown", false), "accepts false"); ok(this.element.selectmenu("option", "dropdown", false), "accepts false");
}); });
test("{ position: default }", function () {
expect(4);
var pos = this.element.selectmenu("option", "position");
ok(typeof (pos) === "object", "position should be of type 'object'");
equals(pos.my, "left top", "my should be 'left top' by default");
equals(pos.at, "left bottom", "at should be 'left bottom' by default");
equals(pos.collision, "none", "collision should be 'none' by default")
});
test("{ value: default }", function () {
expect(1);
equals(this.element.selectmenu("option", "value"), "Medium", "should reflect selected value of underlying select");
});
test("value in sync with selected item", function () { test("value in sync with selected item", function () {
expect(1); expect(1);