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.

option-tests.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. module('Results - option');
  2. var $ = require('jquery');
  3. var Options = require('select2/options');
  4. var Results = require('select2/results');
  5. test('disabled property on option is respected - enabled', function (assert) {
  6. var results = new Results($('<select></select>'), new Options({}));
  7. var $option = $('<option></option>');
  8. var option = results.option({
  9. element: $option[0]
  10. });
  11. assert.notEqual(option.getAttribute('aria-disabled'), 'true');
  12. });
  13. test('disabled property on option is respected - disabled', function (assert) {
  14. var results = new Results($('<select></select>'), new Options({}));
  15. var $option = $('<option disabled></option>');
  16. var option = results.option({
  17. element: $option[0]
  18. });
  19. assert.equal(option.getAttribute('aria-disabled'), 'true');
  20. });
  21. test('disabled property on enabled optgroup is respected', function (assert) {
  22. var results = new Results($('<select></select>'), new Options({}));
  23. var $option = $('<optgroup></optgroup>');
  24. var option = results.option({
  25. element: $option[0]
  26. });
  27. assert.notEqual(option.getAttribute('aria-disabled'), 'true');
  28. });
  29. test('disabled property on disabled optgroup is respected', function (assert) {
  30. var results = new Results($('<select></select>'), new Options({}));
  31. var $option = $('<optgroup disabled></optgroup>');
  32. var option = results.option({
  33. element: $option[0]
  34. });
  35. assert.equal(option.getAttribute('aria-disabled'), 'true');
  36. });
  37. test('option in disabled optgroup is disabled', function (assert) {
  38. var results = new Results($('<select></select>'), new Options({}));
  39. var $option = $('<optgroup disabled><option></option></optgroup>')
  40. .find('option');
  41. var option = results.option({
  42. element: $option[0]
  43. });
  44. assert.equal(option.getAttribute('aria-disabled'), 'true');
  45. });
  46. test('options are not selected by default', function (assert) {
  47. var results = new Results($('<select></select>'), new Options({}));
  48. var $option = $('<option></option>');
  49. var option = results.option({
  50. id: 'test',
  51. element: $option[0]
  52. });
  53. assert.equal(option.getAttribute('aria-selected'), 'false');
  54. });
  55. test('options with children are given the group role', function(assert) {
  56. var results = new Results($('<select></select>'), new Options({}));
  57. var $option = $('<optgroup></optgroup>');
  58. var option = results.option({
  59. children: [{
  60. id: 'test'
  61. }],
  62. element: $option[0]
  63. });
  64. assert.equal(option.getAttribute('role'), 'group');
  65. });
  66. test('options with children have the aria-label set', function (assert) {
  67. var results = new Results($('<select></select>'), new Options({}));
  68. var $option = $('<optgroup></optgroup>');
  69. var option = results.option({
  70. children: [{
  71. id: 'test'
  72. }],
  73. element: $option[0],
  74. text: 'test'
  75. });
  76. assert.equal(option.getAttribute('aria-label'), 'test');
  77. });
  78. test('non-group options are given the option role', function (assert) {
  79. var results = new Results($('<select></select>'), new Options({}));
  80. var $option = $('<option></option>');
  81. var option = results.option({
  82. id: 'test',
  83. element: $option[0]
  84. });
  85. assert.equal(option.getAttribute('role'), 'option');
  86. });