Add tests for tab and tabpanel role generation

This commit is contained in:
conzett 2011-11-22 19:42:52 -05:00
parent c8fc54fd77
commit 7779cb0506
2 changed files with 63 additions and 6 deletions

View File

@ -34,17 +34,18 @@
$(tabs).each(function(index) {
// if there is no aria selected role present, set it to false
var ariaSelected = $(this).attr('aria-selected');
var id = $(this).attr('id');
var selectedVar = $(this).attr('aria-selected');
if(!selectedVar){
if(!ariaSelected){
$(this).attr('aria-selected', 'false');
}
// add IDs to tabs
$(this).attr('id', 'tab' + index + 1);
if(!id){
$(this).attr('id', 'tab' + parseInt(index + 1));
}
});
@ -58,7 +59,13 @@
// add IDs to tab panels
$(tabPanels).each(function(index) {
$(this).attr('id', 'tabpanel' + index + 1);
var id = $(this).attr('id');
if(!id){
$(this).attr('id', 'tabpanel' + parseInt(index + 1));
}
});
};

View File

@ -78,4 +78,54 @@ $(document).ready(function () {
});
test("Tabs and tabpanel ID generation with IDs set by user", function () {
var tabContainer = $('#qunit-fixture #tab-container');
$(tabContainer).find("ul li:nth-child(2)").attr('id', 'something');
$(tabContainer).children().not('ul').first().attr('id', 'else');
var tabList = $(tabContainer).find('> ul');
var tabs = tabList.find('li');
var tabPanels = $(tabContainer).children().not('ul');
tabContainer.skeletonTabs();
equal($(tabList).find(':nth-child(2)').attr('id'),
'something',
'Expect 2nd tab id role to be "something"');
equal($(tabPanels).first().attr('id'),
'else',
'Expect 2nd tab id role to be "else"');
});
test("Tab role generation", function () {
var tabContainer = $('#qunit-fixture #tab-container');
var tabList = $(tabContainer).find('> ul');
var tabs = tabList.find('li');
tabContainer.skeletonTabs();
$(tabs).each(function(index) {
equals($(this).attr('role'),
'tab',
'Expect tab at position ' + index + ' to have an id');
});
});
test("Tabpanel role generation", function () {
var tabContainer = $('#qunit-fixture #tab-container');
var tabList = $(tabContainer).find('> ul');
var tabPanels = $(tabContainer).children().not('ul');
tabContainer.skeletonTabs();
$(tabPanels).each(function(index) {
equals($(this).attr('role'),
'tabpanel',
'Expect tab panel at position ' + index + ' to have an id');
});
});
});