From 9afc75f2b1aa1aade7bc216e64f3a6101e1dca4e Mon Sep 17 00:00:00 2001 From: conzett Date: Tue, 22 Nov 2011 19:56:01 -0500 Subject: [PATCH] Add tests for aria-controls and aria-labeledby attribute generation --- javascripts/tabs.js | 28 ++++++++++++++-------------- javascripts/tests/tests.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/javascripts/tabs.js b/javascripts/tabs.js index ab3a692..1056053 100644 --- a/javascripts/tabs.js +++ b/javascripts/tabs.js @@ -41,12 +41,24 @@ $(this).attr('aria-selected', 'false'); } - // add IDs to tabs - if(!id){ $(this).attr('id', 'tab' + parseInt(index + 1)); } + $(this).attr('role', 'tab'); + + }); + + $(tabPanels).each(function(index) { + + var id = $(this).attr('id'); + + if(!id){ + $(this).attr('id', 'tabpanel' + parseInt(index + 1)); + } + + $(this).attr('role', 'tabpanel'); + }); // if there isn't already a selected tab, make the first one selected @@ -55,18 +67,6 @@ { $(tabs).first().attr('aria-selected', 'true'); } - - // add IDs to tab panels - - $(tabPanels).each(function(index) { - - var id = $(this).attr('id'); - - if(!id){ - $(this).attr('id', 'tabpanel' + parseInt(index + 1)); - } - - }); }; diff --git a/javascripts/tests/tests.js b/javascripts/tests/tests.js index 1821520..1c1d289 100644 --- a/javascripts/tests/tests.js +++ b/javascripts/tests/tests.js @@ -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); + }); + + }); + }); \ No newline at end of file