Skip to content
Permalink
Browse files

Merge pull request #536 from danwellman/selectmenu

Selectmenu: additional unit tests
  • Loading branch information
fnagel committed Jan 11, 2012
2 parents 021243b + d02f606 commit db4acf61d14210360fdebda602297bc2bdc959ed
Showing with 139 additions and 6 deletions.
  1. +97 −3 tests/unit/selectmenu/selectmenu_events.js
  2. +42 −3 tests/unit/selectmenu/selectmenu_options.js
@@ -1,7 +1,101 @@
(function( $ ) {
(function ($) {

module( "selectmenu: events" );
module("selectmenu: events", {
setup: function () {
this.element = $("#speed");
}
});

test("change", function () {
expect(5);

this.element.selectmenu({
change: function (event, ui) {
ok(event, "change event fired on change");
equals(event.type, "selectmenuchange", "event type set to selectmenuchange");
ok(ui, "ui object is passed as second argument to event handler");
equals(ui.item.element[0].nodeName, "OPTION", "ui.item.element[0] points to original option element");
equals(ui.item.value, value, "ui.item.value property updated correctly");
}
});

})( jQuery );
var widget = this.element.selectmenu("widget"),
menu = widget.filter(".ui-selectmenu-menu"),
value = this.element.find("option").eq(0).text();

menu.find(".ui-menu-item").eq(0).simulate("click");

equals(this.element.selectmenu("option", "value"), "Slower", "should be set to first option");
});

test("close", function () {
expect(3);

this.element.selectmenu({
close: function (event, ui) {
ok(event, "close event fired on close");
equals(event.type, "selectmenuclose", "event type set to selectmenuclose");
ok(ui, "ui object is passed as second argument to event handler");
}
});

this.element.selectmenu("open").selectmenu("close");
});

test("focus", function () {
expect(4);

var counter = 0;

this.element.selectmenu({
focus: function (event, ui) {
counter++;

if (counter === 1) {
ok(event, "focus event fired on mouseover");
equals(event.type, "selectmenufocus", "event type set to selectmenufocus");
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");
}
}
});

var widget = this.element.selectmenu("widget"),
menu = widget.filter(".ui-selectmenu-menu");

menu.find(".ui-menu-item").simulate("mouseover");
});

test("open", function () {
expect(3);

this.element.selectmenu({
open: function (event, ui) {
ok(event, "open event fired on open");
equals(event.type, "selectmenuopen", "event type set to selectmenuopen");
ok(ui, "ui object is passed as second argument to event handler");
}
});

this.element.selectmenu("open");
});

test("select", function () {
expect(4);

this.element.selectmenu({
select: function (event, ui) {
ok(event, "select event fired on item select");
equals(event.type, "selectmenuselect", "event type set to selectmenuselect");
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");
}
});

var widget = this.element.selectmenu("widget"),
menu = widget.filter(".ui-selectmenu-menu");

menu.find(".ui-menu-item").eq(0).simulate("click");
});

})(jQuery);
@@ -1,7 +1,46 @@
(function( $ ) {
(function ($) {

module( "selectmenu: options" );
module("selectmenu: options", {
setup: function () {
this.element = $("#speed");
this.element.selectmenu();
}
});

test("appendTo another element", function () {
expect(2);

ok(this.element.selectmenu("option", "appendTo", "#qunit-fixture"), "appendTo accepts selector");
ok($("#qunit-fixture").find(".ui-selectmenu-menu").length, "selectmenu appendedTo other element");
});

})( jQuery );
test("dropdown", function () {
expect(2);

var button = $("#speed-button"),
widget = this.element.selectmenu("widget"),
buttonPos = {
l: button.offset().top,
t: button.offset().left
},
menuPos = {
l: widget.offset().top,
t: widget.offset().left
};

equals(menuPos.t, buttonPos.t, "menu positioned below button in dropdown mode"); //button has no height

ok(this.element.selectmenu("option", "dropdown", false), "accepts false");
});

test("value option", function () {
expect(1);

var value = this.element.find("option").eq(0).text();

this.element.selectmenu("option", "value", value);

equals(this.element.selectmenu("option", "value"), value, "should be set to " + value);
});

})(jQuery);

0 comments on commit db4acf6

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