No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search-a11y-tests.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. module('Selection containers - Inline search - Accessibility');
  2. var MultipleSelection = require('select2/selection/multiple');
  3. var InlineSearch = require('select2/selection/search');
  4. var $ = require('jquery');
  5. var Utils = require('select2/utils');
  6. var Options = require('select2/options');
  7. var options = new Options({});
  8. test('role attribute is set to searchbox', function (assert) {
  9. var $select = $('#qunit-fixture .multiple');
  10. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  11. var selection = new CustomSelection($select, options);
  12. var $selection = selection.render();
  13. var container = new MockContainer();
  14. selection.bind(container, $('<span></span>'));
  15. // Update the selection so the search is rendered
  16. selection.update([]);
  17. assert.equal(
  18. $selection.find('input').attr('role'),
  19. 'searchbox',
  20. 'The search box is marked as a search box'
  21. );
  22. });
  23. test('aria-autocomplete attribute is present', function (assert) {
  24. var $select = $('#qunit-fixture .multiple');
  25. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  26. var selection = new CustomSelection($select, options);
  27. var $selection = selection.render();
  28. var container = new MockContainer();
  29. selection.bind(container, $('<span></span>'));
  30. // Update the selection so the search is rendered
  31. selection.update([]);
  32. assert.equal(
  33. $selection.find('input').attr('aria-autocomplete'),
  34. 'list',
  35. 'The search box is marked as autocomplete'
  36. );
  37. });
  38. test('aria-activedescendant should not be set initiailly', function (assert) {
  39. var $select = $('#qunit-fixture .multiple');
  40. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  41. var selection = new CustomSelection($select, options);
  42. var $selection = selection.render();
  43. var container = new MockContainer();
  44. selection.bind(container, $('<span></span>'));
  45. // Update the selection so the search is rendered
  46. selection.update([]);
  47. var $search = $selection.find('input');
  48. assert.ok(
  49. !$search.attr('aria-activedescendant'),
  50. 'The search box should not point to anything when it is first rendered'
  51. );
  52. });
  53. test('aria-activedescendant should be set after highlight', function (assert) {
  54. var $select = $('#qunit-fixture .multiple');
  55. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  56. var selection = new CustomSelection($select, options);
  57. var $selection = selection.render();
  58. var container = new MockContainer();
  59. selection.bind(container, $('<span></span>'));
  60. // Update the selection so the search is rendered
  61. selection.update([]);
  62. container.trigger('results:focus', {
  63. data: {
  64. _resultId: 'test'
  65. }
  66. });
  67. var $search = $selection.find('input');
  68. assert.equal(
  69. $search.attr('aria-activedescendant'),
  70. 'test',
  71. 'The search is pointing to the focused result'
  72. );
  73. });
  74. test('activedescendant should remove if there is no ID', function (assert) {
  75. var $select = $('#qunit-fixture .multiple');
  76. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  77. var selection = new CustomSelection($select, options);
  78. var $selection = selection.render();
  79. var container = new MockContainer();
  80. selection.bind(container, $('<span></span>'));
  81. // Update the selection so the search is rendered
  82. selection.update([]);
  83. var $search = $selection.find('input');
  84. $search.attr('aria-activedescendant', 'test');
  85. container.trigger('results:focus', {
  86. data: {}
  87. });
  88. assert.ok(
  89. !$search.attr('aria-activedescendant'),
  90. 'There is no result for the search to be pointing to'
  91. );
  92. });
  93. test('aria-activedescendant should be removed when closed', function (assert) {
  94. var $select = $('#qunit-fixture .multiple');
  95. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  96. var selection = new CustomSelection($select, options);
  97. var $selection = selection.render();
  98. var container = new MockContainer();
  99. selection.bind(container, $('<span></span>'));
  100. // Update the selection so the search is rendered
  101. selection.update([]);
  102. var $search = $selection.find('input');
  103. $search.attr('aria-activedescendant', 'something');
  104. container.trigger('close');
  105. assert.ok(
  106. !$search.attr('aria-activedescendant'),
  107. 'There is no active descendant when the dropdown is closed'
  108. );
  109. });
  110. test('aria-controls should not be set initiailly', function (assert) {
  111. var $select = $('#qunit-fixture .multiple');
  112. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  113. var selection = new CustomSelection($select, options);
  114. var $selection = selection.render();
  115. var container = new MockContainer();
  116. selection.bind(container, $('<span></span>'));
  117. // Update the selection so the search is rendered
  118. selection.update([]);
  119. var $search = $selection.find('input');
  120. assert.ok(
  121. !$search.attr('aria-controls'),
  122. 'The search box should not point to the results when it is first rendered'
  123. );
  124. });
  125. test('aria-controls should be set when opened', function (assert) {
  126. var $select = $('#qunit-fixture .multiple');
  127. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  128. var selection = new CustomSelection($select, options);
  129. var $selection = selection.render();
  130. var container = new MockContainer();
  131. selection.bind(container, $('<span></span>'));
  132. // Update the selection so the search is rendered
  133. selection.update([]);
  134. var $search = $selection.find('input');
  135. container.trigger('open');
  136. assert.ok(
  137. $search.attr('aria-controls'),
  138. 'The search should point to the results when it is opened'
  139. );
  140. });
  141. test('aria-controls should be removed when closed', function (assert) {
  142. var $select = $('#qunit-fixture .multiple');
  143. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  144. var selection = new CustomSelection($select, options);
  145. var $selection = selection.render();
  146. var container = new MockContainer();
  147. selection.bind(container, $('<span></span>'));
  148. // Update the selection so the search is rendered
  149. selection.update([]);
  150. var $search = $selection.find('input');
  151. $search.attr('aria-controls', 'something');
  152. container.trigger('close');
  153. assert.ok(
  154. !$search.attr('aria-controls'),
  155. 'There are no results for the search box to point to when it is closed'
  156. );
  157. });