Skip to content

Commit

Permalink
slider unit tests: created separate file for each module: core, commo…
Browse files Browse the repository at this point in the history
…n widget, events, methods, options, tickets
  • Loading branch information
rdworth committed Feb 2, 2009
1 parent 8735354 commit c3046b9
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 96 deletions.
7 changes: 6 additions & 1 deletion tests/unit/slider/slider.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
<script type="text/javascript" src="../../../external/qunit/testrunner.js"></script> <script type="text/javascript" src="../../../external/qunit/testrunner.js"></script>
<script type="text/javascript" src="../../../external/simulate/jquery.simulate.js"></script> <script type="text/javascript" src="../../../external/simulate/jquery.simulate.js"></script>


<script type="text/javascript" src="slider.js"></script> <script type="text/javascript" src="slider_core.js"></script>
<script type="text/javascript" src="slider_defaults.js"></script>
<script type="text/javascript" src="slider_events.js"></script>
<script type="text/javascript" src="slider_methods.js"></script>
<script type="text/javascript" src="slider_options.js"></script>
<script type="text/javascript" src="slider_tickets.js"></script>
</head> </head>
<body> <body>


Expand Down
96 changes: 1 addition & 95 deletions tests/unit/slider/slider.js → tests/unit/slider/slider_core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@
// Slider Test Helper Functions // Slider Test Helper Functions
// //


var defaults = {
max: 100,
min: 0,
orientation: 'auto',
step: 1,
value: 0
};

var el, options; var el, options;


function handle() { function handle() {
return el.find(".ui-slider-handle"); return el.find(".ui-slider-handle");
} }


// Slider Tests // Slider Tests
module("slider"); module("slider: core");


