'use strict'; describe('$aria', function() { var scope, $compile, element; beforeEach(module('ngAria')); function injectScopeAndCompiler() { return inject(function(_$compile_, _$rootScope_) { $compile = _$compile_; scope = _$rootScope_; }); } function compileInput(inputHtml) { element = $compile(inputHtml)(scope); scope.$digest(); } describe('aria-hidden', function() { beforeEach(injectScopeAndCompiler); it('should attach aria-hidden to ng-show', function() { compileInput('
'); scope.$apply('val = false'); expect(element.attr('aria-hidden')).toBe('true'); scope.$apply('val = true'); expect(element.attr('aria-hidden')).toBe('false'); }); it('should attach aria-hidden to ng-hide', function() { compileInput(''); scope.$apply('val = false'); expect(element.attr('aria-hidden')).toBe('false'); scope.$apply('val = true'); expect(element.attr('aria-hidden')).toBe('true'); }); it('should not change aria-hidden if it is already present on ng-show', function() { compileInput(''); expect(element.attr('aria-hidden')).toBe('userSetValue'); scope.$apply('val = true'); expect(element.attr('aria-hidden')).toBe('userSetValue'); }); it('should not change aria-hidden if it is already present on ng-hide', function() { compileInput(''); expect(element.attr('aria-hidden')).toBe('userSetValue'); scope.$apply('val = true'); expect(element.attr('aria-hidden')).toBe('userSetValue'); }); }); describe('aria-hidden when disabled', function() { beforeEach(configAriaProvider({ ariaHidden: false })); beforeEach(injectScopeAndCompiler); it('should not attach aria-hidden', function() { scope.$apply('val = false'); compileInput(''); expect(element.attr('aria-hidden')).toBeUndefined(); compileInput(''); expect(element.attr('aria-hidden')).toBeUndefined(); }); }); describe('aria-checked', function() { beforeEach(injectScopeAndCompiler); it('should attach itself to input type="checkbox"', function() { compileInput(''); scope.$apply('val = true'); expect(element.attr('aria-checked')).toBe('true'); scope.$apply('val = false'); expect(element.attr('aria-checked')).toBe('false'); }); it('should attach itself to input type="radio"', function() { var element = $compile('' + '')(scope); scope.$apply("val='one'"); expect(element.eq(0).attr('aria-checked')).toBe('true'); expect(element.eq(1).attr('aria-checked')).toBe('false'); scope.$apply("val='two'"); expect(element.eq(0).attr('aria-checked')).toBe('false'); expect(element.eq(1).attr('aria-checked')).toBe('true'); }); it('should attach itself to role="radio"', function() { scope.$apply("val = 'one'"); compileInput(''); expect(element.attr('aria-checked')).toBe('true'); }); it('should attach itself to role="checkbox"', function() { scope.val = true; compileInput(''); expect(element.attr('aria-checked')).toBe('true'); }); it('should attach itself to role="menuitemradio"', function() { scope.val = 'one'; compileInput(''); expect(element.attr('aria-checked')).toBe('true'); }); it('should attach itself to role="menuitemcheckbox"', function() { scope.val = true; compileInput(''); expect(element.attr('aria-checked')).toBe('true'); }); it('should not attach itself if an aria-checked value is already present', function() { var element = [ $compile("")(scope), $compile("")(scope), $compile("")(scope), $compile("")(scope), $compile("")(scope), $compile("")(scope) ]; scope.$apply("val1=true;val2='one';val3='1'"); expectAriaAttrOnEachElement(element, 'aria-checked', 'userSetValue'); }); }); describe('aria-checked when disabled', function() { beforeEach(configAriaProvider({ ariaChecked: false })); beforeEach(injectScopeAndCompiler); it('should not attach aria-checked', function() { compileInput(""); expect(element.attr('aria-checked')).toBeUndefined(); compileInput(""); expect(element.attr('aria-checked')).toBeUndefined(); compileInput(""); expect(element.attr('aria-checked')).toBeUndefined(); compileInput(""); expect(element.attr('aria-checked')).toBeUndefined(); }); }); describe('aria-disabled', function() { beforeEach(injectScopeAndCompiler); it('should attach itself to input elements', function() { scope.$apply('val = false'); compileInput(""); expect(element.attr('aria-disabled')).toBe('false'); scope.$apply('val = true'); expect(element.attr('aria-disabled')).toBe('true'); }); it('should attach itself to textarea elements', function() { scope.$apply('val = false'); compileInput(''); expect(element.attr('aria-disabled')).toBe('false'); scope.$apply('val = true'); expect(element.attr('aria-disabled')).toBe('true'); }); it('should attach itself to button elements', function() { scope.$apply('val = false'); compileInput(''); expect(element.attr('aria-disabled')).toBe('false'); scope.$apply('val = true'); expect(element.attr('aria-disabled')).toBe('true'); }); it('should attach itself to select elements', function() { scope.$apply('val = false'); compileInput(''); expect(element.attr('aria-disabled')).toBe('false'); scope.$apply('val = true'); expect(element.attr('aria-disabled')).toBe('true'); }); it('should not attach itself if an aria-disabled attribute is already present', function() { var element = [ $compile("")(scope), $compile("")(scope), $compile("")(scope), $compile("")(scope) ]; scope.$apply('val = true'); expectAriaAttrOnEachElement(element, 'aria-disabled', 'userSetValue'); }); }); describe('aria-disabled when disabled', function() { beforeEach(configAriaProvider({ ariaDisabled: false })); beforeEach(injectScopeAndCompiler); it('should not attach aria-disabled', function() { var element = [ $compile("")(scope), $compile("")(scope), $compile("")(scope), $compile("")(scope) ]; scope.$apply('val = false'); expectAriaAttrOnEachElement(element, 'aria-disabled', undefined); }); }); describe('aria-invalid', function() { beforeEach(injectScopeAndCompiler); it('should attach aria-invalid to input', function() { compileInput(''); scope.$apply("txtInput='LTten'"); expect(element.attr('aria-invalid')).toBe('true'); scope.$apply("txtInput='morethantencharacters'"); expect(element.attr('aria-invalid')).toBe('false'); }); it('should not attach itself if aria-invalid is already present', function() { compileInput(''); scope.$apply("txtInput='LTten'"); expect(element.attr('aria-invalid')).toBe('userSetValue'); }); }); describe('aria-invalid when disabled', function() { beforeEach(configAriaProvider({ ariaInvalid: false })); beforeEach(injectScopeAndCompiler); it('should not attach aria-invalid if the option is disabled', function() { scope.$apply("txtInput='LTten'"); compileInput(''); expect(element.attr('aria-invalid')).toBeUndefined(); }); }); describe('aria-required', function() { beforeEach(injectScopeAndCompiler); it('should attach aria-required to input', function() { compileInput(''); expect(element.attr('aria-required')).toBe('true'); scope.$apply("val='input is valid now'"); expect(element.attr('aria-required')).toBe('false'); }); it('should attach aria-required to textarea', function() { compileInput(''); expect(element.attr('aria-required')).toBe('true'); scope.$apply("val='input is valid now'"); expect(element.attr('aria-required')).toBe('false'); }); it('should attach aria-required to select', function() { compileInput(''); expect(element.attr('aria-required')).toBe('true'); scope.$apply("val='input is valid now'"); expect(element.attr('aria-required')).toBe('false'); }); it('should attach aria-required to ngRequired', function() { compileInput(''); expect(element.attr('aria-required')).toBe('true'); scope.$apply("val='input is valid now'"); expect(element.attr('aria-required')).toBe('false'); }); it('should not attach itself if aria-required is already present', function() { compileInput(""); expect(element.attr('aria-required')).toBe('userSetValue'); compileInput(""); expect(element.attr('aria-required')).toBe('userSetValue'); compileInput(""); expect(element.attr('aria-required')).toBe('userSetValue'); compileInput(""); expect(element.attr('aria-required')).toBe('userSetValue'); }); }); describe('aria-required when disabled', function() { beforeEach(configAriaProvider({ ariaRequired: false })); beforeEach(injectScopeAndCompiler); it('should not add the aria-required attribute', function() { compileInput(""); expect(element.attr('aria-required')).toBeUndefined(); compileInput(""); expect(element.attr('aria-required')).toBeUndefined(); compileInput(""); expect(element.attr('aria-required')).toBeUndefined(); }); }); describe('aria-multiline', function() { beforeEach(injectScopeAndCompiler); it('should attach itself to textarea', function() { compileInput(''); expect(element.attr('aria-multiline')).toBe('true'); }); it('should attach itself role="textbox"', function() { compileInput(''); expect(element.attr('aria-multiline')).toBe('true'); }); it('should not attach itself if aria-multiline is already present', function() { compileInput(''); expect(element.attr('aria-multiline')).toBe('userSetValue'); compileInput(''); expect(element.attr('aria-multiline')).toBe('userSetValue'); }); }); describe('aria-multiline when disabled', function() { beforeEach(configAriaProvider({ ariaMultiline: false })); beforeEach(injectScopeAndCompiler); it('should not attach itself to textarea', function() { compileInput(''); expect(element.attr('aria-multiline')).toBeUndefined(); }); it('should not attach itself role="textbox"', function() { compileInput(''); expect(element.attr('aria-multiline')).toBeUndefined(); }); }); describe('aria-value', function() { beforeEach(injectScopeAndCompiler); it('should attach to input type="range"', function() { var element = [ $compile('')(scope), $compile('