search-tests.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module('Accessibility - Search');
  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('aria-autocomplete attribute is present', 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. // Update the selection so the search is rendered
  14. selection.update([]);
  15. assert.equal(
  16. $selection.find('input').attr('aria-autocomplete'),
  17. 'list',
  18. 'The search box is marked as autocomplete'
  19. );
  20. });
  21. test('aria-activedescendant should be removed when closed', function (assert) {
  22. var $select = $('#qunit-fixture .multiple');
  23. var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);
  24. var selection = new CustomSelection($select, options);
  25. var $selection = selection.render();
  26. var container = new MockContainer();
  27. selection.bind(container, $('<span></span>'));
  28. // Update the selection so the search is rendered
  29. selection.update([]);
  30. var $search = $selection.find('input');
  31. $search.attr('aria-activedescendant', 'something');
  32. container.trigger('close');
  33. assert.ok(
  34. !$search.attr('aria-activedescendant'),
  35. 'There is no active descendant when the dropdown is closed'
  36. );
  37. });