aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/menu/menu_events.js
diff options
context:
space:
mode:
authorkborchers <kris.borchers@gmail.com>2012-05-22 23:52:59 -0500
committerkborchers <kris.borchers@gmail.com>2012-05-22 23:52:59 -0500
commitc275ebe09b967ab834646be9e0c73f2ff468bdac (patch)
tree430f258cb6054ea0a12115d628b2a6406fd31100 /tests/unit/menu/menu_events.js
parentc1dc1911bf2bad00ca0d343328d3b3ae384bcdfd (diff)
downloadjquery-ui-c275ebe09b967ab834646be9e0c73f2ff468bdac.tar.gz
jquery-ui-c275ebe09b967ab834646be9e0c73f2ff468bdac.zip
Menu Tests: Remove unused unit tests and add new unit tests to improve coverage.
Diffstat (limited to 'tests/unit/menu/menu_events.js')
-rw-r--r--tests/unit/menu/menu_events.js123
1 files changed, 87 insertions, 36 deletions
diff --git a/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js
index 643da4a26..d3a0e1afb 100644
--- a/tests/unit/menu/menu_events.js
+++ b/tests/unit/menu/menu_events.js
@@ -41,49 +41,62 @@ test("handle click on custom item menu", function() {
equal( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid.");
});
-/* Commenting out these tests until a way to handle the extra focus and blur events
- fired by IE is found
-test( "handle blur: click", function() {
- expect( 4 );
- var $menu = $( "#menu1" ).menu({
- focus: function( event, ui ) {
- equal( event.originalEvent.type, "click", "focus triggered 'click'" );
- equal( event.type, "menufocus", "focus event.type is 'menufocus'" );
-
- },
- blur: function( event, ui ) {
- equal( event.originalEvent.type, "click", "blur triggered 'click'" );
- equal( event.type, "menublur", "blur event.type is 'menublur'" );
- }
- });
-
- $menu.find( "li a:first" ).trigger( "click" );
- $( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" );
+asyncTest( "handle blur", function() {
+ expect( 1 );
+ var blurHandled = false,
+ $menu = $( "#menu1" ).menu({
+ blur: function( event, ui ) {
+ // Ignore duplicate blur event fired by IE
+ if ( !blurHandled ) {
+ blurHandled = true;
+ equal( event.type, "menublur", "blur event.type is 'menublur'" );
+ }
+ }
+ });
+
+ click( $menu, "1" );
+ setTimeout( function() {
+ $menu.blur();
+ start();
+ }, 350);
+});
- $("#remove").remove();
+asyncTest( "handle blur on click", function() {
+ expect( 1 );
+ var blurHandled = false,
+ $menu = $( "#menu1" ).menu({
+ blur: function( event, ui ) {
+ // Ignore duplicate blur event fired by IE
+ if ( !blurHandled ) {
+ blurHandled = true;
+ equal( event.type, "menublur", "blur event.type is 'menublur'" );
+ }
+ }
+ });
+
+ click( $menu, "1" );
+ setTimeout( function() {
+ $( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" );
+ $("#remove").remove();
+ start();
+ }, 350);
});
-test( "handle blur on custom item menu: click", function() {
- expect( 4 );
- var $menu = $( "#menu5" ).menu({
+test( "handle focus of menu with active item", function() {
+ expect( 1 );
+ var element = $( "#menu1" ).menu({
focus: function( event, ui ) {
- equal( event.originalEvent.type, "click", "focus triggered 'click'" );
- equal( event.type, "menufocus", "focus event.type is 'menufocus'" );
-
- },
- blur: function( event, ui ) {
- equal( event.originalEvent.type, "click", "blur triggered 'click'" );
- equal( event.type, "menublur", "blur event.type is 'menublur'" );
- },
- items: "div"
+ log( $( event.target ).find( ".ui-state-focus" ).parent().index() );
+ }
});
- click($('#menu5'),"1");
- $( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" );
-
- $("#remove").remove();
+ log( "focus", true );
+ element.focus();
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.focus();
+ equal( $("#log").html(), "2,2,1,0,focus,", "current active item remains active");
});
-*/
asyncTest( "handle submenu auto collapse: mouseleave", function() {
expect( 4 );
@@ -536,4 +549,42 @@ asyncTest("handle keyboard navigation and mouse click on menu with disabled item
}
});
+test("handle keyboard navigation with spelling of menu items", function() {
+ expect( 2 );
+ var element = $( "#menu2" ).menu({
+ focus: function( event, ui ) {
+ log( $( event.target ).find( ".ui-state-focus" ).parent().index() );
+ }
+ });
+
+ log( "keydown", true );
+ element.one( "menufocus", function( event, ui ) {
+ element.simulate( "keydown", { keyCode: 65 } );
+ element.simulate( "keydown", { keyCode: 68 } );
+ element.simulate( "keydown", { keyCode: 68 } );
+ equal( $("#log").html(), "3,1,0,keydown,", "Keydown focus Addyston by spelling the first 3 letters");
+ element.simulate( "keydown", { keyCode: 68 } );
+ equal( $("#log").html(), "4,3,1,0,keydown,", "Keydown focus Delphi by repeating the 'd' again");
+ });
+ element.focus();
+});
+
+asyncTest("handle page up and page down before the menu has focus", function() {
+ expect( 1 );
+ var element = $( "#menu1" ).menu({
+ focus: function( event, ui ) {
+ log( $( event.target ).find( ".ui-state-focus" ).parent().index() );
+ }
+ });
+
+ log( "keydown", true );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
+ element.blur();
+ setTimeout( function() {
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
+ equal( $("#log").html(), "0,0,keydown,", "Page Up and Page Down bring initial focus to first item");
+ start();
+ }, 350);
+});
+
})(jQuery);