RefreshMethodSpec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. describe("refresh() Method Tests", function() {
  2. var testSlider;
  3. var $testSlider;
  4. var options;
  5. var initialValue, initialRangeValue;
  6. var newValue, newRangeValue;
  7. beforeEach(function() {
  8. initialValue = 5;
  9. initialRangeValue = [4, 5];
  10. newValue = 7;
  11. newRangeValue = [7, 10];
  12. options = {
  13. id: 'mySlider',
  14. min: 0,
  15. max: 10,
  16. step: 1,
  17. value: initialValue
  18. };
  19. });
  20. afterEach(function() {
  21. if(testSlider) {
  22. testSlider.destroy();
  23. testSlider = null;
  24. }
  25. if ($testSlider) {
  26. $testSlider.slider('destroy');
  27. $testSlider = null;
  28. }
  29. });
  30. it("does not convert a non-range slider into a range slider when invoked", function() {
  31. // Initialize non-range slider
  32. testSlider = new Slider("#testSlider1", {
  33. min: 0,
  34. max: 10,
  35. value: 5
  36. });
  37. // Assert that slider is non-range slider
  38. var initialValue = testSlider.getValue();
  39. var sliderIsRangeValue = initialValue instanceof Array;
  40. expect(sliderIsRangeValue).toBeFalsy();
  41. // Invoke refresh() method
  42. testSlider.refresh();
  43. // Assert that slider remains a non-range slider
  44. var afterRefreshValue = testSlider.getValue();
  45. sliderIsRangeValue = afterRefreshValue instanceof Array;
  46. expect(sliderIsRangeValue).toBeFalsy();
  47. });
  48. it("should reset slider to its default value on refresh", function() {
  49. // Initialize non-range slider
  50. testSlider = new Slider('#testSlider1', options);
  51. testSlider.setValue(newValue, true, true);
  52. testSlider.refresh();
  53. expect(testSlider.getValue()).toBe(initialValue);
  54. });
  55. it("should maintain its current value on refresh", function() {
  56. // Initialize non-range slider
  57. testSlider = new Slider('#testSlider1', options);
  58. testSlider.setValue(newValue, true, true);
  59. testSlider.refresh({ useCurrentValue: true });
  60. expect(testSlider.getValue()).toBe(newValue);
  61. });
  62. it("should reset slider to its default value on refresh (jQuery)", function() {
  63. // Initialize non-range slider
  64. $testSlider = $('#testSlider1').slider(options);
  65. $testSlider.slider('setValue', newValue, true, true);
  66. $testSlider.slider('refresh');
  67. expect($testSlider.slider('getValue')).toBe(initialValue);
  68. });
  69. it("should maintain its current value on refresh (jQuery)", function() {
  70. // Initialize non-range slider
  71. $testSlider = $('#testSlider1').slider(options);
  72. $testSlider.slider('setValue', newValue, true, true);
  73. $testSlider.slider('refresh', { useCurrentValue: true });
  74. expect($testSlider.slider('getValue')).toBe(newValue);
  75. });
  76. it("should reset slider to its default value on refresh (range)", function() {
  77. // Initialize range slider
  78. options.value = initialRangeValue;
  79. options.range = true;
  80. testSlider = new Slider('#testSlider1', options);
  81. testSlider.setValue(newRangeValue, true, true);
  82. testSlider.refresh();
  83. expect(testSlider.getValue()).toBe(initialRangeValue);
  84. });
  85. it("should maintain its current value on refresh (range)", function() {
  86. // Initialize range slider
  87. options.value = initialRangeValue;
  88. options.range = true;
  89. testSlider = new Slider('#testSlider1', options);
  90. testSlider.setValue(newRangeValue, true, true);
  91. testSlider.refresh({ useCurrentValue: true });
  92. expect(testSlider.getValue()).toBe(newRangeValue);
  93. });
  94. }); // End of spec