From b96516ef877bb10379ae47cf18fdb980cf2a3251 Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Mon, 17 Nov 2014 17:12:50 -0800 Subject: [PATCH] feat(mdAria): Checks child nodes for aria-label Closes #567 --- src/core/services/aria/aria.js | 25 +++++++++++++++++++--- src/core/services/aria/aria.spec.js | 33 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/core/services/aria/aria.spec.js diff --git a/src/core/services/aria/aria.js b/src/core/services/aria/aria.js index 40e96ae016c..6d4fc5a5ca0 100644 --- a/src/core/services/aria/aria.js +++ b/src/core/services/aria/aria.js @@ -13,14 +13,28 @@ function AriaService($$rAF, $log) { }; /** - * Check if expected attribute has been specified on the target element + * Check if expected attribute has been specified on the target element or child * @param element * @param attrName * @param {optional} defaultValue What to set the attr to if no value is found */ function expect(element, attrName, defaultValue) { - var node = element[0]; - if (!node.hasAttribute(attrName)) { + var node = element[0], + hasChildren = node.hasChildNodes(), + childHasAttribute = false; + + if(hasChildren) { + var children = node.childNodes; + for(var i=0; i')($rootScope); + + $mdAria.expect(button, 'aria-label'); + + expect($log.warn).toHaveBeenCalled(); + })); + + it('should not warn if child element has attribute', inject(function($compile, $rootScope, $log, $mdAria) { + spyOn($log, 'warn'); + var button = $compile('')($rootScope); + + $mdAria.expect(button, 'aria-label'); + + expect($log.warn).not.toHaveBeenCalled(); + })); + + xit('should warn if child with attribute is hidden', inject(function($compile, $rootScope, $log, $mdAria) { + spyOn($log, 'warn'); + var button = $compile('')($rootScope); + + $mdAria.expect(button, 'aria-label'); + + expect($log.warn).toHaveBeenCalled(); + })); + }); + +});