Skip to content

Commit 7e3d4fb

Browse files
binary-koankevin-brown
authored andcommitted
Add tests for accessible search results
1 parent 9fae3d7 commit 7e3d4fb

3 files changed

Lines changed: 52 additions & 25 deletions

File tree

tests/a11y/search-tests.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
});

tests/a11y/selection-tests.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,6 @@ test('static aria attributes are present', function (assert) {
6464
'true',
6565
'The dropdown is considered a popup of the container'
6666
);
67-
68-
assert.equal(
69-
$selection.attr('aria-autocomplete'),
70-
'list',
71-
'The results in the dropdown are the autocomplete list'
72-
);
73-
});
74-
75-
test('aria-activedescendant should be removed when closed', function (assert) {
76-
var $select = $('#qunit-fixture .single');
77-
78-
var selection = new BaseSelection($select, options);
79-
var $selection = selection.render();
80-
81-
var container = new MockContainer();
82-
selection.bind(container, $('<span></span>'));
83-
84-
$selection.attr('aria-activedescendant', 'something');
85-
86-
container.trigger('close');
87-
88-
assert.ok(
89-
!$selection.attr('aria-activedescendant'),
90-
'There is no active descendant when the dropdown is closed'
91-
);
9267
});
9368

9469
test('the container should be in the tab order', function (assert) {

tests/unit.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<script src="helpers.js" type="text/javascript"></script>
5656

5757
<script src="a11y/selection-tests.js" type="text/javascript"></script>
58+
<script src="a11y/search-tests.js" type="text/javascript"></script>
5859

5960
<script src="data/array-tests.js" type="text/javascript"></script>
6061
<script src="data/base-tests.js" type="text/javascript"></script>

0 commit comments

Comments
 (0)