From 32efbc2b00a00ad368848dccc290739394d78992 Mon Sep 17 00:00:00 2001 From: Nicolas Coden Date: Thu, 18 Jan 2018 23:38:11 +0100 Subject: [PATCH] test: add unit tests for Abide.addA11yAttributes() --- test/javascript/components/abide.js | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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'); -- 2.47.2