|
| 1 | +module('Accessibility - Search'); |
| 2 | + |
| 3 | +var MultipleSelection = require('select2/selection/multiple'); |
| 4 | +var InlineSearch = require('select2/selection/search'); |
| 5 | + |
| 6 | +var $ = require('jquery'); |
| 7 | + |
| 8 | +var Utils = require('select2/utils'); |
| 9 | +var Options = require('select2/options'); |
| 10 | +var options = new Options({}); |
| 11 | + |
| 12 | +test('aria-autocomplete attribute is present', function (assert) { |
| 13 | + var $select = $('#qunit-fixture .multiple'); |
| 14 | + |
| 15 | + var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch); |
| 16 | + var selection = new CustomSelection($select, options); |
| 17 | + var $selection = selection.render(); |
| 18 | + |
| 19 | + // Update the selection so the search is rendered |
| 20 | + selection.update([]); |
| 21 | + |
| 22 | + assert.equal( |
| 23 | + $selection.find('input').attr('aria-autocomplete'), |
| 24 | + 'list', |
| 25 | + 'The search box is marked as autocomplete' |
| 26 | + ); |
| 27 | +}); |
| 28 | + |
| 29 | +test('aria-activedescendant should be removed when closed', function (assert) { |
| 30 | + var $select = $('#qunit-fixture .multiple'); |
| 31 | + |
| 32 | + var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch); |
| 33 | + var selection = new CustomSelection($select, options); |
| 34 | + var $selection = selection.render(); |
| 35 | + |
| 36 | + var container = new MockContainer(); |
| 37 | + selection.bind(container, $('<span></span>')); |
| 38 | + |
| 39 | + // Update the selection so the search is rendered |
| 40 | + selection.update([]); |
| 41 | + |
| 42 | + var $search = $selection.find('input'); |
| 43 | + $search.attr('aria-activedescendant', 'something'); |
| 44 | + |
| 45 | + container.trigger('close'); |
| 46 | + |
| 47 | + assert.ok( |
| 48 | + !$search.attr('aria-activedescendant'), |
| 49 | + 'There is no active descendant when the dropdown is closed' |
| 50 | + ); |
| 51 | +}); |
0 commit comments