aboutsummaryrefslogtreecommitdiffstats
path: root/tests/slider.js
diff options
context:
space:
mode:
authorRichard Worth <rdworth@gmail.com>2008-06-07 17:35:27 +0000
committerRichard Worth <rdworth@gmail.com>2008-06-07 17:35:27 +0000
commit3524ef0c26f8760615c01217045c72f9bb20dde9 (patch)
treed7fa5208fb99d2f7d074706f1eed86a6a4b53acd /tests/slider.js
parent2ac4aa61e5167d9aa427b70fc5f1ad9b934fdf3c (diff)
downloadjquery-ui-3524ef0c26f8760615c01217045c72f9bb20dde9.tar.gz
jquery-ui-3524ef0c26f8760615c01217045c72f9bb20dde9.zip
removed extra level ui folder
Diffstat (limited to 'tests/slider.js')
-rw-r--r--tests/slider.js110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/slider.js b/tests/slider.js
new file mode 100644
index 000000000..7b6d095a5
--- /dev/null
+++ b/tests/slider.js
@@ -0,0 +1,110 @@
+
+var keyCodes = {
+ leftArrow: 37,
+ upArrow: 38,
+ rightArrow: 39,
+ downArrow: 40
+};
+
+$.each(keyCodes, function(key, val) {
+ $.fn[key] = function() {
+ return this.simulate("keydown", { keyCode: val });
+ }
+});
+
+function assertChange(stepping, start, result, action) {
+ return function() {
+ expect(1);
+ var slider = $("#slider3").slider({
+ stepping: stepping,
+ startValue: start,
+ min: 0,
+ max: 1000,
+ change: function(e, ui) {
+ equals(ui.value, result, "changed to " + ui.value);
+ }
+ });
+ action.apply(slider);
+ }
+}
+
+module("slider: single handle")
+
+test("change one step via keydown", assertChange(1, undefined, 1, function() {
+ this.find("a").rightArrow();
+}))
+test("change - 10 steps via keydown", assertChange(10, 20, 10, function() {
+ this.find("a").leftArrow();
+}))
+test("change +10 steps via keydown", assertChange(10, 20, 30, function() {
+ this.find("a").rightArrow();
+}))
+
+test("moveTo, absolute value", assertChange(1, 1, 10, function() {
+ this.slider("moveTo", 10);
+}))
+
+test("moveTo, absolute value as string", assertChange(1, 1, 10, function() {
+ this.slider("moveTo", "10");
+}))
+
+test("moveTo, absolute value, below min", assertChange(1, 1, 0, function() {
+ this.slider("moveTo", -10);
+}))
+
+test("moveTo, relative positive value", assertChange(1, 1, 11, function() {
+ this.slider("moveTo", "+=10");
+}))
+
+test("moveTo, relative positive value, above max", assertChange(1, 10, 1000, function() {
+ this.slider("moveTo", "+=2000");
+}))
+
+test("moveTo, relative negative value", assertChange(1, 20, 10, function() {
+ this.slider("moveTo", "-=10");
+}))
+
+test("options update min/max", function() {
+ expect(2);
+ var slider = $("#slider3").slider({
+ stepping: 1,
+ startValue: 1
+ });
+ slider.slider("moveTo", "-=10");
+ equals(slider.slider("value"), 0);
+ slider.data("min.slider", -10);
+ slider.slider("moveTo", "-=20");
+ equals(slider.slider("value"), -10);
+})
+
+module("slider: setup and teardown");
+
+test("destroy and recreate", function() {
+ expect(3)
+ var slider = $("#slider3").slider();
+ slider.slider("moveTo", "+=20");
+ equals(slider.slider("value"), 20);
+ slider.slider("destroy");
+
+ slider.slider("moveTo", "+=30");
+ ok(true, "nothing happens after slider is destroyed");
+
+ slider.slider().slider("moveTo", "30");
+
+ equals(Math.round(slider.slider("value")), 30);
+})
+
+test("handle creation", function() {
+ var slider = $("#slider1");
+ equals(slider.children().size(), 0);
+ slider.slider({
+ handles: [
+ { start: 0 },
+ { start: 10 }
+ ]
+ });
+ equals(slider.children().size(), 2);
+ var instance = $.data(slider[0], "slider")
+ equals(instance.handle.length, 2);
+ ok(instance.handle.jquery, "handle must be a jquery object")
+}) \ No newline at end of file