diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/menu/core.js | 50 | ||||
-rw-r--r-- | tests/unit/menu/events.js | 293 | ||||
-rw-r--r-- | tests/unit/menu/methods.js | 51 | ||||
-rw-r--r-- | tests/unit/menu/options.js | 63 |
4 files changed, 239 insertions, 218 deletions
diff --git a/tests/unit/menu/core.js b/tests/unit/menu/core.js index 200812f4e..6742aa53e 100644 --- a/tests/unit/menu/core.js +++ b/tests/unit/menu/core.js @@ -1,48 +1,50 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/menu" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { -module( "menu: core" ); +QUnit.module( "menu: core" ); -test( "markup structure", function( assert ) { - expect( 11 ); +QUnit.test( "markup structure", function( assert ) { + assert.expect( 11 ); var element = $( "#menu9" ).menu(), items = element.children(), firstItemChildren = items.eq( 0 ).children(); assert.hasClasses( element, "ui-menu ui-widget ui-widget-content" ); assert.hasClasses( items[ 0 ], "ui-menu-item" ); - equal( items.eq( 0 ).children().length, 2, "Item has exactly 2 children when it has a sub menu" ); + assert.equal( items.eq( 0 ).children().length, 2, "Item has exactly 2 children when it has a sub menu" ); assert.hasClasses( firstItemChildren[ 0 ], "ui-menu-item-wrapper" ); assert.hasClasses( firstItemChildren[ 1 ], "ui-menu ui-widget ui-widget-content" ); assert.hasClasses( firstItemChildren.eq( 1 ).children()[ 0 ], "ui-menu-item" ); assert.hasClasses( firstItemChildren.eq( 1 ).children().eq( 0 ).children(), "ui-menu-item-wrapper" ); assert.hasClasses( items[ 1 ], "ui-menu-item" ); - equal( items.eq( 1 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" ); + assert.equal( items.eq( 1 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" ); assert.hasClasses( items[ 2 ], "ui-menu-item" ); - equal( items.eq( 2 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" ); + assert.equal( items.eq( 2 ).children().length, 1, "Item has exactly 1 child when it does not have a sub menu" ); } ); -test( "accessibility", function() { - expect( 4 ); +QUnit.test( "accessibility", function( assert ) { + assert.expect( 4 ); var element = $( "#menu1" ).menu(); - equal( element.attr( "role" ), "menu", "main role" ); - ok( !element.attr( "aria-activedescendant" ), "aria-activedescendant not set" ); + assert.equal( element.attr( "role" ), "menu", "main role" ); + assert.ok( !element.attr( "aria-activedescendant" ), "aria-activedescendant not set" ); element.menu( "focus", $.Event(), element.children().eq( -2 ) ); - equal( element.attr( "aria-activedescendant" ), "testID1", "aria-activedescendant from existing id" ); + assert.equal( element.attr( "aria-activedescendant" ), "testID1", "aria-activedescendant from existing id" ); element.menu( "focus", $.Event(), element.children().eq( 0 ) ); - ok( /^ui-id-\d+$/.test( element.attr( "aria-activedescendant" ) ), "aria-activedescendant from generated id" ); + assert.ok( /^ui-id-\d+$/.test( element.attr( "aria-activedescendant" ) ), "aria-activedescendant from generated id" ); // Item roles are tested in the role option tests } ); -asyncTest( "#9044: Autofocus issue with dialog opened from menu widget", function() { - expect( 1 ); +QUnit.test( "#9044: Autofocus issue with dialog opened from menu widget", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "#menu1" ).menu(); $( "<input>", { id: "test9044" } ).appendTo( "body" ); @@ -53,14 +55,15 @@ asyncTest( "#9044: Autofocus issue with dialog opened from menu widget", functio testHelper.click( element, "3" ); setTimeout( function() { - equal( document.activeElement.id, "test9044", "Focus was swallowed by menu" ); + assert.equal( document.activeElement.id, "test9044", "Focus was swallowed by menu" ); $( "#test9044" ).remove(); - start(); + ready(); } ); } ); -asyncTest( "#9532: Need a way in Menu to keep ui-state-active class on selected item for Selectmenu", function( assert ) { - expect( 1 ); +QUnit.test( "#9532: Need a way in Menu to keep ui-state-active class on selected item for Selectmenu", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "#menu1" ).menu(), firstChild = element.children().eq( 0 ), wrapper = firstChild.children( ".ui-menu-item-wrapper" ); @@ -69,12 +72,13 @@ asyncTest( "#9532: Need a way in Menu to keep ui-state-active class on selected wrapper.addClass( "ui-state-active" ); setTimeout( function() { assert.hasClasses( wrapper, "ui-state-active" ); - start(); + ready(); } ); } ); -asyncTest( "active menu item styling", function( assert ) { - expect( 5 ); +QUnit.test( "active menu item styling", function( assert ) { + var ready = assert.async(); + assert.expect( 5 ); function isActive( item ) { assert.hasClasses( item.children( ".ui-menu-item-wrapper" ), "ui-state-active" ); } @@ -97,7 +101,7 @@ asyncTest( "active menu item styling", function( assert ) { isInactive( parentItem ); isInactive( childItem ); $.ui.menu.prototype.delay = 300; - start(); + ready(); }, 50 ); } ); } ); diff --git a/tests/unit/menu/events.js b/tests/unit/menu/events.js index 4d2af394f..701523de7 100644 --- a/tests/unit/menu/events.js +++ b/tests/unit/menu/events.js @@ -1,21 +1,22 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/menu" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { var log = testHelper.log, logOutput = testHelper.logOutput, click = testHelper.click; -module( "menu: events", { - setup: function() { +QUnit.module( "menu: events", { + beforeEach: function() { testHelper.clearLog(); } } ); -test( "handle click on menu", function() { - expect( 1 ); +QUnit.test( "handle click on menu", function( assert ) { + assert.expect( 1 ); var element = $( "#menu1" ).menu( { select: function() { log(); @@ -27,11 +28,11 @@ test( "handle click on menu", function() { click( element, "2" ); click( element, "3" ); click( element, "1" ); - equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." ); + assert.equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." ); } ); -test( "handle click on custom item menu", function() { - expect( 1 ); +QUnit.test( "handle click on custom item menu", function( assert ) { + assert.expect( 1 ); var element = $( "#menu5" ).menu( { select: function() { log(); @@ -44,11 +45,12 @@ test( "handle click on custom item menu", function() { click( element, "2" ); click( element, "3" ); click( element, "1" ); - equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." ); + assert.equal( logOutput(), "click,1,afterclick,2,3,1", "Click order not valid." ); } ); -asyncTest( "handle blur", function() { - expect( 2 ); +QUnit.test( "handle blur", function( assert ) { + var ready = assert.async(); + assert.expect( 2 ); var blurHandled = false, index = 1, element = $( "#menu1" ).menu( { @@ -57,8 +59,8 @@ asyncTest( "handle blur", function() { // Ignore duplicate blur event fired by IE if ( !blurHandled ) { blurHandled = true; - equal( event.type, "menublur", "blur event.type is 'menublur'" ); - strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" ); + assert.equal( event.type, "menublur", "blur event.type is 'menublur'" ); + assert.strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" ); } } } ); @@ -67,13 +69,14 @@ asyncTest( "handle blur", function() { setTimeout( function() { element.trigger( "blur" ); setTimeout( function() { - start(); + ready(); }, 350 ); } ); } ); -asyncTest( "handle blur via click outside", function() { - expect( 2 ); +QUnit.test( "handle blur via click outside", function( assert ) { + var ready = assert.async(); + assert.expect( 2 ); var blurHandled = false, index = 1, element = $( "#menu1" ).menu( { @@ -82,8 +85,8 @@ asyncTest( "handle blur via click outside", function() { // Ignore duplicate blur event fired by IE if ( !blurHandled ) { blurHandled = true; - equal( event.type, "menublur", "blur event.type is 'menublur'" ); - strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" ); + assert.equal( event.type, "menublur", "blur event.type is 'menublur'" ); + assert.strictEqual( ui.item[ 0 ], element.children()[ index ], "ui.item" ); } } } ); @@ -92,13 +95,14 @@ asyncTest( "handle blur via click outside", function() { setTimeout( function() { $( "<a>", { id: "remove" } ).appendTo( "body" ).trigger( "click" ); setTimeout( function() { - start(); + ready(); }, 350 ); } ); } ); -asyncTest( "handle focus of menu with active item", function() { - expect( 1 ); +QUnit.test( "handle focus of menu with active item", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "#menu1" ).menu( { focus: function( event ) { log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() ); @@ -114,14 +118,14 @@ asyncTest( "handle focus of menu with active item", function() { setTimeout( function() { element[ 0 ].focus(); setTimeout( function() { - equal( logOutput(), "focus,0,1,2,2", "current active item remains active" ); - start(); + assert.equal( logOutput(), "focus,0,1,2,2", "current active item remains active" ); + ready(); } ); } ); } ); } ); -test( "handle mouseenter on nested menu item", function( assert ) { +QUnit.test( "handle mouseenter on nested menu item", function( assert ) { assert.expect( 8 ); $.ui.menu.prototype.delay = 1; var activeItem, @@ -133,7 +137,7 @@ test( "handle mouseenter on nested menu item", function( assert ) { .menu( "expand" ); function checkSubmenus() { - equal( element.find( "ul[aria-expanded='true']" ).length, 2, "both submenus expanded" ); + assert.equal( element.find( "ul[aria-expanded='true']" ).length, 2, "both submenus expanded" ); } function menumouseenter1() { element.menu( "expand" ); @@ -163,70 +167,73 @@ test( "handle mouseenter on nested menu item", function( assert ) { setTimeout( menumouseenter1, 25 ); } ); -asyncTest( "handle submenu auto collapse: mouseleave, default markup", function() { - expect( 4 ); +QUnit.test( "handle submenu auto collapse: mouseleave, default markup", function( assert ) { + var ready = assert.async(); + assert.expect( 4 ); $.ui.menu.prototype.delay = 1; var element = $( "#menu2" ).menu(), event = $.Event( "mouseenter" ); function menumouseleave1() { - equal( element.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" ); + assert.equal( element.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" ); element.menu( "focus", event, element.find( "li:nth-child(7) li:first" ) ); setTimeout( menumouseleave2, 25 ); } function menumouseleave2() { - equal( element.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" ); + assert.equal( element.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" ); element.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" ); setTimeout( menumouseleave3, 25 ); } function menumouseleave3() { - equal( element.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + assert.equal( element.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); element.trigger( "mouseleave" ); setTimeout( menumouseleave4, 25 ); } function menumouseleave4() { - equal( element.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + assert.equal( element.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); $.ui.menu.prototype.delay = 300; - start(); + ready(); } element.find( "li:nth-child(7)" ).trigger( "mouseenter" ); setTimeout( menumouseleave1, 25 ); } ); -asyncTest( "handle submenu auto collapse: mouseleave, custom markup", function() { - expect( 4 ); +QUnit.test( "handle submenu auto collapse: mouseleave, custom markup", function( assert ) { + var ready = assert.async(); + assert.expect( 4 ); $.ui.menu.prototype.delay = 1; var element = $( "#menu5" ).menu( { menus: ".menu" } ), event = $.Event( "mouseenter" ); function menumouseleave1() { - equal( element.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" ); + assert.equal( element.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" ); element.menu( "focus", event, element.find( ":nth-child(7)" ).find( ".menu" ).eq( 0 ).children().eq( 0 ) ); setTimeout( menumouseleave2, 25 ); } function menumouseleave2() { - equal( element.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" ); + assert.equal( element.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" ); element.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" ); setTimeout( menumouseleave3, 25 ); } function menumouseleave3() { - equal( element.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + assert.equal( element.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); element.trigger( "mouseleave" ); setTimeout( menumouseleave4, 25 ); } function menumouseleave4() { - equal( element.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + assert.equal( element.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); $.ui.menu.prototype.delay = 300; - start(); + ready(); } element.find( ":nth-child(7)" ).trigger( "mouseenter" ); setTimeout( menumouseleave1, 25 ); } ); -asyncTest( "handle keyboard navigation on menu without scroll and without submenus", function() { - expect( 12 ); +QUnit.test( "handle keyboard navigation on menu without scroll and without submenus", function( assert ) { + var ready = assert.async(); + assert.expect( 12 ); var element = $( "#menu1" ).menu( { select: function( event, ui ) { log( $( ui.item[ 0 ] ).text() ); @@ -241,58 +248,59 @@ asyncTest( "handle keyboard navigation on menu without scroll and without submen setTimeout( function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" ); + assert.equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( logOutput(), "keydown,1", "Keydown UP" ); + assert.equal( logOutput(), "keydown,1", "Keydown UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); - equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown,4", "Keydown PAGE_DOWN" ); + assert.equal( logOutput(), "keydown,4", "Keydown PAGE_DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); + assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( logOutput(), "keydown,4", "Keydown END" ); + assert.equal( logOutput(), "keydown,4", "Keydown END" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( logOutput(), "keydown,0", "Keydown HOME" ); + assert.equal( logOutput(), "keydown,0", "Keydown HOME" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" ); + assert.equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" ); - start(); + ready(); } ); } ); -asyncTest( "handle keyboard navigation on menu without scroll and with submenus", function() { - expect( 16 ); +QUnit.test( "handle keyboard navigation on menu without scroll and with submenus", function( assert ) { + var ready = assert.async(); + assert.expect( 16 ); var element = $( "#menu2" ).menu( { select: function( event, ui ) { log( $( ui.item[ 0 ] ).text() ); @@ -306,7 +314,7 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" element.one( "menufocus", function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( logOutput(), "keydown,1,2", "Keydown DOWN" ); + assert.equal( logOutput(), "keydown,1,2", "Keydown DOWN" ); setTimeout( menukeyboard1 ); } ); element.trigger( "focus" ); @@ -315,11 +323,11 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( logOutput(), "keydown,1,0", "Keydown UP" ); + assert.equal( logOutput(), "keydown,1,0", "Keydown UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); @@ -329,7 +337,7 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); setTimeout( function() { - equal( logOutput(), "keydown,1,2,3,4,0", "Keydown RIGHT (open submenu)" ); + assert.equal( logOutput(), "keydown,1,2,3,4,0", "Keydown RIGHT (open submenu)" ); setTimeout( menukeyboard2 ); } ); } @@ -337,7 +345,7 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" function menukeyboard2() { log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( logOutput(), "keydown,4", "Keydown LEFT (close submenu)" ); + assert.equal( logOutput(), "keydown,4", "Keydown LEFT (close submenu)" ); // Re-open submenu element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); @@ -347,31 +355,31 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" function menukeyboard3() { log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown,2", "Keydown PAGE_DOWN" ); + assert.equal( logOutput(), "keydown,2", "Keydown PAGE_DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); + assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( logOutput(), "keydown,2", "Keydown END" ); + assert.equal( logOutput(), "keydown,2", "Keydown END" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( logOutput(), "keydown,0", "Keydown HOME" ); + assert.equal( logOutput(), "keydown,0", "Keydown HOME" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" ); + assert.equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.SPACE } ); @@ -379,11 +387,11 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" } function menukeyboard4() { - equal( logOutput(), "keydown,0", "Keydown SPACE (open submenu)" ); + assert.equal( logOutput(), "keydown,0", "Keydown SPACE (open submenu)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" ); + assert.equal( logOutput(), "keydown,4", "Keydown ESCAPE (close submenu)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); @@ -396,7 +404,7 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( logOutput(), "keydown,5,6,0,1,0,2,4,0", "Keydown skip dividers" ); + assert.equal( logOutput(), "keydown,5,6,0,1,0,2,4,0", "Keydown skip dividers" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); @@ -406,13 +414,14 @@ asyncTest( "handle keyboard navigation on menu without scroll and with submenus" } function menukeyboard6() { - equal( logOutput(), "keydown,Ada", "Keydown ENTER (open submenu)" ); - start(); + assert.equal( logOutput(), "keydown,Ada", "Keydown ENTER (open submenu)" ); + ready(); } } ); -asyncTest( "handle keyboard navigation on menu with scroll and without submenus", function() { - expect( 14 ); +QUnit.test( "handle keyboard navigation on menu with scroll and without submenus", function( assert ) { + var ready = assert.async(); + assert.expect( 14 ); var element = $( "#menu3" ).menu( { select: function( event, ui ) { log( $( ui.item[ 0 ] ).text() ); @@ -427,67 +436,68 @@ asyncTest( "handle keyboard navigation on menu with scroll and without submenus" setTimeout( function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" ); + assert.equal( logOutput(), "keydown,0,1,2", "Keydown DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( logOutput(), "keydown,1,0", "Keydown UP" ); + assert.equal( logOutput(), "keydown,1,0", "Keydown UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); - equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown RIGHT (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" ); + assert.equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown,34", "Keydown PAGE_DOWN" ); + assert.equal( logOutput(), "keydown,34", "Keydown PAGE_DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown,17", "Keydown PAGE_UP" ); + assert.equal( logOutput(), "keydown,17", "Keydown PAGE_UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); + assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown PAGE_UP (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( logOutput(), "keydown,37", "Keydown END" ); + assert.equal( logOutput(), "keydown,37", "Keydown END" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown PAGE_DOWN (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( logOutput(), "keydown,0", "Keydown HOME" ); + assert.equal( logOutput(), "keydown,0", "Keydown HOME" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown ESCAPE (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" ); + assert.equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER" ); - start(); + ready(); } ); } ); -asyncTest( "handle keyboard navigation on menu with scroll and with submenus", function() { - expect( 14 ); +QUnit.test( "handle keyboard navigation on menu with scroll and with submenus", function( assert ) { + var ready = assert.async(); + assert.expect( 14 ); var element = $( "#menu4" ).menu( { select: function( event, ui ) { log( $( ui.item[ 0 ] ).text() ); @@ -501,7 +511,7 @@ asyncTest( "handle keyboard navigation on menu with scroll and with submenus", f element.one( "menufocus", function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( logOutput(), "keydown,1,2", "Keydown DOWN" ); + assert.equal( logOutput(), "keydown,1,2", "Keydown DOWN" ); setTimeout( menukeyboard1 ); } ); element.trigger( "focus" ); @@ -510,18 +520,18 @@ asyncTest( "handle keyboard navigation on menu with scroll and with submenus", f log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); - equal( logOutput(), "keydown,1,0", "Keydown UP" ); + assert.equal( logOutput(), "keydown,1,0", "Keydown UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); setTimeout( function() { - equal( logOutput(), "keydown,1,0", "Keydown RIGHT (open submenu)" ); + assert.equal( logOutput(), "keydown,1,0", "Keydown RIGHT (open submenu)" ); }, 50 ); setTimeout( menukeyboard2, 50 ); } @@ -529,7 +539,7 @@ asyncTest( "handle keyboard navigation on menu with scroll and with submenus", f function menukeyboard2() { log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( logOutput(), "keydown,1", "Keydown LEFT (close submenu)" ); + assert.equal( logOutput(), "keydown,1", "Keydown LEFT (close submenu)" ); // Re-open submenu element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); @@ -539,31 +549,31 @@ asyncTest( "handle keyboard navigation on menu with scroll and with submenus", f function menukeyboard3() { log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" ); + assert.equal( logOutput(), "keydown,17", "Keydown PAGE_DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); - equal( logOutput(), "keydown,27", "Keydown PAGE_DOWN" ); + assert.equal( logOutput(), "keydown,27", "Keydown PAGE_DOWN" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown,10", "Keydown PAGE_UP" ); + assert.equal( logOutput(), "keydown,10", "Keydown PAGE_UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); - equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); + assert.equal( logOutput(), "keydown,0", "Keydown PAGE_UP" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); - equal( logOutput(), "keydown,27", "Keydown END" ); + assert.equal( logOutput(), "keydown,27", "Keydown END" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); - equal( logOutput(), "keydown,0", "Keydown HOME" ); + assert.equal( logOutput(), "keydown,0", "Keydown HOME" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); - equal( logOutput(), "keydown,1", "Keydown ESCAPE (close submenu)" ); + assert.equal( logOutput(), "keydown,1", "Keydown ESCAPE (close submenu)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); @@ -571,18 +581,19 @@ asyncTest( "handle keyboard navigation on menu with scroll and with submenus", f } function menukeyboard4() { - equal( logOutput(), "keydown,0", "Keydown ENTER (open submenu)" ); + assert.equal( logOutput(), "keydown,0", "Keydown ENTER (open submenu)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER (select item)" ); + assert.equal( logOutput(), "keydown,Aberdeen", "Keydown ENTER (select item)" ); - start(); + ready(); } } ); -asyncTest( "handle keyboard navigation and mouse click on menu with disabled items", function() { - expect( 6 ); +QUnit.test( "handle keyboard navigation and mouse click on menu with disabled items", function( assert ) { + var ready = assert.async(); + assert.expect( 6 ); var element = $( "#menu6" ).menu( { select: function( event, ui ) { log( $( ui.item[ 0 ] ).text() ); @@ -596,7 +607,7 @@ asyncTest( "handle keyboard navigation and mouse click on menu with disabled ite element.one( "menufocus", function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( logOutput(), "keydown,1", "Keydown focus but not select disabled item" ); + assert.equal( logOutput(), "keydown,1", "Keydown focus but not select disabled item" ); setTimeout( menukeyboard1, 50 ); } ); element.trigger( "focus" ); @@ -606,34 +617,35 @@ asyncTest( "handle keyboard navigation and mouse click on menu with disabled ite element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( logOutput(), "keydown,2,3,4", "Keydown focus disabled item with submenu" ); + assert.equal( logOutput(), "keydown,2,3,4", "Keydown focus disabled item with submenu" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); - equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); + assert.equal( logOutput(), "keydown", "Keydown LEFT (no effect)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); setTimeout( function() { - equal( logOutput(), "keydown", "Keydown RIGHT (no effect on disabled sub-menu)" ); + assert.equal( logOutput(), "keydown", "Keydown RIGHT (no effect on disabled sub-menu)" ); log( "keydown", true ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); setTimeout( function() { - equal( logOutput(), "keydown", "Keydown ENTER (no effect on disabled sub-menu)" ); + assert.equal( logOutput(), "keydown", "Keydown ENTER (no effect on disabled sub-menu)" ); log( "click", true ); click( element, "1" ); - equal( logOutput(), "click", "Click disabled item (no effect)" ); - start(); + assert.equal( logOutput(), "click", "Click disabled item (no effect)" ); + ready(); }, 50 ); }, 50 ); } } ); -asyncTest( "handle keyboard navigation and mouse click on menu with dividers and group labels", function() { - expect( 2 ); +QUnit.test( "handle keyboard navigation and mouse click on menu with dividers and group labels", function( assert ) { + var ready = assert.async(); + assert.expect( 2 ); var element = $( "#menu7" ).menu( { items: "> :not('.ui-menu-group')", select: function( event, ui ) { @@ -648,7 +660,7 @@ asyncTest( "handle keyboard navigation and mouse click on menu with dividers and element.one( "menufocus", function() { element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); - equal( logOutput(), "keydown,2,Ada", "Keydown skips initial group label" ); + assert.equal( logOutput(), "keydown,2,Ada", "Keydown skips initial group label" ); setTimeout( menukeyboard1, 50 ); } ); element.trigger( "focus" ); @@ -658,13 +670,14 @@ asyncTest( "handle keyboard navigation and mouse click on menu with dividers and element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - equal( logOutput(), "keydown,3,4,7", "Keydown focus skips divider and group label" ); - start(); + assert.equal( logOutput(), "keydown,3,4,7", "Keydown focus skips divider and group label" ); + ready(); } } ); -asyncTest( "handle keyboard navigation with spelling of menu items", function() { - expect( 3 ); +QUnit.test( "handle keyboard navigation with spelling of menu items", function( assert ) { + var ready = assert.async(); + assert.expect( 3 ); var element = $( "#menu2" ).menu( { focus: function( event ) { log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() ); @@ -676,18 +689,19 @@ asyncTest( "handle keyboard navigation with spelling of menu items", function() element.simulate( "keydown", { keyCode: 65 } ); element.simulate( "keydown", { keyCode: 68 } ); element.simulate( "keydown", { keyCode: 68 } ); - equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" ); + assert.equal( logOutput(), "keydown,0,1,3", "Keydown focus Addyston by spelling the first 3 letters" ); element.simulate( "keydown", { keyCode: 68 } ); - equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" ); + assert.equal( logOutput(), "keydown,0,1,3,4", "Keydown focus Delphi by repeating the 'd' again" ); element.simulate( "keydown", { keyCode: 83 } ); - equal( logOutput(), "keydown,0,1,3,4,5", "Keydown focus Saarland ignoring leading space" ); - start(); + assert.equal( logOutput(), "keydown,0,1,3,4,5", "Keydown focus Saarland ignoring leading space" ); + ready(); } ); element[ 0 ].focus(); } ); -asyncTest( "Keep focus on selected item (see #10644)", function() { - expect( 1 ); +QUnit.test( "Keep focus on selected item (see #10644)", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "#menu2" ).menu( { focus: function( event ) { log( $( event.target ).find( ".ui-menu-item-wrapper.ui-state-active" ).parent().index() ); @@ -701,15 +715,15 @@ asyncTest( "Keep focus on selected item (see #10644)", function() { element.simulate( "keydown", { keyCode: 68 } ); element.simulate( "keydown", { keyCode: 89 } ); element.simulate( "keydown", { keyCode: 83 } ); - equal( logOutput(), "keydown,0,1,3,3,3", + assert.equal( logOutput(), "keydown,0,1,3,3,3", "Focus stays on 'Addyston', even after other options are eliminated" ); - start(); + ready(); } ); element[ 0 ].focus(); } ); -test( "#9469: Stopping propagation in a select event should not suppress subsequent select events.", function() { - expect( 1 ); +QUnit.test( "#9469: Stopping propagation in a select event should not suppress subsequent select events.", function( assert ) { + assert.expect( 1 ); var element = $( "#menu1" ).menu( { select: function( event ) { log(); @@ -720,23 +734,24 @@ test( "#9469: Stopping propagation in a select event should not suppress subsequ click( element, "1" ); click( element, "2" ); - equal( logOutput(), "1,2", "Both select events were not triggered." ); + assert.equal( logOutput(), "1,2", "Both select events were not triggered." ); } ); -asyncTest( "#10571: When typing in a menu, only menu-items should be focused", function( assert ) { - expect( 3 ); +QUnit.test( "#10571: When typing in a menu, only menu-items should be focused", function( assert ) { + var ready = assert.async(); + assert.expect( 3 ); var element = $( "#menu8" ).menu( { focus: function( event, ui ) { - equal( ui.item.length, 1, "There should only be one match when filtering" ); + assert.equal( ui.item.length, 1, "There should only be one match when filtering" ); assert.hasClasses( ui.item, "ui-menu-item" ); - equal( ui.item.text(), "-Saarland", "element has correct text" ); + assert.equal( ui.item.text(), "-Saarland", "element has correct text" ); } } ); setTimeout( function() { element.menu( "widget" ).simulate( "keydown", { keyCode: "-".charCodeAt( 0 ) } ); - start(); + ready(); } ); } ); diff --git a/tests/unit/menu/methods.js b/tests/unit/menu/methods.js index dc857cc42..48eaa33cd 100644 --- a/tests/unit/menu/methods.js +++ b/tests/unit/menu/methods.js @@ -1,21 +1,22 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/menu" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { var log = testHelper.log, logOutput = testHelper.logOutput, click = testHelper.click; -module( "menu: methods", { - setup: function() { +QUnit.module( "menu: methods", { + beforeEach: function() { testHelper.clearLog(); } } ); -test( "destroy", function( assert ) { - expect( 2 ); +QUnit.test( "destroy", function( assert ) { + assert.expect( 2 ); assert.domEqual( "#menu2", function() { $( "#menu2" ).menu().menu( "destroy" ); } ); @@ -24,8 +25,8 @@ test( "destroy", function( assert ) { } ); } ); -test( "enable/disable", function( assert ) { - expect( 3 ); +QUnit.test( "enable/disable", function( assert ) { + assert.expect( 3 ); var element = $( "#menu1" ).menu( { select: function() { log(); @@ -41,34 +42,34 @@ test( "enable/disable", function( assert ) { log( "click" ); click( element, "1" ); log( "afterclick" ); - equal( logOutput(), "click,afterclick,click,1,afterclick", "Click order not valid." ); + assert.equal( logOutput(), "click,afterclick,click,1,afterclick", "Click order not valid." ); } ); -test( "refresh", function() { - expect( 5 ); +QUnit.test( "refresh", function( assert ) { + assert.expect( 5 ); var element = $( "#menu1" ).menu(); - equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); + assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); element.append( "<li><a href='#'>test item</a></li>" ).menu( "refresh" ); - equal( element.find( ".ui-menu-item" ).length, 6, "Incorrect number of menu items" ); + assert.equal( element.find( ".ui-menu-item" ).length, 6, "Incorrect number of menu items" ); element.find( ".ui-menu-item:last" ).remove().end().menu( "refresh" ); - equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); + assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); element.append( "<li>---</li>" ).menu( "refresh" ); - equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); + assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); element.children( ":last" ).remove().end().menu( "refresh" ); - equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); + assert.equal( element.find( ".ui-menu-item" ).length, 5, "Incorrect number of menu items" ); } ); -test( "refresh submenu", function() { - expect( 2 ); +QUnit.test( "refresh submenu", function( assert ) { + assert.expect( 2 ); var element = $( "#menu2" ).menu(); - equal( element.find( "ul:first .ui-menu-item" ).length, 3 ); + assert.equal( element.find( "ul:first .ui-menu-item" ).length, 3 ); element.find( "ul" ).addBack().append( "<li><a href=\"#\">New Item</a></li>" ); element.menu( "refresh" ); - equal( element.find( "ul:first .ui-menu-item" ).length, 4 ); + assert.equal( element.find( "ul:first .ui-menu-item" ).length, 4 ); } ); -test( "refresh icons (see #9377)", function( assert ) { - expect( 3 ); +QUnit.test( "refresh icons (see #9377)", function( assert ) { + assert.expect( 3 ); var element = $( "#menu1" ).menu(); assert.lacksClasses( element, "ui-menu-icons" ); element.find( "li:first .ui-menu-item-wrapper" ) @@ -81,12 +82,12 @@ test( "refresh icons (see #9377)", function( assert ) { assert.lacksClasses( element, "ui-menu-icons" ); } ); -test( "widget", function() { - expect( 2 ); +QUnit.test( "widget", function( assert ) { + assert.expect( 2 ); var element = $( "#menu1" ).menu(), widgetElement = element.menu( "widget" ); - equal( widgetElement.length, 1, "one element" ); - strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" ); + assert.equal( widgetElement.length, 1, "one element" ); + assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" ); } ); // TODO: test focus method diff --git a/tests/unit/menu/options.js b/tests/unit/menu/options.js index dd27ec5c2..8479b719c 100644 --- a/tests/unit/menu/options.js +++ b/tests/unit/menu/options.js @@ -1,21 +1,22 @@ define( [ + "qunit", "jquery", "./helper", "ui/widgets/menu" -], function( $, testHelper ) { +], function( QUnit, $, testHelper ) { var log = testHelper.log, logOutput = testHelper.logOutput, click = testHelper.click; -module( "menu: options", { - setup: function() { +QUnit.module( "menu: options", { + beforeEach: function() { testHelper.clearLog(); } } ); -test( "{ disabled: true }", function( assert ) { - expect( 2 ); +QUnit.test( "{ disabled: true }", function( assert ) { + assert.expect( 2 ); var element = $( "#menu1" ).menu( { disabled: true, select: function() { @@ -26,11 +27,11 @@ test( "{ disabled: true }", function( assert ) { log( "click", true ); click( element, "1" ); log( "afterclick" ); - equal( logOutput(), "click,afterclick", "Click order not valid." ); + assert.equal( logOutput(), "click,afterclick", "Click order not valid." ); } ); -test( "{ disabled: false }", function( assert ) { - expect( 2 ); +QUnit.test( "{ disabled: false }", function( assert ) { + assert.expect( 2 ); var element = $( "#menu1" ).menu( { disabled: false, select: function() { @@ -41,11 +42,11 @@ test( "{ disabled: false }", function( assert ) { log( "click", true ); click( element, "1" ); log( "afterclick" ); - equal( logOutput(), "click,1,afterclick", "Click order not valid." ); + assert.equal( logOutput(), "click,1,afterclick", "Click order not valid." ); } ); -test( "{ icons: default }", function( assert ) { - expect( 8 ); +QUnit.test( "{ icons: default }", function( assert ) { + assert.expect( 8 ); var element = $( "#menu2" ).menu(); element.find( ".ui-menu-icon" ).each( function() { assert.hasClasses( this, "ui-menu-icon ui-icon ui-icon-caret-1-e" ); @@ -57,8 +58,8 @@ test( "{ icons: default }", function( assert ) { } ); } ); -test( "{ icons: { submenu: 'custom' } }", function( assert ) { - expect( 4 ); +QUnit.test( "{ icons: { submenu: 'custom' } }", function( assert ) { + assert.expect( 4 ); var element = $( "#menu2" ).menu( { icons: { submenu: "custom-class" @@ -73,51 +74,51 @@ test( "{ icons: { submenu: 'custom' } }", function( assert ) { // TODO: test position option -test( "{ role: 'menu' } ", function( assert ) { +QUnit.test( "{ role: 'menu' } ", function( assert ) { var element = $( "#menu1" ).menu(), items = element.find( "li" ); - expect( 2 + 3 * items.length ); - equal( element.attr( "role" ), "menu" ); - ok( items.length > 0, "number of menu items" ); + assert.expect( 2 + 3 * items.length ); + assert.equal( element.attr( "role" ), "menu" ); + assert.ok( items.length > 0, "number of menu items" ); items.each( function( item ) { assert.hasClasses( $( this ), "ui-menu-item" ); - equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), + assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), "menuitem", "menu item (" + item + ") role" ); - equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1", + assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1", "tabindex for menu item (" + item + ")" ); } ); } ); -test( "{ role: 'listbox' } ", function( assert ) { +QUnit.test( "{ role: 'listbox' } ", function( assert ) { var element = $( "#menu1" ).menu( { role: "listbox" } ), items = element.find( "li" ); - expect( 2 + 3 * items.length ); - equal( element.attr( "role" ), "listbox" ); - ok( items.length > 0, "number of menu items" ); + assert.expect( 2 + 3 * items.length ); + assert.equal( element.attr( "role" ), "listbox" ); + assert.ok( items.length > 0, "number of menu items" ); items.each( function( item ) { assert.hasClasses( $( this ), "ui-menu-item" ); - equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), "option", + assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), "option", "menu item (" + item + ") role" ); - equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1", + assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1", "tabindex for menu item (" + item + ")" ); } ); } ); -test( "{ role: null }", function( assert ) { +QUnit.test( "{ role: null }", function( assert ) { var element = $( "#menu1" ).menu( { role: null } ), items = element.find( "li" ); - expect( 2 + 3 * items.length ); - equal( element.attr( "role" ), null ); - ok( items.length > 0, "number of menu items" ); + assert.expect( 2 + 3 * items.length ); + assert.equal( element.attr( "role" ), null ); + assert.ok( items.length > 0, "number of menu items" ); items.each( function( item ) { assert.hasClasses( $( this ), "ui-menu-item" ); - equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), null, + assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), null, "menu item (" + item + ") role" ); - equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1", + assert.equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1", "tabindex for menu item (" + item + ")" ); } ); } ); |