From 7e3d4fb697f20748b991859a32dcf5370fe1cbab Mon Sep 17 00:00:00 2001 From: Jono Mingard Date: Sun, 1 Nov 2015 20:39:45 +1300 Subject: [PATCH] Add tests for accessible search results --- tests/a11y/search-tests.js | 51 +++++++++++++++++++++++++++++++++++ tests/a11y/selection-tests.js | 25 ----------------- tests/unit.html | 1 + 3 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 tests/a11y/search-tests.js diff --git a/tests/a11y/search-tests.js b/tests/a11y/search-tests.js new file mode 100644 index 00000000..58e56492 --- /dev/null +++ b/tests/a11y/search-tests.js @@ -0,0 +1,51 @@ +module('Accessibility - Search'); + +var MultipleSelection = require('select2/selection/multiple'); +var InlineSearch = require('select2/selection/search'); + +var $ = require('jquery'); + +var Utils = require('select2/utils'); +var Options = require('select2/options'); +var options = new Options({}); + +test('aria-autocomplete attribute is present', function (assert) { + var $select = $('#qunit-fixture .multiple'); + + var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch); + var selection = new CustomSelection($select, options); + var $selection = selection.render(); + + // Update the selection so the search is rendered + selection.update([]); + + assert.equal( + $selection.find('input').attr('aria-autocomplete'), + 'list', + 'The search box is marked as autocomplete' + ); +}); + +test('aria-activedescendant should be removed when closed', function (assert) { + var $select = $('#qunit-fixture .multiple'); + + var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch); + var selection = new CustomSelection($select, options); + var $selection = selection.render(); + + var container = new MockContainer(); + selection.bind(container, $('')); + + // Update the selection so the search is rendered + selection.update([]); + + var $search = $selection.find('input'); + $search.attr('aria-activedescendant', 'something'); + + container.trigger('close'); + + assert.ok( + !$search.attr('aria-activedescendant'), + 'There is no active descendant when the dropdown is closed' + ); +}); diff --git a/tests/a11y/selection-tests.js b/tests/a11y/selection-tests.js index ef316cee..e2c14602 100644 --- a/tests/a11y/selection-tests.js +++ b/tests/a11y/selection-tests.js @@ -64,31 +64,6 @@ test('static aria attributes are present', function (assert) { 'true', 'The dropdown is considered a popup of the container' ); - - assert.equal( - $selection.attr('aria-autocomplete'), - 'list', - 'The results in the dropdown are the autocomplete list' - ); -}); - -test('aria-activedescendant should be removed when closed', function (assert) { - var $select = $('#qunit-fixture .single'); - - var selection = new BaseSelection($select, options); - var $selection = selection.render(); - - var container = new MockContainer(); - selection.bind(container, $('')); - - $selection.attr('aria-activedescendant', 'something'); - - container.trigger('close'); - - assert.ok( - !$selection.attr('aria-activedescendant'), - 'There is no active descendant when the dropdown is closed' - ); }); test('the container should be in the tab order', function (assert) { diff --git a/tests/unit.html b/tests/unit.html index 5b34b95c..c1f19c5e 100644 --- a/tests/unit.html +++ b/tests/unit.html @@ -55,6 +55,7 @@ +