Permalink
Browse files

Selectmenu: fix unit tests (with clean-up)

  • Loading branch information...
1 parent 6c049f2 commit 5766261af2767862ab6750e5eb8d6a927ced50ae @fnagel fnagel committed Jan 13, 2012
View
29 tests/unit/selectmenu/selectmenu_core.js
@@ -3,13 +3,15 @@
module( "selectmenu: core" );
test("accessibility", function () {
- var element = $('#speed').selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var menu = widget.filter(".ui-selectmenu-menu");
- var link = button.children("a");
- var ul = menu.children("ul")
- var links = ul.find("li.ui-menu-item a");
+ var element = $('#speed').selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu"),
+ link = button.find("a"),
+ selected = element.find("option:selected"),
+ ul = menu.children("ul"),
+ links = ul.find("li.ui-menu-item a");
+
expect(9 + links.length * 2);
equals( "true", link.attr("aria-haspopup"), "button link aria-haspopup" );
@@ -41,12 +43,13 @@ $.each([
], function( i, settings ) {
test("state synchronization - " + settings.type, function () {
expect(5);
- var element = $(settings.selector).selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var menu = widget.filter(".ui-selectmenu-menu");
- var link = button.find("a");
- var selected = element.find("option:selected");
+
+ var element = $(settings.selector).selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu"),
+ link = button.find("a"),
+ selected = element.find("option:selected");
equals( button.text(), selected.text(), "inital button text" );
View
205 tests/unit/selectmenu/selectmenu_events.js
@@ -1,105 +1,108 @@
(function ($) {
- 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");
- }
- });
-
- var widget = this.element.selectmenu("widget"),
- menu = widget.filter(".ui-selectmenu-menu"),
- button = widget.filter(".ui-selectmenu-button"),
- value = this.element.find("option").first().text();
-
- button.find("a").simulate( "click" );
- menu.find("a").first().simulate( "mouseover" ).simulate( "click" );
- });
-
- 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"),
- button = widget.filter(".ui-selectmenu-button"),
- menu = widget.filter(".ui-selectmenu-menu");
-
- button.find("a").simulate( "click" );
- 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"),
- button = widget.filter(".ui-selectmenu-button"),
- menu = widget.filter(".ui-selectmenu-menu");
-
- button.find("a").simulate( "click" );
- menu.find("a").first().simulate( "mouseover" ).simulate("click");
- });
+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");
+ }
+ });
+
+ var widget = this.element.selectmenu("widget"),
+ menu = widget.filter(".ui-selectmenu-menu"),
+ button = widget.filter(".ui-selectmenu-button"),
+ value = this.element.find("option").first().text();
+
+ button.find("a").simulate( "click" );
+ menu.find("a").first().simulate( "mouseover" ).simulate( "click" );
+});
+
+
+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"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu");
+
+ button.find("a").simulate( "click" );
+ 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"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu");
+
+ button.find("a").simulate( "click" );
+ menu.find("a").first().simulate( "mouseover" ).simulate("click");
+});
})(jQuery);
View
59 tests/unit/selectmenu/selectmenu_methods.js
@@ -13,10 +13,10 @@ test( "destroy", function() {
test( "open / close", function() {
expect( 4 );
- var element = $("#speed").selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var menu = widget.filter(".ui-selectmenu-menu");
+ var element = $('#speed').selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu");
element.selectmenu("open");
ok( menu.is( ":visible" ), "menu visible" );
@@ -30,11 +30,12 @@ test( "open / close", function() {
test("enable / disable", function () {
expect(12);
- var element = $("#speed").selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var link = button.children("a");
- var menu = widget.filter(".ui-selectmenu-menu");
+
+ var element = $('#speed').selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu"),
+ link = button.find("a");
element.selectmenu("disable")
ok( element.selectmenu("option", "disabled"), "disable: widget option" );
@@ -56,10 +57,11 @@ test("enable / disable", function () {
test("refresh - structure", function () {
expect(3);
- var element = $("#number").selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var menu = widget.filter(".ui-selectmenu-menu");
+
+ var element = $('#speed').selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu");
element.find("option").eq(2).remove();
element.find("option").eq(3).remove();
@@ -77,10 +79,11 @@ test("refresh - structure", function () {
test("refresh - disabled select", function () {
expect(6);
- var element = $("#speed").selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var menu = widget.filter(".ui-selectmenu-menu");
+
+ var element = $('#speed').selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu");
element.attr("disabled", "disabled");
element.selectmenu("refresh");
@@ -95,10 +98,11 @@ test("refresh - disabled select", function () {
test("refresh - disabled option", function () {
expect(2);
- var element = $("#speed").selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var menu = widget.filter(".ui-selectmenu-menu");
+
+ var element = $('#speed').selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu");
element.attr("disabled", "disabled");
element.find("option").eq(2).attr("disabled", "disabled");
@@ -110,13 +114,14 @@ test("refresh - disabled option", function () {
});
test("refresh - disabled optgroup", function () {
- var element = $("#files").selectmenu();
- var widget = element.selectmenu("widget");
- var button = widget.filter(".ui-selectmenu-button");
- var menu = widget.filter(".ui-selectmenu-menu");
- var originalDisabledOptgroup = element.find("optgroup").first();
- var originalDisabledOptions = originalDisabledOptgroup.find("option");
+ var element = $('#files').selectmenu(),
+ widget = element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ menu = widget.filter(".ui-selectmenu-menu");
+ originalDisabledOptgroup = element.find("optgroup").first(),
+ originalDisabledOptions = originalDisabledOptgroup.find("option");
+
expect(2 + originalDisabledOptions.length * 2);
originalDisabledOptgroup.attr("disabled", "disabled");
View
59 tests/unit/selectmenu/selectmenu_options.js
@@ -1,36 +1,31 @@
(function ($) {
- 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");
- });
-
- 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");
- });
+module("selectmenu: options", {
+ setup: function () {
+ this.element = $("#speed").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");
+});
+
+test("dropdown: CSS styles", function () {
+ expect(2);
+
+ var widget = this.element.selectmenu("widget"),
+ button = widget.filter(".ui-selectmenu-button"),
+ link = button.find("a"),
+ menu = widget.filter(".ui-selectmenu-menu"),
+ ul = widget.find("ul");
+
+ this.element.selectmenu("open");
+
+ ok( link.hasClass("ui-corner-top") && !link.hasClass("ui-corner-all"), "button styles");
+ ok( ul.hasClass("ui-corner-bottom") && !ul.hasClass("ui-corner-all"), "menu styles");
+});
})(jQuery);

0 comments on commit 5766261

Please sign in to comment.