Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
test(): Adding test coverage for $materialAria
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Oct 3, 2014
1 parent 7de0f05 commit 828cb4e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/components/checkbox/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ function MaterialCheckboxDirective(inputDirectives, $materialInkRipple, $materia
tAttrs.tabIndex = 0;
tElement.attr('role', tAttrs.type);

$materialAria.expect(tElement, 'aria-label');

return function postLink(scope, element, attr, ngModelCtrl) {
var checked = false;

Expand All @@ -90,6 +88,8 @@ function MaterialCheckboxDirective(inputDirectives, $materialInkRipple, $materia
$formatters: []
};

$materialAria.expect(element, 'aria-label');

// Reuse the original input[type=checkbox] directive from Angular core.
// This is a bit hacky as we need our own event listener and own render
// function.
Expand Down Expand Up @@ -120,7 +120,6 @@ function MaterialCheckboxDirective(inputDirectives, $materialInkRipple, $materia

function render() {
checked = ngModelCtrl.$viewValue;
// element.attr('aria-checked', checked);
if(checked) {
element.addClass(CHECKED_CSS);
} else {
Expand Down
22 changes: 22 additions & 0 deletions src/components/checkbox/checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ describe('materialCheckbox', function() {
beforeEach(module('ngAria'));
beforeEach(TestUtil.mockRaf);

it('should warn developers they need a label', inject(function($compile, $rootScope, $log){
spyOn($log, "warn");
var element = $compile('<div>' +
'<material-checkbox ng-model="blue">' +
'</material-checkbox>' +
'</div>')($rootScope);

var cbElements = element.find('material-checkbox');
expect($log.warn).toHaveBeenCalled();
}));

it('should copy text content to aria-label', inject(function($compile, $rootScope){
var element = $compile('<div>' +
'<material-checkbox ng-model="blue">' +
'Some text' +
'</material-checkbox>' +
'</div>')($rootScope);

var cbElements = element.find('material-checkbox');
expect(cbElements.eq(0).attr('aria-label')).toBe('Some text');
}));

it('should set checked css class and aria-checked attributes', inject(function($compile, $rootScope) {
var element = $compile('<div>' +
'<material-checkbox ng-model="blue">' +
Expand Down
22 changes: 21 additions & 1 deletion src/components/radioButton/radioButton.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('radioButton', function() {
expect(rbGroupElement.find('material-radio-button').eq(0).attr('role')).toEqual('radio');
}));

it('should set aria attributes', inject(function($compile, $rootScope) {
it('should set aria states', inject(function($compile, $rootScope) {
var element = $compile('<material-radio-group ng-model="color">' +
'<material-radio-button value="blue"></material-radio-button>' +
'<material-radio-button value="green"></material-radio-button>' +
Expand All @@ -51,6 +51,26 @@ describe('radioButton', function() {
expect(element.attr('aria-activedescendant')).not.toEqual(rbElements.eq(0).attr('id'));
}));

it('should warn developers they need a label', inject(function($compile, $rootScope, $log){
spyOn($log, "warn");
var element = $compile('<material-radio-group ng-model="color">' +
'<material-radio-button value="blue"></material-radio-button>' +
'<material-radio-button value="green"></material-radio-button>' +
'</material-radio-group>')($rootScope);

expect($log.warn).toHaveBeenCalled();
}));

it('should create an aria label from provided text', inject(function($compile, $rootScope) {
var element = $compile('<material-radio-group ng-model="color">' +
'<material-radio-button value="blue">Blue</material-radio-button>' +
'<material-radio-button value="green">Green</material-radio-button>' +
'</material-radio-group>')($rootScope);

var rbElements = element.find('material-radio-button');
expect(rbElements.eq(0).attr('aria-label')).toEqual('Blue');
}));

it('should be operable via arrow keys', inject(function($compile, $rootScope) {
var element = $compile('<material-radio-group ng-model="color">' +
'<material-radio-button value="blue"></material-radio-button>' +
Expand Down
11 changes: 11 additions & 0 deletions src/components/slider/slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('material-slider', function() {
};
}

// beforeEach(TestUtil.mockRaf);
beforeEach(module('ngAria'));
beforeEach(module('material.components.slider','material.decorators'));

it('should set model on press', inject(function($compile, $rootScope, $timeout) {
Expand Down Expand Up @@ -93,4 +95,13 @@ describe('material-slider', function() {
expect($rootScope.model).toBe(100);
}));

xit('should warn developers they need a label', inject(function($compile, $rootScope, $timeout, $log) {
spyOn($log, "warn");

var slider = $compile(
'<material-slider min="100" max="104" step="2" ng-model="model">'
)($rootScope);

expect($log.warn).toHaveBeenCalled();
}));
});
2 changes: 0 additions & 2 deletions src/services/aria/aria.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ function AriaService($$rAF, $log) {

if (hasDefault) {
defaultValue = String(defaultValue).trim();
// $log.warn(messageTemplate + ' ' + defaultValueTemplate,
// attrName, getTagString(node), attrName, defaultValue);
element.attr(attrName, defaultValue);
} else {
$log.warn(messageTemplate, attrName, getTagString(node));
Expand Down

0 comments on commit 828cb4e

Please sign in to comment.