]>
git.proxmox.com Git - extjs.git/blob - extjs/classic/classic/test/specs/slider/Thumb.js
1 describe("Ext.slider.Thumb", function() {
2 var slider
, thumb
, createSlider
, createThumb
;
4 beforeEach(function() {
5 createSlider = function(config
) {
6 slider
= new Ext
.slider
.Multi(Ext
.apply({
7 renderTo
: Ext
.getBody(),
11 hideEmptyLabel
: false,
17 createThumb = function(config
) {
18 thumb
= new Ext
.slider
.Thumb(config
);
22 afterEach(function() {
34 describe("component initialization", function() {
35 describe("if slider is vertical", function() {
36 beforeEach(function() {
44 specFor(Ext
.slider
.Thumb
.Vertical
, function(key
, value
) {
45 it("should override " + key
+ " method", function() {
46 expect(thumb
[key
]).toBe(value
);
52 describe("thumb slide", function() {
53 describe("horizontal", function() {
54 var thumb0
, thumb60
, thumb90
,
55 setupSlider = function(config
) {
56 createSlider(Ext
.apply({
60 thumb0
= slider
.thumbs
[0];
61 thumb60
= slider
.thumbs
[1];
62 thumb90
= slider
.thumbs
[2];
64 spyOn(slider
, "fireEvent").andCallThrough();
67 describe("mouse events", function() {
68 describe("on slider mousedown", function() {
69 describe("on thumb", function() {
70 describe("no drag (mousedown/mouseup)", function() {
71 beforeEach(function() {
73 var xy
= thumb0
.el
.getXY();
74 jasmine
.fireMouseEvent(thumb0
.el
, 'mousedown', xy
[0], xy
[1]);
75 jasmine
.fireMouseEvent(thumb0
.el
, 'mouseup', xy
[0], xy
[1]);
78 it("should not change the thumb value", function() {
79 expect(thumb0
.value
).toEqual(0);
85 dragConfig
["drag without snapping"] = {
90 dragConfig
["drag with snapping"] = {
97 specFor(dragConfig
, function(key
, value
) {
98 describe(key
, function() {
99 beforeEach(function() {
100 setupSlider(value
.config
);
101 var xy
= thumb0
.el
.getXY(),
102 innerEl
= slider
.innerEl
,
103 trackLength
= innerEl
.getWidth(),
104 // Work out the exact correct mousemove offset based difference between cur value and expected value
105 xOffset
= trackLength
* (slider
.calculateThumbPosition(value
.expected
- slider
.getValue(0)) / 100);
107 // Mousedown on edge of thumb
108 jasmine
.fireMouseEvent(thumb0
.el
, 'mousedown', xy
[0], xy
[1]);
110 jasmine
.fireMouseEvent(thumb0
.el
, 'mousemove', xy
[0], xy
[1]);
111 jasmine
.fireMouseEvent(thumb0
.el
, 'mouseup', xy
[0], xy
[1]);
114 it("should change the thumb value", function() {
115 expect(thumb0
.value
).toEqual(value
.expected
);
118 describe("z-index", function() {
119 it("should increase z-index of dragged thumb", function() {
120 expect(thumb0
.el
.dom
.style
.zIndex
).toBeGreaterThan(0);
123 it("should remove z-index of non-dragged thumb", function() {
124 // z-indices will work down from the top one which is at 10000
125 expect(thumb60
.el
.dom
.style
.zIndex
== 9000).toBe(true);
126 expect(thumb90
.el
.dom
.style
.zIndex
== 8000).toBe(true);
133 describe("outside thumbs", function() {
134 beforeEach(function() {
138 describe("if slider enabled", function() {
139 beforeEach(function() {
140 var xy
= slider
.innerEl
.getXY();
141 jasmine
.fireMouseEvent(slider
.el
, 'click', xy
[0] + 100, xy
[1] + 10);
144 it("should change the thumb value", function() {
145 expect(thumb60
.value
).toEqual(50);
149 describe("if slider disabled", function() {
150 beforeEach(function() {
152 var xy
= slider
.innerEl
.getXY();
153 jasmine
.fireMouseEvent(slider
.el
, 'mousedown', xy
[0] + 10, xy
[1] + 10);
156 it("should not change the thumb value", function() {
157 expect(thumb0
.value
).toEqual(0);
165 describe("vertical", function() {
166 var thumb0
, thumb60
, thumb90
,
167 setupSlider = function(config
) {
168 createSlider(Ext
.apply({
174 thumb0
= slider
.thumbs
[0];
175 thumb60
= slider
.thumbs
[1];
176 thumb90
= slider
.thumbs
[2];
178 spyOn(slider
, "fireEvent").andCallThrough();
181 describe("mouse events", function() {
182 describe("on slider mousedown", function() {
183 describe("on thumb", function() {
186 dragConfig
["drag without snapping"] = {
191 dragConfig
["drag with snapping"] = {
198 specFor(dragConfig
, function(key
, value
) {
199 describe(key
, function() {
200 beforeEach(function() {
201 setupSlider(value
.config
);
202 var xy
= thumb0
.el
.getXY(),
203 innerEl
= slider
.innerEl
,
204 trackLength
= innerEl
.getHeight(),
205 // Work out the exact correct mousemove offset based on new value.
206 yOffset
= trackLength
* (slider
.calculateThumbPosition(slider
.getValue(0) - value
.expected
) / 100);
208 // Mousedown on edge of thumb
209 jasmine
.fireMouseEvent(thumb0
.el
, 'mousedown', xy
[0], xy
[1]);
211 jasmine
.fireMouseEvent(thumb0
.el
, 'mousemove', xy
[0], xy
[1]);
212 jasmine
.fireMouseEvent(thumb0
.el
, 'mouseup', xy
[0], xy
[1]);
215 it("should change the thumb value", function() {
216 expect(thumb0
.value
).toEqual(value
.expected
);
219 describe("z-index", function() {
220 it("should increase z-index of dragged thumb", function() {
221 expect(thumb0
.el
.dom
.style
.zIndex
).toBeGreaterThan(0);
224 it("should remove z-index of non-dragged thumb", function() {
225 // z-indices will work down from the top one which is at 10000
226 expect(thumb60
.el
.dom
.style
.zIndex
== 9000).toBe(true);
227 expect(thumb90
.el
.dom
.style
.zIndex
== 8000).toBe(true);
233 describe("outside thumbs", function() {
234 beforeEach(function() {
238 describe("if slider enabled", function() {
239 beforeEach(function() {
240 var xy
= slider
.innerEl
.getXY(),
241 offset
= Math
.floor(slider
.innerEl
.getHeight() / 2);
243 jasmine
.fireMouseEvent(slider
.el
, 'click', xy
[0] + 8, xy
[1] + offset
);
247 it("should change the thumb value", function() {
248 expect(thumb60
.value
).toEqual(50);
252 describe("if slider disabled", function() {
253 beforeEach(function() {
255 var xy
= slider
.innerEl
.getXY();
256 jasmine
.fireMouseEvent(slider
.el
, 'mousedown', xy
[0] + 10, xy
[1] - 10);
259 it("should not change the thumb value", function() {
260 expect(thumb0
.value
).toEqual(0);