Permalink
Browse files

Menu Tests: Remove unused unit tests and add new unit tests to improv…

…e coverage.
  • Loading branch information...
1 parent c1dc191 commit c275ebe09b967ab834646be9e0c73f2ff468bdac @kborchers kborchers committed May 23, 2012
Showing with 88 additions and 37 deletions.
  1. +1 −1 tests/unit/menu/menu.html
  2. +87 −36 tests/unit/menu/menu_events.js
@@ -63,7 +63,7 @@ <h2 id="qunit-userAgent"></h2>
<li class="foo"><a class="foo" href="#">Aberdeen</a></li>
<li class="foo"><a class="foo" href="#">Ada</a></li>
<li class="foo"><a class="foo" href="#">Adamsville</a></li>
- <li class="foo"><a class="foo" href="#">Addyston</a></li>
+ <li class="foo"><a class="foo" href="#"><span class="ui-icon ui-icon-print"></span>Addyston</a></li>
<li>
<a href="#">Delphi</a>
<ul>
@@ -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);

0 comments on commit c275ebe

Please sign in to comment.