~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to lib/jquery/jquery.ui-1.6rc2/tests/slider.js

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * slider unit tests
3
 
 */
4
 
(function($) {
5
 
 
6
 
var keyCodes = {
7
 
        leftArrow: 37,
8
 
        upArrow: 38,
9
 
        rightArrow: 39,
10
 
        downArrow: 40
11
 
};
12
 
 
13
 
$.each(keyCodes, function(key, val) {
14
 
        $.fn[key] = function() {
15
 
                return this.simulate("keydown", { keyCode: val });
16
 
        }
17
 
});
18
 
 
19
 
function assertChange(stepping, start, result, action) {
20
 
        return function() {
21
 
                expect(1);
22
 
                var slider = $("#slider3").slider({
23
 
                        stepping: stepping,
24
 
                        startValue: start,
25
 
                        min: 0,
26
 
                        max: 1000,
27
 
                        change: function(e, ui) {
28
 
                                equals(ui.value, result, "changed to " + ui.value);
29
 
                        }
30
 
                });
31
 
                action.apply(slider);
32
 
        }
33
 
}
34
 
 
35
 
module("slider: single handle")
36
 
 
37
 
test("change one step via keydown", assertChange(1, undefined, 1, function() {
38
 
        this.find("a").rightArrow();
39
 
}))
40
 
test("change - 10 steps via keydown", assertChange(10, 20, 10, function() {
41
 
        this.find("a").leftArrow();
42
 
}))
43
 
test("change +10 steps via keydown", assertChange(10, 20, 30, function() {
44
 
        this.find("a").rightArrow();
45
 
}))
46
 
 
47
 
test("moveTo, absolute value", assertChange(1, 1, 10, function() {
48
 
        this.slider("moveTo", 10);
49
 
}))
50
 
 
51
 
test("moveTo, absolute value as string", assertChange(1, 1, 10, function() {
52
 
        this.slider("moveTo", "10");
53
 
}))
54
 
 
55
 
test("moveTo, absolute value, below min", assertChange(1, 1, 0, function() {
56
 
        this.slider("moveTo", -10);
57
 
}))
58
 
 
59
 
test("moveTo, relative positive value", assertChange(1, 1, 11, function() {
60
 
        this.slider("moveTo", "+=10");
61
 
}))
62
 
 
63
 
test("moveTo, relative positive value, above max", assertChange(1, 10, 1000, function() {
64
 
        this.slider("moveTo", "+=2000");
65
 
}))
66
 
 
67
 
test("moveTo, relative negative value", assertChange(1, 20, 10, function() {
68
 
        this.slider("moveTo", "-=10");
69
 
}))
70
 
 
71
 
test("options update min/max", function() {
72
 
        expect(2);
73
 
        var slider = $("#slider3").slider({
74
 
                stepping: 1,
75
 
                startValue: 1
76
 
        });
77
 
        slider.slider("moveTo", "-=10");
78
 
        equals(slider.slider("value"), 0);
79
 
        slider.data("min.slider", -10);
80
 
        slider.slider("moveTo", "-=20");
81
 
        equals(slider.slider("value"), -10);
82
 
})
83
 
 
84
 
module("slider: setup and teardown");
85
 
 
86
 
test("destroy and recreate", function() {
87
 
        expect(3)
88
 
        var slider = $("#slider3").slider();
89
 
        slider.slider("moveTo", "+=20");
90
 
        equals(slider.slider("value"), 20);
91
 
        slider.slider("destroy");
92
 
        
93
 
        slider.slider("moveTo", "+=30");
94
 
        ok(true, "nothing happens after slider is destroyed");
95
 
        
96
 
        slider.slider().slider("moveTo", "30");
97
 
        
98
 
        equals(Math.round(slider.slider("value")), 30);
99
 
})
100
 
 
101
 
test("handle creation", function() {
102
 
        var slider = $("#slider1");
103
 
        equals(slider.children().size(), 0);
104
 
        slider.slider({
105
 
                handles: [
106
 
                        { start: 0 },
107
 
                        { start: 10 }
108
 
                ]
109
 
        });
110
 
        equals(slider.children().size(), 2);
111
 
        var instance = $.data(slider[0], "slider")
112
 
        equals(instance.handle.length, 2);
113
 
        ok(instance.handle.jquery, "handle must be a jquery object")
114
 
})
115
 
 
116
 
})(jQuery);