Add tests for aria-controls and aria-labeledby attribute generation

This commit is contained in:
conzett 2011-11-22 19:56:01 -05:00
parent 7779cb0506
commit 9afc75f2b1
2 changed files with 46 additions and 14 deletions

View File

@ -41,23 +41,14 @@
$(this).attr('aria-selected', 'false'); $(this).attr('aria-selected', 'false');
} }
// add IDs to tabs
if(!id){ if(!id){
$(this).attr('id', 'tab' + parseInt(index + 1)); $(this).attr('id', 'tab' + parseInt(index + 1));
} }
$(this).attr('role', 'tab');
}); });
// if there isn't already a selected tab, make the first one selected
if($(tabList).find('[aria-selected="true"]').length == 0)
{
$(tabs).first().attr('aria-selected', 'true');
}
// add IDs to tab panels
$(tabPanels).each(function(index) { $(tabPanels).each(function(index) {
var id = $(this).attr('id'); var id = $(this).attr('id');
@ -66,8 +57,17 @@
$(this).attr('id', 'tabpanel' + parseInt(index + 1)); $(this).attr('id', 'tabpanel' + parseInt(index + 1));
} }
$(this).attr('role', 'tabpanel');
}); });
// if there isn't already a selected tab, make the first one selected
if($(tabList).find('[aria-selected="true"]').length == 0)
{
$(tabs).first().attr('aria-selected', 'true');
}
}; };
$.fn[pluginName] = function ( options ) { $.fn[pluginName] = function ( options ) {

View File

@ -128,4 +128,36 @@ $(document).ready(function () {
}); });
test("Aria-controls attribute generation", function () {
var tabContainer = $('#qunit-fixture #tab-container');
var tabList = $(tabContainer).find('> ul');
var tabPanels = $(tabContainer).children().not('ul');
var tabs = tabList.find('li');
tabContainer.skeletonTabs();
$(tabs).each(function(index) {
equals($(this).attr('aria-controls'),
$(tabPanels[index]).attr('id'),
'Expect tab at position ' + index + ' to match panel id at position ' + index);
});
});
test("Aria-labeledby attribute generation", function () {
var tabContainer = $('#qunit-fixture #tab-container');
var tabList = $(tabContainer).find('> ul');
var tabPanels = $(tabContainer).children().not('ul');
var tabs = tabList.find('li');
tabContainer.skeletonTabs();
$(tabPanels).each(function(index) {
equals($(this).attr('aria-labeledby'),
$(tabs[index]).attr('id'),
'Expect tab at position ' + index + ' to match panel id at position ' + index);
});
});
}); });