LogarithmicScaleSpec.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. *************************
  3. Logarithmic Scale Tests
  4. *************************
  5. */
  6. describe("Slider with logarithmic scale tests", function() {
  7. var testSlider;
  8. describe("Should properly position the slider", function() {
  9. function testSliderPosition(min, max, value){
  10. testSlider = $("#testSlider1").slider({
  11. min: min,
  12. max: max,
  13. scale: 'logarithmic',
  14. value: value // This should be at 50%
  15. });
  16. var expectedPostition = 210 / 2 + 'px';
  17. var handle = $("#testSlider1").prev('div.slider').find('.min-slider-handle');
  18. expect(handle.css('left')).toBe(expectedPostition);
  19. }
  20. it("with positive values", function() {
  21. testSliderPosition(1, 10000, 100);
  22. });
  23. it("with zero", function() {
  24. testSliderPosition(0, 63, 7);
  25. });
  26. it("with a negative value", function() {
  27. testSliderPosition(-7, 56, 0);
  28. });
  29. });
  30. it("Should properly position the tick marks", function() {
  31. testSlider = $("#testSlider1").slider({
  32. min: 1,
  33. max: 100,
  34. scale: 'logarithmic',
  35. ticks: [1,10,20,50,100]
  36. });
  37. // Position expected for the '10' tick
  38. var expectedTickOnePosition = 210 / 2 + 'px'; //should be at 50%
  39. var handle = $("#testSlider1").prev('div.slider').find(".slider-tick").eq(1);
  40. expect(handle.css('left')).toBe(expectedTickOnePosition);
  41. });
  42. it("Should use step size when navigating the keyboard", function() {
  43. testSlider = $("#testSlider1").slider({
  44. min: 1,
  45. max: 10000,
  46. scale: 'logarithmic',
  47. value: 100,
  48. step: 5
  49. });
  50. // Focus on handle1
  51. var handle1 = $("#testSlider1").prev('div.slider').find('.slider-handle');
  52. handle1.focus();
  53. // Create keyboard event
  54. var keyboardEvent = document.createEvent("Events");
  55. keyboardEvent.initEvent("keydown", true, true);
  56. var keyPresses = 0;
  57. handle1.on("keydown", function() {
  58. keyPresses++;
  59. var value = $("#testSlider1").slider('getValue');
  60. expect(value).toBe(100 + keyPresses*5);
  61. });
  62. keyboardEvent.keyCode = keyboardEvent.which = 39; // RIGHT
  63. for (var i = 0; i < 5; i++) {
  64. handle1[0].dispatchEvent(keyboardEvent);
  65. }
  66. });
  67. afterEach(function() {
  68. if(testSlider) {
  69. testSlider.slider('destroy');
  70. testSlider = null;
  71. }
  72. });
  73. });