PublicMethodsSpec.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. describe("Public Method Tests", function() {
  2. var testSlider;
  3. describe("slider constructor", function() {
  4. describe("returns a jQuery object if it is called on a jQuery object with zero or more matching elements", function() {
  5. it("returns a jQuery object if it is called on with no matching elements", function() {
  6. testSlider = $();
  7. expect(testSlider.slider() instanceof jQuery).toBe(true);
  8. });
  9. it("returns a jQuery object if it is called on with one matching element", function() {
  10. testSlider = $('#testSlider1');
  11. expect(testSlider.slider() instanceof jQuery).toBe(true);
  12. });
  13. it("returns a jQuery object if it is called on with multiple matching elements", function() {
  14. testSlider = $('#testSlider1, #testSlider2');
  15. expect(testSlider.slider() instanceof jQuery).toBe(true);
  16. });
  17. });
  18. it("reads and sets the 'id' attribute of the slider instance that is created", function() {
  19. var sliderId = "mySlider";
  20. testSlider = $("#testSlider1").slider({
  21. id : sliderId
  22. });
  23. var sliderInstanceHasExpectedId = $("#testSlider1").siblings("div.slider").is("#" + sliderId);
  24. expect(sliderInstanceHasExpectedId).toBeTruthy();
  25. });
  26. it("generates multiple slider instances from selector", function() {
  27. $(".makeSlider").slider();
  28. var sliderInstancesExists = $(".makeSlider").siblings().is(".slider");
  29. expect(sliderInstancesExists).toBeTruthy();
  30. var sliderInstancesCount = $(".makeSlider").siblings(".slider").length;
  31. expect(sliderInstancesCount).toEqual(2);
  32. $('.makeSlider').slider('destroy');
  33. });
  34. it("reads and sets the 'min' option properly", function() {
  35. var minVal = -5;
  36. testSlider = $("#testSlider1").slider({
  37. min : minVal
  38. });
  39. testSlider.slider('setValue', minVal);
  40. var sliderValue = testSlider.slider('getValue');
  41. expect(sliderValue).toBe(minVal);
  42. });
  43. it("reads and sets the 'max' option properly", function() {
  44. var maxVal = 15;
  45. testSlider = $("#testSlider1").slider({
  46. max : maxVal
  47. });
  48. testSlider.slider('setValue', maxVal);
  49. var sliderValue = testSlider.slider('getValue');
  50. expect(sliderValue).toBe(maxVal);
  51. });
  52. it("reads and sets the 'precision' option properly", function() {
  53. testSlider = $("#testSlider1").slider({
  54. precision: 2
  55. });
  56. testSlider.slider('setValue', 8.115);
  57. var sliderValue = testSlider.slider('getValue');
  58. expect(sliderValue).toBe(8.12);
  59. });
  60. it("reads and sets the 'orientation' option properly", function() {
  61. var orientationVal = "vertical";
  62. testSlider = $("#testSlider1").slider({
  63. orientation : orientationVal
  64. });
  65. var orientationClassApplied = $("#testSlider1").siblings("div.slider").hasClass("slider-vertical");
  66. expect(orientationClassApplied).toBeTruthy();
  67. });
  68. it("reads and sets the 'value' option properly", function() {
  69. var val = 8;
  70. testSlider = $("#testSlider1").slider({
  71. value : val
  72. });
  73. testSlider.slider('setValue', val);
  74. var sliderValue = testSlider.slider('getValue');
  75. expect(sliderValue).toBe(val);
  76. });
  77. it("reads and sets the 'selection' option properly", function() {
  78. var selectionVal = "after",
  79. maxSliderVal = 10;
  80. testSlider = $("#testSlider1").slider({
  81. selection : selectionVal
  82. });
  83. testSlider.slider('setValue', maxSliderVal);
  84. var sliderSelectionWidthAtMaxValue = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-selection").width();
  85. expect(sliderSelectionWidthAtMaxValue).toBe(0);
  86. });
  87. it("updates the 'selection' option properly", function() {
  88. var selectionVal = "none",
  89. maxSliderVal = 10;
  90. testSlider = $("#testSlider1").slider({
  91. selection : selectionVal
  92. });
  93. testSlider.slider('setValue', maxSliderVal);
  94. testSlider.slider('refresh');
  95. var sliderSelectionHasHideClass_A = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-track-low").hasClass('hide');
  96. expect(sliderSelectionHasHideClass_A).toBe(true);
  97. var sliderSelectionHasHideClass_B = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-selection").hasClass('hide');
  98. expect(sliderSelectionHasHideClass_B).toBe(true);
  99. var sliderSelectionHasHideClass_C = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-track-high").hasClass('hide');
  100. expect(sliderSelectionHasHideClass_C).toBe(true);
  101. var newSelectionVal = 'after';
  102. testSlider.slider('setAttribute', 'selection', newSelectionVal);
  103. testSlider.slider('refresh');
  104. var sliderSelectionHasHideClass_D = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-track-low").hasClass('hide');
  105. expect(sliderSelectionHasHideClass_D).toBe(false);
  106. var sliderSelectionHasHideClass_E = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-selection").hasClass('hide');
  107. expect(sliderSelectionHasHideClass_E).toBe(false);
  108. var sliderSelectionHasHideClass_F = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-track-high").hasClass('hide');
  109. expect(sliderSelectionHasHideClass_F).toBe(false);
  110. });
  111. it("reads and sets the 'handle' option properly", function() {
  112. var handleVal = "triangle";
  113. testSlider = $("#testSlider1").slider({
  114. handle : handleVal
  115. });
  116. var handleIsSetToTriangle = $("#testSlider1").siblings(".slider").children("div.slider-handle").hasClass("triangle");
  117. expect(handleIsSetToTriangle).toBeTruthy();
  118. });
  119. it("reads and sets the 'reversed' option properly", function() {
  120. var reversedVal = true,
  121. maxSliderVal = 10;
  122. testSlider = $("#testSlider1").slider({
  123. reversed : reversedVal
  124. });
  125. testSlider.slider('setValue', maxSliderVal);
  126. var sliderSelectionHeightAtMaxValue = $("#testSlider1").siblings(".slider").children("div.slider-track").children("div.slider-selection").width();
  127. expect(sliderSelectionHeightAtMaxValue).toBe(0);
  128. });
  129. it("reads and sets the 'formatter' option properly", function() {
  130. var tooltipFormatter = function(value) {
  131. return 'Current value: ' + value;
  132. };
  133. testSlider = $("#testSlider1").slider({
  134. formatter : tooltipFormatter
  135. });
  136. testSlider.slider('setValue', 9);
  137. var tooltipMessage = $("#testSlider1").siblings(".slider").find("div.tooltip").children("div.tooltip-inner").text();
  138. var expectedMessage = tooltipFormatter(9);
  139. expect(tooltipMessage).toBe(expectedMessage);
  140. });
  141. it("reads and sets the 'enabled' option properly", function() {
  142. testSlider = $("#testSlider1").slider({
  143. enabled: false
  144. });
  145. var isEnabled = testSlider.slider('isEnabled');
  146. expect(isEnabled).not.toBeTruthy();
  147. });
  148. describe("reads and sets the 'tooltip' option properly", function() {
  149. it("tooltip is not shown if set to 'hide'", function() {
  150. testSlider = $("#testSlider1").slider({
  151. tooltip : "hide"
  152. });
  153. var tooltipIsHidden = testSlider.siblings(".slider").children("div.tooltip").hasClass("hide");
  154. expect(tooltipIsHidden).toBeTruthy();
  155. });
  156. it("tooltip is shown during sliding if set to 'show'", function() {
  157. testSlider = $("#testSlider1").slider({
  158. tooltip : "show"
  159. });
  160. var tooltipIsHidden = !($("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in"));
  161. expect(tooltipIsHidden).toBeTruthy();
  162. // Trigger hover
  163. var mouseenterEvent = document.createEvent("Events");
  164. mouseenterEvent.initEvent("mouseenter", true, true);
  165. testSlider.data('slider').sliderElem.dispatchEvent(mouseenterEvent);
  166. var tooltipIsShownAfterSlide = $("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in");
  167. expect(tooltipIsShownAfterSlide).toBeTruthy();
  168. });
  169. it("tooltip is shown on mouse over and hides correctly after mouse leave", function() {
  170. testSlider = $("#testSlider1").slider({
  171. tooltip : "show"
  172. });
  173. var tooltipIsHidden = !($("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in"));
  174. expect(tooltipIsHidden).toBeTruthy();
  175. // Trigger hover
  176. var mouseenterEvent = document.createEvent("Events");
  177. mouseenterEvent.initEvent("mouseenter", true, true);
  178. testSlider.data('slider').sliderElem.dispatchEvent(mouseenterEvent);
  179. var tooltipIsShownAfterSlide = $("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in");
  180. expect(tooltipIsShownAfterSlide).toBeTruthy();
  181. // Trigger leave
  182. var mouseleaveEvent = document.createEvent("Events");
  183. mouseleaveEvent.initEvent("mouseleave", true, true);
  184. testSlider.data('slider').sliderElem.dispatchEvent(mouseleaveEvent);
  185. var tooltipIsAgainHidden = !($("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in"));
  186. expect(tooltipIsAgainHidden).toBeTruthy();
  187. });
  188. it("tooltip is always shown if set to 'always'", function() {
  189. testSlider = $("#testSlider1").slider({
  190. tooltip : "always"
  191. });
  192. var tooltipIsShown = $("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in");
  193. expect(tooltipIsShown).toBeTruthy();
  194. });
  195. it("defaults to 'show' option if invalid value is passed", function() {
  196. testSlider = $("#testSlider1").slider({
  197. tooltip : "invalid option value"
  198. });
  199. var tooltipIsHidden = !($("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in"));
  200. expect(tooltipIsHidden).toBeTruthy();
  201. // Trigger hover
  202. var mouseenterEvent = document.createEvent("Events");
  203. mouseenterEvent.initEvent("mouseenter", true, true);
  204. testSlider.data('slider').sliderElem.dispatchEvent(mouseenterEvent);
  205. var tooltipIsShownOnHover = $("#testSlider1").siblings(".slider").children("div.tooltip").hasClass("in");
  206. expect(tooltipIsShownOnHover).toBeTruthy();
  207. });
  208. });
  209. });
  210. describe("'setValue()' tests", function() {
  211. var formatInvalidInputMsg = function(invalidValue) { return "Invalid input value '" + invalidValue + "' passed in"; };
  212. describe("if slider is a single value slider", function() {
  213. beforeEach(function() {
  214. testSlider = $("#testSlider1").slider();
  215. });
  216. it("properly sets the value of the slider when given a numeric value", function() {
  217. var valueToSet = 5;
  218. testSlider.slider('setValue', valueToSet);
  219. var sliderValue = testSlider.slider('getValue');
  220. expect(sliderValue).toBe(valueToSet);
  221. });
  222. it("properly sets the value of the slider when given a string value", function(){
  223. var valueToSet = "5";
  224. testSlider.slider('setValue', valueToSet);
  225. var sliderValue = testSlider.slider('getValue');
  226. expect(sliderValue).toBe(5);
  227. });
  228. it("if a value passed in is greater than the max (10), the slider only goes to the max", function() {
  229. var maxValue = 10,
  230. higherThanSliderMaxVal = maxValue + 5;
  231. testSlider.slider('setValue', higherThanSliderMaxVal);
  232. var sliderValue = testSlider.slider('getValue');
  233. expect(sliderValue).toBe(maxValue);
  234. });
  235. it("if a value passed in is less than the min (0), the slider only goes to the min", function() {
  236. var minValue = 0,
  237. lowerThanSliderMaxVal = minValue - 5;
  238. testSlider.slider('setValue', lowerThanSliderMaxVal);
  239. var sliderValue = testSlider.slider('getValue');
  240. expect(sliderValue).toBe(minValue);
  241. });
  242. it("sets the 'value' property of the slider <input> element", function() {
  243. var value = 9;
  244. testSlider.slider('setValue', value);
  245. var currentValue = document.querySelector("#testSlider1").value;
  246. currentValue = parseFloat(currentValue);
  247. expect(currentValue).toBe(value);
  248. });
  249. it("sets the 'value' attribute of the slider <input> element", function() {
  250. var value = 9;
  251. testSlider.slider('setValue', value);
  252. var currentValue = document.querySelector("#testSlider1").getAttribute("value");
  253. currentValue = parseFloat(currentValue);
  254. expect(currentValue).toBe(value);
  255. });
  256. describe("when an invalid value type is passed in", function() {
  257. var invalidValue;
  258. beforeEach(function() {
  259. invalidValue = "a";
  260. });
  261. it("throws an error and does not alter the slider value", function() {
  262. var originalSliderValue = testSlider.slider('getValue');
  263. var settingValue = function() {
  264. testSlider.slider('setValue', invalidValue);
  265. };
  266. expect(settingValue).toThrow(new Error( formatInvalidInputMsg(invalidValue) ));
  267. var sliderValue = testSlider.slider('getValue');
  268. expect(sliderValue).toBe(originalSliderValue);
  269. });
  270. });
  271. });
  272. describe("if slider is a range slider", function() {
  273. beforeEach(function() {
  274. testSlider = $("#testSlider1").slider({
  275. value : [3, 8]
  276. });
  277. });
  278. it("properly sets the values if both within the max and min", function() {
  279. var valuesToSet = [5, 7];
  280. testSlider.slider('setValue', valuesToSet);
  281. var sliderValues = testSlider.slider('getValue');
  282. expect(sliderValues[0]).toBe(valuesToSet[0]);
  283. expect(sliderValues[1]).toBe(valuesToSet[1]);
  284. });
  285. describe("caps values to the min if they are set to be less than the min", function() {
  286. var minValue = -5,
  287. otherValue = 7;
  288. it("first value is capped to min", function() {
  289. testSlider.slider('setValue', [minValue, otherValue]);
  290. var sliderValues = testSlider.slider('getValue');
  291. expect(sliderValues[0]).toBe(0);
  292. });
  293. it("second value is capped to min", function() {
  294. testSlider.slider('setValue', [otherValue, minValue]);
  295. var sliderValues = testSlider.slider('getValue');
  296. expect(sliderValues[1]).toBe(0);
  297. });
  298. });
  299. describe("caps values to the max if they are set to be higher than the max", function() {
  300. var maxValue = 15,
  301. otherValue = 7;
  302. it("first value is capped to max", function() {
  303. testSlider.slider('setValue', [maxValue, otherValue]);
  304. var sliderValues = testSlider.slider('getValue');
  305. expect(sliderValues[0]).toBe(10);
  306. });
  307. it("second value is capped to max", function() {
  308. testSlider.slider('setValue', [otherValue, maxValue]);
  309. var sliderValues = testSlider.slider('getValue');
  310. expect(sliderValues[1]).toBe(10);
  311. });
  312. });
  313. describe("if either value is of invalid type", function() {
  314. var invalidValue = "a",
  315. otherValue = 7;
  316. it("first value is of invalid type", function() {
  317. var setSliderValueFn = function() {
  318. testSlider.slider('setValue', [invalidValue, otherValue]);
  319. };
  320. expect(setSliderValueFn).toThrow(new Error( formatInvalidInputMsg(invalidValue) ));
  321. });
  322. it("second value is of invalid type", function() {
  323. var setSliderValueFn = function() {
  324. testSlider.slider('setValue', [otherValue, invalidValue]);
  325. };
  326. expect(setSliderValueFn).toThrow(new Error( formatInvalidInputMsg(invalidValue) ));
  327. });
  328. });
  329. });
  330. describe("triggerSlideEvent argument", function() {
  331. it("if triggerSlideEvent argument is true, the 'slide' event is triggered", function() {
  332. var testSlider = $("#testSlider1").slider({
  333. value : 3
  334. });
  335. var newSliderVal = 5;
  336. testSlider.on('slide', function(evt) {
  337. expect(newSliderVal).toEqual(evt.value);
  338. });
  339. testSlider.slider('setValue', newSliderVal, true);
  340. });
  341. it("if triggerSlideEvent argument is false, the 'slide' event is not triggered", function() {
  342. var newSliderVal = 5;
  343. var slideEventTriggered = false;
  344. var testSlider = $("#testSlider1").slider({
  345. value : 3
  346. });
  347. testSlider.on('slide', function() {
  348. slideEventTriggered = true;
  349. });
  350. testSlider.slider('setValue', newSliderVal, false);
  351. expect(slideEventTriggered).toEqual(false);
  352. });
  353. });
  354. describe("triggerChangeEvent argument", function() {
  355. it("if triggerChangeEvent argument is true, the 'change' event is triggered", function() {
  356. var testSlider = $("#testSlider1").slider({
  357. value : 3
  358. });
  359. var newSliderVal = 5;
  360. testSlider.on('change', function(evt) {
  361. expect(newSliderVal).toEqual(evt.value.newValue);
  362. });
  363. testSlider.slider('setValue', newSliderVal, true);
  364. });
  365. it("if triggerChangeEvent argument is false, the 'change' event is not triggered", function() {
  366. var changeEventTriggered = false;
  367. var testSlider = $("#testSlider1").slider({
  368. value : 3
  369. });
  370. testSlider.on('change', function() {
  371. changeEventTriggered = true;
  372. });
  373. testSlider.slider('setValue', 5, false);
  374. expect(changeEventTriggered).toEqual(false);
  375. });
  376. });
  377. });
  378. describe("'getValue()' tests", function() {
  379. it("returns the current value of the slider", function() {
  380. testSlider = $("#testSlider1").slider();
  381. var valueToSet = 5;
  382. testSlider.slider('setValue', valueToSet);
  383. var sliderValue = testSlider.slider('getValue');
  384. expect(sliderValue).toBe(valueToSet);
  385. });
  386. });
  387. describe("'enable()' tests", function() {
  388. it("correctly enables a slider", function() {
  389. testSlider = $("#testSlider1").slider({
  390. enabled: false
  391. });
  392. testSlider.slider("enable");
  393. var isEnabled = testSlider.slider("isEnabled");
  394. expect(isEnabled).toBeTruthy();
  395. });
  396. });
  397. describe("'disable()' tests", function() {
  398. it("correctly disable a slider", function() {
  399. testSlider = $("#testSlider1").slider();
  400. testSlider.slider("disable");
  401. var isEnabled = testSlider.slider("isEnabled");
  402. expect(isEnabled).not.toBeTruthy();
  403. });
  404. });
  405. describe("'toggle()' tests", function() {
  406. it("correctly enables a disabled slider", function() {
  407. testSlider = $("#testSlider1").slider({
  408. enabled: false
  409. });
  410. testSlider.slider("toggle");
  411. var isEnabled = testSlider.slider("isEnabled");
  412. expect(isEnabled).toBeTruthy();
  413. });
  414. it("correctly disables an enabled slider", function() {
  415. testSlider = $("#testSlider1").slider();
  416. testSlider.slider("toggle");
  417. var isEnabled = testSlider.slider("isEnabled");
  418. expect(isEnabled).not.toBeTruthy();
  419. });
  420. });
  421. describe("'isEnabled()' tests", function() {
  422. it("returns true for an enabled slider", function() {
  423. testSlider = $("#testSlider1").slider({
  424. id: "enabled",
  425. enabled: true
  426. });
  427. var isEnabled = testSlider.slider("isEnabled");
  428. var $slider = testSlider.siblings("#enabled");
  429. var hasDisabledClass = $slider.hasClass("slider") && $slider.hasClass("#enabled");
  430. expect(isEnabled).toBeTruthy();
  431. expect(hasDisabledClass).not.toBeTruthy();
  432. });
  433. it("returns false for a disabled slider", function() {
  434. testSlider = $("#testSlider1").slider({
  435. id: "disabled",
  436. enabled: false
  437. });
  438. var isEnabled = testSlider.slider("isEnabled");
  439. var $slider = testSlider.siblings("#disabled");
  440. var hasDisabledClass = $slider.hasClass("slider") && $slider.hasClass("slider-disabled");
  441. expect(isEnabled).not.toBeTruthy();
  442. expect(hasDisabledClass).toBeTruthy();
  443. });
  444. });
  445. it("get attribute", function() {
  446. testSlider = $("#testSlider1").slider();
  447. var sliderMaxValue = testSlider.slider('getAttribute', 'max');
  448. expect(sliderMaxValue).toBe(10);
  449. });
  450. it("changes slider from basic to range", function() {
  451. testSlider = $("#makeRangeSlider").slider();
  452. testSlider.slider('setAttribute', 'range', true).slider('refresh');
  453. var isRangeSlider = $("#changeOrientationSlider").parent("div.slider").find('.slider-handle').last().hasClass('hide');
  454. expect(isRangeSlider).toBeFalsy();
  455. });
  456. it("setAttribute: changes the 'data-slider-orientation' property from horizontal to vertical", function() {
  457. testSlider = $("#changeOrientationSlider").slider({
  458. id: "changeOrientationSliderElem"
  459. });
  460. testSlider.slider('setAttribute', 'orientation', 'vertical').slider('refresh');
  461. var $slider = $("#changeOrientationSliderElem");
  462. var orientationClassApplied = $slider.hasClass("slider-vertical");
  463. expect(orientationClassApplied).toBeTruthy();
  464. });
  465. it("relayout: if slider is not displayed on initialization and then displayed later on, relayout() will not adjust the margin-left of the tooltip", function() {
  466. // Setup
  467. testSlider = new Slider("#relayoutSliderInput", {
  468. id: "relayoutSlider",
  469. min: 0,
  470. max: 10,
  471. value: 5
  472. });
  473. var mainTooltipDOMRef = document.querySelector("#relayoutSlider .tooltip-main");
  474. var relayoutSliderContainerDOMRef = document.querySelector("#relayoutSliderContainer");
  475. var tooltipMarginLeft;
  476. // Main tooltip margin-left offset should not be set on slider intialization
  477. tooltipMarginLeft = parseFloat(mainTooltipDOMRef.style.marginLeft);
  478. expect(tooltipMarginLeft).toBeNaN();
  479. // Show slider and call relayout()
  480. relayoutSliderContainerDOMRef.style.display = "block";
  481. testSlider.relayout();
  482. // Main tooltip margin-left offset should not be set after relayout() is called.
  483. tooltipMarginLeft = Math.abs( parseFloat(mainTooltipDOMRef.style.marginLeft) );
  484. expect(tooltipMarginLeft).toBeNaN();
  485. });
  486. it("relayout: if slider is not displayed on initialization and then displayed later on, relayout() will re-adjust the tick label width", function() {
  487. // Setup
  488. testSlider = new Slider("#relayoutSliderInputTickLabels", {
  489. id: "relayoutSliderTickLabels",
  490. min: 0,
  491. max: 10,
  492. ticks: [0, 5, 10],
  493. ticks_labels: ['low', 'mid', 'high'],
  494. value: 5
  495. });
  496. var $ticks = $('#relayoutSliderTickLabels').find('.slider-tick-label');
  497. // Tick-Width should be 0 on slider intialization
  498. var i, $tick;
  499. for (i = 0; i < $ticks.length; i++) {
  500. $tick = $($ticks[i]);
  501. expect( parseInt($tick.css('width')) ).toBe(0);
  502. }
  503. // Show slider and call relayout()
  504. $('#relayoutSliderContainerTickLabels').css('display', 'block');
  505. testSlider.relayout();
  506. $('#relayoutSliderContainerTickLabels').css('display', 'none');
  507. // Tick-Width should re-adjust to be > 0
  508. for (i = 0; i < $ticks.length; i++) {
  509. $tick = $($ticks[i]);
  510. expect( parseInt($tick.css('width')) ).toBeGreaterThan(0);
  511. }
  512. });
  513. afterEach(function() {
  514. if(testSlider) {
  515. if(testSlider instanceof jQuery) { testSlider.slider('destroy'); }
  516. if(testSlider instanceof Slider) { testSlider.destroy(); }
  517. testSlider = null;
  518. }
  519. });
  520. });