LowAndHighTrackSpec.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. **********************
  3. Left/Right Track Tests
  4. **********************
  5. This spec has tests for checking that the widths of the left and right
  6. segments are the correct widths and colors, based on their CSS.
  7. */
  8. describe("Low/High Track Tests", function() {
  9. var unstyledID = "low-high-slider";
  10. var styledID = "low-high-slider-styled";
  11. var testSlider;
  12. describe("Single-value sliders, no styling", function() {
  13. var id = unstyledID;
  14. beforeEach(function() {
  15. testSlider = $("#testSlider1").slider({
  16. id: id,
  17. min: 0,
  18. max: 10,
  19. value: 5
  20. });
  21. });
  22. it("low track width is zero", function()
  23. {
  24. var leftTrack = $("#" + id + " .slider-track-low");
  25. expect($(leftTrack).css("width")).toBe("0px");
  26. });
  27. it("high track width is 50%", function()
  28. {
  29. var rightTrack = $("#" + id + " .slider-track-high");
  30. var trackWidth = rightTrack.parent().width();
  31. expect($(rightTrack).css("width")).toBe((trackWidth / 2) + "px");
  32. });
  33. it("high track is transparent", function()
  34. {
  35. var rightTrack = $("#" + id + " .slider-track-high");
  36. var rightColor = rightTrack.css("background-color");
  37. var isTransparent = rightColor.match(/rgba\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}, 0\)/);
  38. expect(isTransparent).toBeTruthy();
  39. });
  40. afterEach(function() {
  41. if(testSlider) {
  42. testSlider.slider('destroy');
  43. testSlider = null;
  44. }
  45. });
  46. });
  47. describe("Single-value sliders, with styling", function() {
  48. var id = styledID;
  49. beforeEach(function() {
  50. testSlider = $("#testSlider1").slider({
  51. id: id,
  52. min: 0,
  53. max: 10,
  54. value: 5
  55. });
  56. });
  57. it("low track width is zero", function()
  58. {
  59. var leftTrack = $("#" + id + " .slider-track-low");
  60. expect($(leftTrack).css("width")).toBe("0px");
  61. });
  62. it("high track width is 50%", function()
  63. {
  64. var rightTrack = $("#" + id + " .slider-track-high");
  65. var trackWidth = rightTrack.parent().width();
  66. expect($(rightTrack).css("width")).toBe((trackWidth / 2) + "px");
  67. });
  68. it("high track is red", function()
  69. {
  70. var rightTrack = $("#" + id + " .slider-track-high");
  71. var rightColor = rightTrack.css("background-color");
  72. expect(rightColor).toBe("rgb(255, 0, 0)");
  73. });
  74. afterEach(function() {
  75. if(testSlider) {
  76. testSlider.slider('destroy');
  77. testSlider = null;
  78. }
  79. });
  80. });
  81. describe("Range sliders, no styling", function() {
  82. var id = unstyledID;
  83. var values = {
  84. min: 0,
  85. max: 10,
  86. values: [ 4, 6 ]
  87. };
  88. beforeEach(function() {
  89. testSlider = $("#testSlider1").slider({
  90. id: id,
  91. min: values.min,
  92. max: values.max,
  93. range: true,
  94. value: values.values
  95. });
  96. });
  97. it("low track width is correct", function()
  98. {
  99. var leftTrack = $("#" + id + " .slider-track-low");
  100. var trackWidth = leftTrack.parent().width();
  101. var expectedWidth = ((values.values[0] - values.min) / (values.max - values.min)) * trackWidth;
  102. expect($(leftTrack).css("width")).toBe(expectedWidth + "px");
  103. });
  104. it("high track width is correct", function()
  105. {
  106. var rightTrack = $("#" + id + " .slider-track-high");
  107. var trackWidth = rightTrack.parent().width();
  108. var expectedWidth = ((values.max - values.values[1]) / (values.max - values.min)) * trackWidth;
  109. expect($(rightTrack).css("width")).toBe(expectedWidth + "px");
  110. });
  111. it("low track is transparent", function()
  112. {
  113. var leftTrack = $("#" + id + " .slider-track-low");
  114. var leftColor = leftTrack.css("background-color");
  115. var isTransparent = leftColor.match(/rgba\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}, 0\)/);
  116. expect(isTransparent).toBeTruthy();
  117. });
  118. it("high track is transparent", function()
  119. {
  120. var rightTrack = $("#" + id + " .slider-track-high");
  121. var rightColor = rightTrack.css("background-color");
  122. var isTransparent = rightColor.match(/rgba\([0-9]{1,3}, [0-9]{1,3}, [0-9]{1,3}, 0\)/);
  123. expect(isTransparent).toBeTruthy();
  124. });
  125. afterEach(function() {
  126. if(testSlider) {
  127. testSlider.slider('destroy');
  128. testSlider = null;
  129. }
  130. });
  131. });
  132. describe("Range sliders, with styling", function() {
  133. var id = styledID;
  134. var values = {
  135. min: 0,
  136. max: 10,
  137. values: [ 4, 6 ]
  138. };
  139. beforeEach(function() {
  140. testSlider = $("#testSlider1").slider({
  141. id: id,
  142. min: values.min,
  143. max: values.max,
  144. range: true,
  145. value: values.values
  146. });
  147. });
  148. it("low track width is correct", function()
  149. {
  150. var leftTrack = $("#" + id + " .slider-track-low");
  151. var trackWidth = leftTrack.parent().width();
  152. var expectedWidth = ((values.values[0] - values.min) / (values.max - values.min)) * trackWidth;
  153. expect($(leftTrack).css("width")).toBe(expectedWidth + "px");
  154. });
  155. it("high track width is correct", function()
  156. {
  157. var rightTrack = $("#" + id + " .slider-track-high");
  158. var trackWidth = rightTrack.parent().width();
  159. var expectedWidth = ((values.max - values.values[1]) / (values.max - values.min)) * trackWidth;
  160. expect($(rightTrack).css("width")).toBe(expectedWidth + "px");
  161. });
  162. it("low track is green", function()
  163. {
  164. var leftTrack = $("#" + id + " .slider-track-low");
  165. var leftColor = leftTrack.css("background-color");
  166. expect(leftColor).toBe("rgb(0, 255, 0)");
  167. });
  168. it("high track is red", function()
  169. {
  170. var rightTrack = $("#" + id + " .slider-track-high");
  171. var rightColor = rightTrack.css("background-color");
  172. expect(rightColor).toBe("rgb(255, 0, 0)");
  173. });
  174. afterEach(function() {
  175. if(testSlider) {
  176. testSlider.slider('destroy');
  177. testSlider = null;
  178. }
  179. });
  180. });
  181. });