From: Nicolas Coden Date: Thu, 18 Jan 2018 22:38:11 +0000 (+0100) Subject: test: add unit tests for Abide.addA11yAttributes() X-Git-Tag: v6.6.0~3^2~311^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32efbc2b0;p=thirdparty%2Ffoundation%2Ffoundation-sites.git test: add unit tests for Abide.addA11yAttributes() --- diff --git a/test/javascript/components/abide.js b/test/javascript/components/abide.js index a429bc041..f57d92478 100644 --- a/test/javascript/components/abide.js +++ b/test/javascript/components/abide.js @@ -92,6 +92,41 @@ describe('Abide', function() { }); }); + describe('addA11yAttributes()', function () { + it('adds [aria-describedby] attribute to field and [for] attribute to form error', function() { + $html = $(` +
+ + +
+ `).appendTo('body'); + plugin = new Foundation.Abide($html, {}); + plugin.addA11yAttributes($html.find('input')); + + $html.find('input').should.have.attr('aria-describedby', 'test-error'); + $html.find('label.form-error').should.have.attr('for', 'test-input'); + }); + + it('adds attributes and ids when no id is set', function() { + $html = $(` +
+ + +
+ `).appendTo('body'); + plugin = new Foundation.Abide($html, {}); + plugin.addA11yAttributes($html.find('input')); + + const errorId = $html.find('.form-error').attr('id'); + $html.find('.form-error').should.have.attr('id').exist; + $html.find('input').should.have.attr('aria-describedby', errorId); + + const inputId = $html.find('input').attr('id'); + $html.find('input').should.have.attr('id').exist; + $html.find('.form-error').should.have.attr('for', inputId); + }); + }); + describe('removeErrorClasses()', function() { it('removes aria-invalid attribute from element', function() { $html = $('
').appendTo('body');