FocusOptionSpec.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. ******************
  3. Focus Option Tests
  4. ******************
  5. This spec has tests for checking proper behavior of the focus option.
  6. */
  7. describe("Focus Option Tests", function() {
  8. var testSlider;
  9. var simulateMousedown = function(target, pos) {
  10. var myEvent = document.createEvent("MouseEvents");
  11. myEvent.initEvent("mousedown", true, true);
  12. myEvent.pageX = pos;
  13. myEvent.pageY = pos;
  14. target.dispatchEvent(myEvent);
  15. };
  16. it("handle should not be focused after value change when 'focus' is false", function() {
  17. testSlider = $("#testSlider1").slider({
  18. min : 0,
  19. max : 10,
  20. value: 0,
  21. focus: false,
  22. id : "testSlider"
  23. });
  24. var hasFocus;
  25. $("#testSlider").find(".min-slider-handle").focus(function() {
  26. hasFocus = true;
  27. });
  28. simulateMousedown($("#testSlider").find(".slider-track-high").get(0), 1000);
  29. expect(hasFocus).toBe(undefined);
  30. });
  31. it("handle should be focused after value change when 'focus' is true", function() {
  32. testSlider = $("#testSlider1").slider({
  33. min : 0,
  34. max : 10,
  35. value: 0,
  36. focus: true,
  37. id : "testSlider"
  38. });
  39. var hasFocus;
  40. $("#testSlider").find(".min-slider-handle").focus(function() {
  41. hasFocus = true;
  42. });
  43. simulateMousedown($("#testSlider").find(".slider-track-high").get(0), 1000);
  44. expect(hasFocus).toBe(true);
  45. });
  46. afterEach(function() {
  47. if (testSlider) {
  48. testSlider.slider("destroy");
  49. testSlider = null;
  50. }
  51. });
  52. });