test("init", function() { test("init", function() {
expect(6); expect(6);
Expand Down Expand Up @@ -79,17 +71,6 @@ test("destroy", function() {
ok(true, 'arbitrary option setter (.slider option method) after destroy'); ok(true, 'arbitrary option setter (.slider option method) after destroy');
}); });


test("defaults", function() {
el = $('<div></div>').slider();
$.each(defaults, function(key, val) {
var actual = el.data(key + ".slider"), expected = val;
same(actual, expected, key);
});
el.remove();
});

module("slider");

test("keydown HOME on handle sets value to min", function() { test("keydown HOME on handle sets value to min", function() {
el = $('<div></div>'); el = $('<div></div>');
options = { options = {
Expand Down Expand Up @@ -318,79 +299,4 @@ test("keydown LEFT on handle decreases value by step, not less than min", functi
el.slider("destroy"); el.slider("destroy");
}); });


module("slider: Options");

test("orientation", function() {
el = $('<div></div>');

options = {
max: 2,
min: -2,
orientation: 'vertical',
value: 1
};

var percentVal = (options.value - options.min) / (options.max - options.min) * 100;

el.slider(options).slider("option", "orientation", "horizontal");
ok(el.is('.ui-slider-horizontal'), "horizontal slider has class .ui-slider-horizontal");
ok(!el.is('.ui-slider-vertical'), "horizontal slider does not have class .ui-slider-vertical");
equals(handle().css('left'), percentVal + '%', "horizontal slider handle is positioned with left: %");

el.slider('destroy');

options = {
max: 2,
min: -2,
orientation: 'horizontal',
value: -1
};

var percentVal = (options.value - options.min) / (options.max - options.min) * 100;

el.slider(options).slider("option", "orientation", "vertical");
ok(el.is('.ui-slider-vertical'), "vertical slider has class .ui-slider-vertical");
ok(!el.is('.ui-slider-horizontal'), "vertical slider does not have class .ui-slider-horizontal");
equals(handle().css('bottom'), percentVal + '%', "vertical slider handle is positioned with bottom: %");

el.slider('destroy');

});

test("max", function() {
el = $('<div></div>');

options = {
max: 37,
min: 6,
orientation: 'horizontal',
step: 1,
value: 50
};

el.slider(options);
ok(el.slider("option", "value") == options.value, "value option is not contained by max");
ok(el.slider("value") == options.max, "value method is contained by max");
el.slider('destroy');

});

test("min", function() {
el = $('<div></div>');

options = {
max: 37,
min: 6,
orientation: 'vertical',
step: 1,
value: 2
};

el.slider(options);
ok(el.slider("option", "value") == options.value, "value option is not contained by min");
ok(el.slider("value") == options.min, "value method is contained by min");
el.slider('destroy');

});

})(jQuery); })(jQuery);
19 changes: 19 additions & 0 deletions tests/unit/slider/slider_defaults.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* slider_defaults.js
*/

var slider_defaults = {
animate: false,
delay: 0,
disabled: false,
distance: 0,
max: 100,
min: 0,
orientation: 'auto',
range: false,
step: 1,
value: 0,
values: null
};

commonWidgetTests('slider', { defaults: slider_defaults });
24 changes: 24 additions & 0 deletions tests/unit/slider/slider_events.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* slider_events.js
*/
(function($) {

module("slider: events");

test("start", function() {
ok(false, "missing test - untested code is broken code.");
});

test("slide", function() {
ok(false, "missing test - untested code is broken code.");
});

test("change", function() {
ok(false, "missing test - untested code is broken code.");
});

test("stop", function() {
ok(false, "missing test - untested code is broken code.");
});

})(jQuery);
24 changes: 24 additions & 0 deletions tests/unit/slider/slider_methods.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* slider_methods.js
*/
(function($) {

module("slider: methods");

test("value", function() {
ok(false, "missing test - untested code is broken code.");
});

test("values", function() {
ok(false, "missing test - untested code is broken code.");
});

test("enable", function() {
ok(false, "missing test - untested code is broken code.");
});

test("disable", function() {
ok(false, "missing test - untested code is broken code.");
});

})(jQuery);
105 changes: 105 additions & 0 deletions tests/unit/slider/slider_options.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* slider_options.js
*/
(function($) {

function handle() {
return el.find(".ui-slider-handle");
}

module("slider: options");

test("animate", function() {
ok(false, "missing test - untested code is broken code.");
});

test("max", function() {
el = $('<div></div>');

options = {
max: 37,
min: 6,
orientation: 'horizontal',
step: 1,
value: 50
};

el.slider(options);
ok(el.slider("option", "value") == options.value, "value option is not contained by max");
ok(el.slider("value") == options.max, "value method is contained by max");
el.slider('destroy');

});

test("min", function() {
el = $('<div></div>');

options = {
max: 37,
min: 6,
orientation: 'vertical',
step: 1,
value: 2
};

el.slider(options);
ok(el.slider("option", "value") == options.value, "value option is not contained by min");
ok(el.slider("value") == options.min, "value method is contained by min");
el.slider('destroy');

});

test("orientation", function() {
el = $('<div></div>');

options = {
max: 2,
min: -2,
orientation: 'vertical',
value: 1
};

var percentVal = (options.value - options.min) / (options.max - options.min) * 100;

el.slider(options).slider("option", "orientation", "horizontal");
ok(el.is('.ui-slider-horizontal'), "horizontal slider has class .ui-slider-horizontal");
ok(!el.is('.ui-slider-vertical'), "horizontal slider does not have class .ui-slider-vertical");
equals(handle().css('left'), percentVal + '%', "horizontal slider handle is positioned with left: %");

el.slider('destroy');

options = {
max: 2,
min: -2,
orientation: 'horizontal',
value: -1
};

var percentVal = (options.value - options.min) / (options.max - options.min) * 100;

el.slider(options).slider("option", "orientation", "vertical");
ok(el.is('.ui-slider-vertical'), "vertical slider has class .ui-slider-vertical");
ok(!el.is('.ui-slider-horizontal'), "vertical slider does not have class .ui-slider-horizontal");
equals(handle().css('bottom'), percentVal + '%', "vertical slider handle is positioned with bottom: %");

el.slider('destroy');

});

test("range", function() {
ok(false, "missing test - untested code is broken code.");
});

test("step", function() {
ok(false, "missing test - untested code is broken code.");
});

test("value", function() {
ok(false, "missing test - untested code is broken code.");
});

test("values", function() {
ok(false, "missing test - untested code is broken code.");
});

})(jQuery);
8 changes: 8 additions & 0 deletions tests/unit/slider/slider_tickets.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* slider_tickets.js
*/
(function($) {

module("slider: tickets");

})(jQuery);

0 comments on commit c3046b9

Please sign in to comment.