Selectmenu: fixed unit tests, needs additional check and cleanup

This commit is contained in:
Felix Nagel 2012-01-12 22:04:43 +01:00
parent 3369ec340d
commit 70ba3b991e
2 changed files with 34 additions and 31 deletions

View File

@ -10,24 +10,21 @@ test("accessibility", function () {
var link = button.children("a");
var ul = menu.children("ul")
var links = ul.find("li.ui-menu-item a");
expect(12 + links.length * 2);
equals( button.attr("aria-disabled"), "false", "button aria-disabled" );
equals( link.attr("aria-disabled"), "false", "button link aria-disabled" );
equals( link.attr("aria-haspopup"), "true", "button link aria-haspopup" );
equals( link.attr("role"), "button", "button link role" );
equals( link.attr("aria-owns"), ul.attr("id"), "button link aria-owns" );
equals( link.attr("tabindex"), 0, "button link tabindex" );
expect(9 + links.length * 2);
equals( ul.attr("aria-hidden"), "true", "menu aria-hidden" );
equals( ul.attr("aria-disabled"), "false", "menu aria-disabled" );
equals( ul.attr("aria-labelledby"), link.attr("id"), "menu aria-labelledby" );
equals( ul.attr("role"), "menubox", "menu role" );
equals( ul.attr("tabindex"), 0, "menu tabindex" );
equals( ul.attr("aria-activedescendant"), links.eq(element[0].selectedIndex).attr("id"), "menu aria-activedescendant" );
equals( "true", link.attr("aria-haspopup"), "button link aria-haspopup" );
equals( "button", link.attr("role"), "button link role" );
equals( ul.attr("id"), link.attr("aria-owns"), "button link aria-owns" );
equals( 0, link.attr("tabindex"), "button link tabindex" );
equals( "true", ul.attr("aria-hidden"), "menu aria-hidden" );
equals( link.attr("id"), ul.attr("aria-labelledby"), "menu aria-labelledby" );
equals( "menubox", ul.attr("role"), "menu role" );
equals( 0, ul.attr("tabindex"), "menu tabindex" );
equals( links.eq(element[0].selectedIndex).attr("id"), ul.attr("aria-activedescendant"), "menu aria-activedescendant" );
$.each( links, function(index){
equals( $(this).attr("role"), "option", "menu link #" + index +" role" );
equals( $(this).attr("tabindex"), -1, "menu link #" + index +" tabindex" );
equals( "option", $(this).attr("role"), "menu link #" + index +" role" );
equals( -1, $(this).attr("tabindex"), "menu link #" + index +" tabindex" );
});
});
@ -43,24 +40,26 @@ $.each([
}
], function( i, settings ) {
test("state synchronization - " + settings.type, function () {
expect(6);
expect(5);
var element = $(settings.selector).selectmenu();
var widget = element.selectmenu("widget");
var button = widget.filter(".ui-selectmenu-button");
var menu = widget.filter(".ui-selectmenu-menu");
var link = button.find("a");
var selected = element.find("option:selected");
equals( element[0].value, element.selectmenu("option", "value"), "inital value" );
equals( element.find("option:selected").text(), button.text(), "inital button text" );
equals( button.text(), selected.text(), "inital button text" );
button.find("a").simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( element[0].value, element.selectmenu("option", "value"), "after keydown value" );
equals( element.find("option:selected").text(), button.text(), "after keydown button text" );
link.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( element.find("option:selected").val(), selected.next("option").val() , "after keydown original select state" );
equals( button.text(), selected.next("option").text(), "after keydown button text" );
button.find("a").simulate( "click" );
menu.find("a").last().simulate( "click" );
equals( element[0].value, element.selectmenu("option", "value"), "after click value" );
equals( element.find("option:selected").text(), button.text(), "after click button text" );
link.simulate( "click" );
menu.find("a").last().simulate( "mouseover" ).simulate( "click" );
equals( element.find("option:selected").val(), element.find("option").last().val(), "after click original select state" );
equals( button.text(), element.find("option").last().text(), "after click button text" );
});
});
})( jQuery );

View File

@ -21,11 +21,11 @@
var widget = this.element.selectmenu("widget"),
menu = widget.filter(".ui-selectmenu-menu"),
value = this.element.find("option").eq(0).text();
button = widget.filter(".ui-selectmenu-button"),
value = this.element.find("option").first().text();
menu.find(".ui-menu-item").eq(0).simulate("click");
equals(this.element.selectmenu("option", "value"), "Slower", "should be set to first option");
button.find("a").simulate( "click" );
menu.find("a").first().simulate( "mouseover" ).simulate( "click" );
});
test("close", function () {
@ -61,8 +61,10 @@
});
var widget = this.element.selectmenu("widget"),
button = widget.filter(".ui-selectmenu-button"),
menu = widget.filter(".ui-selectmenu-menu");
button.find("a").simulate( "click" );
menu.find(".ui-menu-item").simulate("mouseover");
});
@ -93,9 +95,11 @@
});
var widget = this.element.selectmenu("widget"),
button = widget.filter(".ui-selectmenu-button"),
menu = widget.filter(".ui-selectmenu-menu");
menu.find(".ui-menu-item").eq(0).simulate("click");
button.find("a").simulate( "click" );
menu.find("a").first().simulate( "mouseover" ).simulate("click");
});
})(jQuery);