AriaValueTextFormatterSpec.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. describe("Aria-valuetext Tests", function() {
  2. it("Sets the aria-valuetext to 'formatter' value", function() {
  3. var textValArrayA = new Array('Monday','Wednesday','Friday');
  4. var tooltipFormatterA = function(value) {
  5. var arrActiveValueA = value;
  6. return textValArrayA[arrActiveValueA-1];
  7. };
  8. //Formatter is used
  9. var testSliderA = $("#accessibilitySliderA").slider({
  10. formatter : tooltipFormatterA
  11. });
  12. testSliderA.slider('setValue', 2);
  13. var tooltipMessageA = $("#accessibilitySliderA").prev(".slider").children(".min-slider-handle").attr("aria-valuetext");
  14. var expectedMessageA = tooltipFormatterA(2);
  15. expect(tooltipMessageA).toBe(expectedMessageA);
  16. $("#accessibilitySliderA").slider('destroy');
  17. });
  18. it("Does not use aria-valuetext if 'formatter' is not used", function() {
  19. //Formatter is not used
  20. var testSliderB = $("#accessibilitySliderB").slider({});
  21. testSliderB.slider('setValue', 1);
  22. var ariaValueTextB = $("#accessibilitySliderB").prev(".slider").children(".min-slider-handle").attr("aria-valuetext");
  23. expect(ariaValueTextB).not.toBeDefined();
  24. $("#accessibilitySliderB").slider('destroy');
  25. });
  26. it("aria-valuetext if 'formatter' is used and has min & max value", function() {
  27. var textValArrayC = new Array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
  28. var tooltipFormatterC = function(value) {
  29. if(value[1]){
  30. var arrActiveValueC0 = value[0];
  31. var arrActiveValueC1 = value[1];
  32. return [ textValArrayC[arrActiveValueC0-1], textValArrayC[arrActiveValueC1-1] ];
  33. } else {
  34. var arrActiveValueC = value;
  35. return textValArrayC[arrActiveValueC-1];
  36. }
  37. };
  38. //Formatter is used for ranges
  39. var testSliderC = $("#accessibilitySliderC").slider({
  40. range: true,
  41. formatter : tooltipFormatterC
  42. });
  43. var valuesToSet = [2,4];
  44. testSliderC.slider('setValue', valuesToSet);
  45. var expectedMessageC = tooltipFormatterC([2,4]);
  46. var ttminMessage = $("#accessibilitySliderC").prev(".slider").children(".min-slider-handle").attr("aria-valuetext");
  47. var ttmaxMessage = $("#accessibilitySliderC").prev(".slider").children(".max-slider-handle").attr("aria-valuetext");
  48. expect(ttminMessage).toBe(expectedMessageC[0]);
  49. expect(ttmaxMessage).toBe(expectedMessageC[1]);
  50. $('#accessibilitySliderC').slider('destroy');
  51. });
  52. describe("Unset 'aria-valuetext' attribute when value can be represented as a number", function() {
  53. var $testSliderC;
  54. var dayOfWeek;
  55. var dayFormatter = function(value) {
  56. if (value[1]) {
  57. return [ dayOfWeek[value[0]-1], dayOfWeek[value[1]-1] ];
  58. }
  59. return dayOfWeek[value-1];
  60. };
  61. beforeEach(function() {
  62. dayOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
  63. $testSliderC = $('#accessibilitySliderC').slider({
  64. id: 'testAccessbilitySlider',
  65. min: 1,
  66. max: 7,
  67. formatter : dayFormatter
  68. });
  69. });
  70. afterEach(function() {
  71. if ($testSliderC) {
  72. $testSliderC.slider('destroy');
  73. }
  74. });
  75. it("Should unset 'aria-valuetext' attribute", function() {
  76. dayOfWeek[0] = '1';
  77. var valueToSet = 1;
  78. $testSliderC.slider('setValue', valueToSet);
  79. var ariaValueText = $('#testAccessbilitySlider').find('.min-slider-handle')[0].getAttribute('aria-valuetext');
  80. expect(ariaValueText).toBeNull();
  81. });
  82. it("Should unset 'aria-valuetext' attributes for range sliders", function() {
  83. dayOfWeek[0] = '1';
  84. dayOfWeek[6] = '7';
  85. $testSliderC.slider('setAttribute', 'range', true);
  86. $testSliderC.slider('refresh');
  87. var valuesToSet = [1, 7];
  88. $testSliderC.slider('setValue', valuesToSet);
  89. var ariaValueText1 = $('#testAccessbilitySlider').find('.min-slider-handle')[0].getAttribute('aria-valuetext');
  90. var ariaValueText2 = $('#testAccessbilitySlider').find('.max-slider-handle')[0].getAttribute('aria-valuetext');
  91. expect(ariaValueText1).toBeNull();
  92. expect(ariaValueText2).toBeNull();
  93. });
  94. });
  95. });