aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-08-03 21:15:38 -0400
committerScott González <scott.gonzalez@gmail.com>2011-08-03 21:15:38 -0400
commitcff6b56fd429b0be2e1668a26b362775263f8925 (patch)
tree502153c4d91b361f5f77c22eaa0b8f08a76623bb /tests
parent4adb9026eab43e36f78991cbe56088f2de110089 (diff)
downloadjquery-ui-cff6b56fd429b0be2e1668a26b362775263f8925.tar.gz
jquery-ui-cff6b56fd429b0be2e1668a26b362775263f8925.zip
Menu tests: Cleanup.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/menu/menu.html22
-rw-r--r--tests/unit/menu/menu_events.js138
-rw-r--r--tests/unit/menu/menu_test_helpers.js14
3 files changed, 88 insertions, 86 deletions
diff --git a/tests/unit/menu/menu.html b/tests/unit/menu/menu.html
index 551d171bd..dc5b71a00 100644
--- a/tests/unit/menu/menu.html
+++ b/tests/unit/menu/menu.html
@@ -16,30 +16,18 @@
<script src="../../jquery.simulate.js"></script>
<script src="../testsuite.js"></script>
- <script>
- function log(message,clear) {
- if (clear && clear === true) {
- $("#log").html("");
- }
- if ( message === undefined ) {
- message = $("#log").data("lastItem");
- }
- $("#log").prepend( message + "," );
- }
- function clickMenu(menu,item) {
- $("#log").data("lastItem",item);
- $('li:eq(' + item + ') a',menu).trigger("click");
- }
- </script>
+ <script src="menu_test_helpers.js"></script>
<script src="menu_core.js"></script>
<script src="menu_defaults.js"></script>
<script src="menu_events.js"></script>
<script src="menu_methods.js"></script>
<script src="menu_options.js"></script>
- <script type="text/javascript" src="../swarminject.js"></script>
+ <script src="../swarminject.js"></script>
<style>
- #qunit-fixture { font-size: 10pt; font-family: "trebuchet ms", verdana, arial; }
+ .ui-menu {
+ font-size: 15px;
+ }
#menu3 {
height: 250px;
overflow: auto;
diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js
index 19ac11c68..312da0d4c 100644
--- a/tests/unit/menu/menu_events.js
+++ b/tests/unit/menu/menu_events.js
@@ -9,15 +9,15 @@ test("handle click on menu", function() {
expect(1);
var ac = $('#menu1').menu({
select: function(event, ui) {
- log();
+ menu_log();
}
});
- log("click",true);
- clickMenu($('#menu1'),"1");
- log("afterclick");
- clickMenu( ac,"2");
- clickMenu($('#menu1'),"3");
- clickMenu( ac,"1");
+ menu_log("click",true);
+ menu_click($('#menu1'),"1");
+ menu_log("afterclick");
+ menu_click( ac,"2");
+ menu_click($('#menu1'),"3");
+ menu_click( ac,"1");
equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
});
@@ -45,59 +45,59 @@ test("handle keyboard navigation on menu without scroll and without submenus", f
expect(12);
var element = $('#menu1').menu({
select: function(event, ui) {
- log($(ui.item[0]).text());
+ menu_log($(ui.item[0]).text());
},
focus: function( event, ui ) {
- log($(event.target).find(".ui-state-focus").parent().index());
+ menu_log($(event.target).find(".ui-state-focus").parent().index());
}
});
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equals( $("#log").html(), "0,keydown,", "Keydown UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equals( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "4,keydown,", "Keydown PAGE_DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equals( $("#log").html(), "4,keydown,", "Keydown END");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equals( $("#log").html(), "0,keydown,", "Keydown HOME");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equals( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equals( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER");
});
@@ -106,27 +106,27 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
expect(14);
var element = $('#menu2').menu({
select: function(event, ui) {
- log($(ui.item[0]).text());
+ menu_log($(ui.item[0]).text());
},
focus: function( event, ui ) {
- log($(event.target).find(".ui-state-focus").parent().index());
+ menu_log($(event.target).find(".ui-state-focus").parent().index());
}
});
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equals( $("#log").html(), "0,keydown,", "Keydown UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
@@ -138,7 +138,7 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
}, 50);
setTimeout( function() {
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equals( $("#log").html(), "4,keydown,", "Keydown LEFT (close submenu)");
@@ -146,41 +146,41 @@ asyncTest("handle keyboard navigation on menu without scroll and with submenus",
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( function() {
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "2,keydown,", "Keydown PAGE_DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equals( $("#log").html(), "2,keydown,", "Keydown END");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equals( $("#log").html(), "0,keydown,", "Keydown HOME");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equals( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( function() {
equals( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equals( $("#log").html(), "Ada,keydown,", "Keydown ENTER (select item)");
@@ -195,67 +195,67 @@ test("handle keyboard navigation on menu with scroll and without submenus", func
expect(14);
var element = $('#menu3').menu({
select: function(event, ui) {
- log($(ui.item[0]).text());
+ menu_log($(ui.item[0]).text());
},
focus: function( event, ui ) {
- log($(event.target).find(".ui-state-focus").parent().index());
+ menu_log($(event.target).find(".ui-state-focus").parent().index());
}
});
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equals( $("#log").html(), "0,keydown,", "Keydown UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equals( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "10,keydown,", "Keydown PAGE_UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equals( $("#log").html(), "37,keydown,", "Keydown END");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equals( $("#log").html(), "0,keydown,", "Keydown HOME");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equals( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equals( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER");
});
@@ -264,27 +264,27 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
expect(14);
var element = $('#menu4').menu({
select: function(event, ui) {
- log($(ui.item[0]).text());
+ menu_log($(ui.item[0]).text());
},
focus: function( event, ui ) {
- log($(event.target).find(".ui-state-focus").parent().index());
+ menu_log($(event.target).find(".ui-state-focus").parent().index());
}
});
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equals( $("#log").html(), "0,keydown,", "Keydown UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
@@ -293,7 +293,7 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
}, 50);
setTimeout( function() {
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equals( $("#log").html(), "1,keydown,", "Keydown LEFT (close submenu)");
@@ -301,41 +301,41 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
setTimeout( function() {
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equals( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "10,keydown,", "Keydown PAGE_UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equals( $("#log").html(), "27,keydown,", "Keydown END");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equals( $("#log").html(), "0,keydown,", "Keydown HOME");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equals( $("#log").html(), "1,keydown,", "Keydown ESCAPE (close submenu)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
setTimeout( function() {
equals( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)");
- log("keydown",true);
+ menu_log("keydown",true);
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
equals( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER (select item)");
diff --git a/tests/unit/menu/menu_test_helpers.js b/tests/unit/menu/menu_test_helpers.js
new file mode 100644
index 000000000..717cfc45d
--- /dev/null
+++ b/tests/unit/menu/menu_test_helpers.js
@@ -0,0 +1,14 @@
+function menu_log( message, clear ) {
+ if ( clear ) {
+ $( "#log" ).empty();
+ }
+ if ( message === undefined ) {
+ message = $( "#log" ).data( "lastItem" );
+ }
+ $( "#log" ).prepend( message + "," );
+}
+
+function menu_click( menu, item ) {
+ $( "#log" ).data( "lastItem", item );
+ menu.find( "li:eq(" + item + ") a" ).trigger( "click" );
+}