diff options
author | Felix Nagel <info@felixnagel.com> | 2012-01-11 11:24:13 -0800 |
---|---|---|
committer | Felix Nagel <info@felixnagel.com> | 2012-01-11 11:24:13 -0800 |
commit | db4acf61d14210360fdebda602297bc2bdc959ed (patch) | |
tree | 570c655dba896f92565cc2df117cd664f89d246c /tests/unit/selectmenu | |
parent | 021243bc9b8aa81a3461564ce17ca3fc360fb948 (diff) | |
parent | d02f6063e29dc9486d23156eaa881d944fd2c2d8 (diff) | |
download | jquery-ui-db4acf61d14210360fdebda602297bc2bdc959ed.tar.gz jquery-ui-db4acf61d14210360fdebda602297bc2bdc959ed.zip |
Merge pull request #536 from danwellman/selectmenu
Selectmenu: additional unit tests
Diffstat (limited to 'tests/unit/selectmenu')
-rw-r--r-- | tests/unit/selectmenu/selectmenu_events.js | 100 | ||||
-rw-r--r-- | tests/unit/selectmenu/selectmenu_options.js | 45 |
2 files changed, 139 insertions, 6 deletions
diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js index 888ab9e9b..fa25e69bb 100644 --- a/tests/unit/selectmenu/selectmenu_events.js +++ b/tests/unit/selectmenu/selectmenu_events.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); diff --git a/tests/unit/selectmenu/selectmenu_options.js b/tests/unit/selectmenu/selectmenu_options.js index b19dac4d4..913d1b4c9 100644 --- a/tests/unit/selectmenu/selectmenu_options.js +++ b/tests/unit/selectmenu/selectmenu_options.js @@ -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); |