Skip to content
Permalink
Browse files

Menu: Use new has/lacksClasses assertions for all class checks

  • Loading branch information
arschmitz committed Jan 30, 2015
1 parent 53d1bc2 commit 144826d17548eb989f05330cc45d23cc9dbd5cc2
@@ -55,7 +55,7 @@ asyncTest( "#9044: Autofocus issue with dialog opened from menu widget", functio
});
});

asyncTest( "#9532: Need a way in Menu to keep ui-state-active class on selected item for Selectmenu", function() {
asyncTest( "#9532: Need a way in Menu to keep ui-state-active class on selected item for Selectmenu", function( assert ) {
expect( 1 );
var element = $( "#menu1" ).menu(),
firstChild = element.children().eq( 0 ),
@@ -64,7 +64,7 @@ asyncTest( "#9532: Need a way in Menu to keep ui-state-active class on selected
element.menu( "focus", null, firstChild );
wrapper.addClass( "ui-state-active" );
setTimeout( function() {
ok( wrapper.is( ".ui-state-active" ) );
assert.hasClasses( wrapper, "ui-state-active" );
start();
});
});
@@ -671,13 +671,13 @@ test( "#9469: Stopping propagation in a select event should not suppress subsequ
equal( logOutput(), "1,2", "Both select events were not triggered." );
});

asyncTest( "#10571: When typing in a menu, only menu-items should be focused", function() {
asyncTest( "#10571: When typing in a menu, only menu-items should be focused", function( assert ) {
expect( 3 );

var element = $( "#menu8" ).menu({
focus: function( event, ui ) {
equal( ui.item.length, 1, "There should only be one match when filtering" );
ok( ui.item.hasClass( "ui-menu-item" ), "element is .ui-menu-item" );
assert.hasClasses( ui.item, "ui-menu-item" );
equal( ui.item.text(), "-Saarland", "element has correct text" );
}
});
@@ -20,20 +20,20 @@ test( "destroy", function() {
});
});

test( "enable/disable", function() {
test( "enable/disable", function( assert ) {
expect( 3 );
var element = $( "#menu1" ).menu({
select: function() {
log();
}
});
element.menu( "disable" );
ok( element.is( ".ui-state-disabled" ), "Missing ui-state-disabled class" );
assert.hasClasses( element, "ui-state-disabled" );
log( "click", true );
click( element, "1" );
log( "afterclick" );
element.menu( "enable" );
ok( element.not( ".ui-state-disabled" ), "Has ui-state-disabled class" );
assert.lacksClasses( element, "ui-state-disabled" );
log( "click" );
click( element, "1" );
log( "afterclick" );
@@ -63,18 +63,18 @@ test( "refresh submenu", function() {
equal( element.find( "ul:first .ui-menu-item" ).length, 4 );
});

test( "refresh icons (see #9377)", function() {
test( "refresh icons (see #9377)", function( assert ) {
expect( 3 );
var element = $( "#menu1" ).menu();
ok( !element.hasClass( "ui-menu-icons") );
assert.lacksClasses( element, "ui-menu-icons" );
element.find( "li:first .ui-menu-item-wrapper" )
.html( "<span class='ui-icon ui-icon-disk'></span>Save</a>" );
element.menu( "refresh" );

ok( element.hasClass( "ui-menu-icons" ) );
assert.hasClasses( element, "ui-menu-icons" );
element.find( "li:first .ui-menu-item-wrapper" ).html( "Save" );
element.menu( "refresh" );
ok( !element.hasClass( "ui-menu-icons" ) );
assert.lacksClasses( element, "ui-menu-icons" );
});

test( "widget", function() {
@@ -10,75 +10,81 @@ module( "menu: options", {
}
});

test( "{ disabled: true }", function() {
test( "{ disabled: true }", function( assert ) {
expect( 2 );
var element = $( "#menu1" ).menu({
disabled: true,
select: function() {
log();
}
});
ok( element.hasClass( "ui-state-disabled" ), "Missing ui-state-disabled class" );
assert.hasClasses( element, "ui-state-disabled" );
log( "click", true );
click( element, "1" );
log( "afterclick" );
equal( logOutput(), "click,afterclick", "Click order not valid." );
});

test( "{ disabled: false }", function() {
test( "{ disabled: false }", function( assert ) {
expect( 2 );
var element = $( "#menu1" ).menu({
disabled: false,
select: function() {
log();
}
});
ok( !element.hasClass( "ui-state-disabled" ), "Has ui-state-disabled class" );
assert.lacksClasses( element, "ui-state-disabled" );
log( "click", true );
click( element, "1" );
log( "afterclick" );
equal( logOutput(), "click,1,afterclick", "Click order not valid." );
});

test( "{ icons: default }", function() {
expect( 2 );
test( "{ icons: default }", function( assert ) {
expect( 8 );
var element = $( "#menu2" ).menu();
equal( element.find( ".ui-menu-icon" ).attr( "class" ), "ui-menu-icon ui-icon ui-icon-caret-1-e" );
element.find( ".ui-menu-icon" ).each( function() {
assert.hasClasses( this, "ui-menu-icon ui-icon ui-icon-caret-1-e" );
});

element.menu( "option", "icons.submenu", "ui-icon-triangle-1-e" );
equal( element.find( ".ui-menu-icon" ).attr( "class" ), "ui-menu-icon ui-icon ui-icon-triangle-1-e" );
element.find( ".ui-menu-icon" ).each( function() {
assert.hasClasses( this, "ui-menu-icon ui-icon ui-icon-triangle-1-e" );
});
});

test( "{ icons: { submenu: 'custom' } }", function() {
expect( 1 );
test( "{ icons: { submenu: 'custom' } }", function( assert ) {
expect( 4 );
var element = $( "#menu2" ).menu({
icons: {
submenu: "custom-class"
}
});
equal( element.find( ".ui-menu-icon" ).attr( "class" ), "ui-menu-icon ui-icon custom-class" );
element.find( ".ui-menu-icon" ).each( function() {
assert.hasClasses( this, "ui-menu-icon ui-icon custom-class" );
});
});

// TODO: test menus option

// TODO: test position option

test( "{ role: 'menu' } ", function() {
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" );
items.each(function( item ) {
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
assert.hasClasses( $( this ), "ui-menu-item" );
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ),
"menuitem", "menu item ("+ item + ") role" );
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
"tabindex for menu item ("+ item + ")" );
});
});

test( "{ role: 'listbox' } ", function() {
test( "{ role: 'listbox' } ", function( assert ) {
var element = $( "#menu1" ).menu({
role: "listbox"
}),
@@ -87,15 +93,15 @@ test( "{ role: 'listbox' } ", function() {
equal( element.attr( "role" ), "listbox" );
ok( items.length > 0, "number of menu items" );
items.each(function( item ) {
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
assert.hasClasses( $( this ), "ui-menu-item" );
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), "option",
"menu item ("+ item + ") role" );
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",
"tabindex for menu item ("+ item + ")" );
});
});

test( "{ role: null }", function() {
test( "{ role: null }", function( assert ) {
var element = $( "#menu1" ).menu({
role: null
}),
@@ -104,7 +110,7 @@ test( "{ role: null }", function() {
strictEqual( element.attr( "role" ), undefined );
ok( items.length > 0, "number of menu items" );
items.each(function( item ) {
ok( $( this ).hasClass( "ui-menu-item" ), "menu item ("+ item + ") class for item" );
assert.hasClasses( $( this ), "ui-menu-item" );
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "role" ), undefined,
"menu item ("+ item + ") role" );
equal( $( this ).find( ".ui-menu-item-wrapper" ).attr( "tabindex" ), "-1",

0 comments on commit 144826d

Please sign in to comment.
You can’t perform that action at this time.