From 63d77ae477761b60b1290f01a6dfbe12a2a71170 Mon Sep 17 00:00:00 2001 From: Dan Wellman Date: Thu, 24 Nov 2011 15:50:20 +0000 Subject: Selectmenu: Added event unit tests --- tests/unit/selectmenu/selectmenu_events.js | 108 ++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 3 deletions(-) (limited to 'tests/unit/selectmenu') diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js index 888ab9e9b..2694eaf7f 100644 --- a/tests/unit/selectmenu/selectmenu_events.js +++ b/tests/unit/selectmenu/selectmenu_events.js @@ -1,7 +1,109 @@ -(function( $ ) { +(function ($) { -module( "selectmenu: events" ); + module("selectmenu: events", { + setup: function () { + this.element = $("#speed"); + } + }); + test("change", function () { + expect(4); + var counter = 0; -})( jQuery ); + this.element.selectmenu({ + change: function (event, ui) { + counter++; + + if (counter === 1) { + 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 points to original option element"); + } + } + }); + + var widget = this.element.selectmenu("widget"), + menu = widget.filter(".ui-selectmenu-menu"); + + menu.find(".ui-menu-item").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"), + 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); + + var counter = 0; + + this.element.selectmenu({ + select: function (event, ui) { + counter++; + + if (counter === 1) { + 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").simulate("click"); + }); + +})(jQuery); -- cgit v1.2.3 From fce4725a8ac599efab5449710550a029a2d6fbe3 Mon Sep 17 00:00:00 2001 From: Dan Wellman Date: Fri, 25 Nov 2011 10:32:44 +0000 Subject: Selectmenu: added option unit tests --- tests/unit/selectmenu/selectmenu_options.js | 61 +++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'tests/unit/selectmenu') diff --git a/tests/unit/selectmenu/selectmenu_options.js b/tests/unit/selectmenu/selectmenu_options.js index b19dac4d4..ed6a27bab 100644 --- a/tests/unit/selectmenu/selectmenu_options.js +++ b/tests/unit/selectmenu/selectmenu_options.js @@ -1,7 +1,62 @@ -(function( $ ) { +(function ($) { -module( "selectmenu: options" ); + module("selectmenu: options", { + setup: function () { + this.element = $("#speed"); + this.element.selectmenu(); + } + }); + test("{ appendTo: default }", function () { + expect(1); + equals(this.element.selectmenu("option", "appendTo"), "body", "should be appended to by default"); + }); -})( jQuery ); + test("appendTo another element", function () { + expect(1); + + 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 () { + expect(1); + + 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 () { + expect(1); + + var widget = this.element.selectmenu("widget"), + menu = widget.filter(".ui-selectmenu-menu"); + + menu.find(".ui-menu-item").eq(0).simulate("click"); + + equals(this.element.selectmenu("option", "value"), "Slower", "should be set to first option"); + }); + +})(jQuery); -- cgit v1.2.3 From f381749ed7d557c65970df24c9f2dab4fbc242ac Mon Sep 17 00:00:00 2001 From: Dan Wellman Date: Thu, 1 Dec 2011 15:12:03 +0000 Subject: Updates to events and options unit tests --- tests/unit/selectmenu/selectmenu_events.js | 32 +++++++++-------------------- tests/unit/selectmenu/selectmenu_options.js | 29 -------------------------- 2 files changed, 10 insertions(+), 51 deletions(-) (limited to 'tests/unit/selectmenu') diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js index 2694eaf7f..86bc33177 100644 --- a/tests/unit/selectmenu/selectmenu_events.js +++ b/tests/unit/selectmenu/selectmenu_events.js @@ -9,25 +9,19 @@ test("change", function () { expect(4); - var counter = 0; - this.element.selectmenu({ change: function (event, ui) { - counter++; - - if (counter === 1) { - 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 points to original option element"); - } + 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 points to original option element"); } }); var widget = this.element.selectmenu("widget"), 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 () { @@ -85,25 +79,19 @@ test("select", function () { expect(4); - var counter = 0; - this.element.selectmenu({ select: function (event, ui) { - counter++; - - if (counter === 1) { - 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"); - } + 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").simulate("click"); + 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 ed6a27bab..0a502712c 100644 --- a/tests/unit/selectmenu/selectmenu_options.js +++ b/tests/unit/selectmenu/selectmenu_options.js @@ -7,47 +7,18 @@ } }); - test("{ appendTo: default }", function () { - expect(1); - - equals(this.element.selectmenu("option", "appendTo"), "body", "should be appended to by default"); - }); - test("appendTo another element", function () { expect(1); 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 () { expect(1); 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 () { expect(1); -- cgit v1.2.3 From 716bf407d2ab0696f5cf0bab50ad656c5b5fcc64 Mon Sep 17 00:00:00 2001 From: Dan Wellman Date: Thu, 1 Dec 2011 15:36:49 +0000 Subject: removed duplicates from options unit tests and added new options and events tests --- tests/unit/selectmenu/selectmenu_events.js | 4 +++- tests/unit/selectmenu/selectmenu_options.js | 12 +++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/unit/selectmenu') diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js index 86bc33177..ec4d3ff25 100644 --- a/tests/unit/selectmenu/selectmenu_events.js +++ b/tests/unit/selectmenu/selectmenu_events.js @@ -7,7 +7,7 @@ }); test("change", function () { - expect(4); + expect(5); this.element.selectmenu({ change: function (event, ui) { @@ -22,6 +22,8 @@ menu = widget.filter(".ui-selectmenu-menu"); 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 () { diff --git a/tests/unit/selectmenu/selectmenu_options.js b/tests/unit/selectmenu/selectmenu_options.js index 0a502712c..e6a057ac0 100644 --- a/tests/unit/selectmenu/selectmenu_options.js +++ b/tests/unit/selectmenu/selectmenu_options.js @@ -8,9 +8,10 @@ }); test("appendTo another element", function () { - expect(1); + 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 false", function () { @@ -19,15 +20,12 @@ ok(this.element.selectmenu("option", "dropdown", false), "accepts false"); }); - test("value in sync with selected item", function () { + test("value option", function () { expect(1); - var widget = this.element.selectmenu("widget"), - menu = widget.filter(".ui-selectmenu-menu"); - - menu.find(".ui-menu-item").eq(0).simulate("click"); + this.element.selectmenu("option", "value", "jQuery UI"); - equals(this.element.selectmenu("option", "value"), "Slower", "should be set to first option"); + equals(this.element.selectmenu("option", "value"), "jQuery UI", "should be set to 'jQuery UI'"); }); })(jQuery); -- cgit v1.2.3 From 7d5238ad632d16da2b1e5c2af289c1a3381f5dd0 Mon Sep 17 00:00:00 2001 From: Dan Wellman Date: Thu, 1 Dec 2011 15:36:49 +0000 Subject: Selectmenu: removed duplicates from options unit tests and added new options and events tests --- tests/unit/selectmenu/selectmenu_events.js | 4 +++- tests/unit/selectmenu/selectmenu_options.js | 12 +++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests/unit/selectmenu') diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js index 86bc33177..ec4d3ff25 100644 --- a/tests/unit/selectmenu/selectmenu_events.js +++ b/tests/unit/selectmenu/selectmenu_events.js @@ -7,7 +7,7 @@ }); test("change", function () { - expect(4); + expect(5); this.element.selectmenu({ change: function (event, ui) { @@ -22,6 +22,8 @@ menu = widget.filter(".ui-selectmenu-menu"); 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 () { diff --git a/tests/unit/selectmenu/selectmenu_options.js b/tests/unit/selectmenu/selectmenu_options.js index 0a502712c..e6a057ac0 100644 --- a/tests/unit/selectmenu/selectmenu_options.js +++ b/tests/unit/selectmenu/selectmenu_options.js @@ -8,9 +8,10 @@ }); test("appendTo another element", function () { - expect(1); + 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 false", function () { @@ -19,15 +20,12 @@ ok(this.element.selectmenu("option", "dropdown", false), "accepts false"); }); - test("value in sync with selected item", function () { + test("value option", function () { expect(1); - var widget = this.element.selectmenu("widget"), - menu = widget.filter(".ui-selectmenu-menu"); - - menu.find(".ui-menu-item").eq(0).simulate("click"); + this.element.selectmenu("option", "value", "jQuery UI"); - equals(this.element.selectmenu("option", "value"), "Slower", "should be set to first option"); + equals(this.element.selectmenu("option", "value"), "jQuery UI", "should be set to 'jQuery UI'"); }); })(jQuery); -- cgit v1.2.3 From c1c0827c67de6d52936d7b1906051ab7be95827b Mon Sep 17 00:00:00 2001 From: Dan Wellman Date: Mon, 12 Dec 2011 23:39:06 +0000 Subject: Selectmenu: updated options and events unit tests --- tests/unit/selectmenu/selectmenu_events.js | 8 ++++---- tests/unit/selectmenu/selectmenu_options.js | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'tests/unit/selectmenu') diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js index ec4d3ff25..98171298b 100644 --- a/tests/unit/selectmenu/selectmenu_events.js +++ b/tests/unit/selectmenu/selectmenu_events.js @@ -14,16 +14,16 @@ 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 points to original option element"); + 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"); + 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 () { diff --git a/tests/unit/selectmenu/selectmenu_options.js b/tests/unit/selectmenu/selectmenu_options.js index e6a057ac0..913d1b4c9 100644 --- a/tests/unit/selectmenu/selectmenu_options.js +++ b/tests/unit/selectmenu/selectmenu_options.js @@ -14,8 +14,21 @@ ok($("#qunit-fixture").find(".ui-selectmenu-menu").length, "selectmenu appendedTo other element"); }); - test("dropdown false", function () { - expect(1); + 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"); }); @@ -23,9 +36,11 @@ test("value option", function () { expect(1); - this.element.selectmenu("option", "value", "jQuery UI"); + var value = this.element.find("option").eq(0).text(); + + this.element.selectmenu("option", "value", value); - equals(this.element.selectmenu("option", "value"), "jQuery UI", "should be set to 'jQuery UI'"); + equals(this.element.selectmenu("option", "value"), value, "should be set to " + value); }); })(jQuery); -- cgit v1.2.3