diff options
Diffstat (limited to 'apps/it/static/js/ui/tests/unit/selectable')
7 files changed, 343 insertions, 0 deletions
diff --git a/apps/it/static/js/ui/tests/unit/selectable/all.html b/apps/it/static/js/ui/tests/unit/selectable/all.html new file mode 100644 index 0000000..5ee323f --- /dev/null +++ b/apps/it/static/js/ui/tests/unit/selectable/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Selectable Test Suite</title> + + <script src="../../../jquery-1.10.2.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../qunit-composite.css"> + <script src="../../../external/qunit.js"></script> + <script src="../qunit-composite.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "selectable" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Selectable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/apps/it/static/js/ui/tests/unit/selectable/selectable.html b/apps/it/static/js/ui/tests/unit/selectable/selectable.html new file mode 100644 index 0000000..18ffc6e --- /dev/null +++ b/apps/it/static/js/ui/tests/unit/selectable/selectable.html @@ -0,0 +1,51 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Selectable Test Suite</title> + + <script src="../../jquery.js"></script> + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + <script> + TestHelpers.loadResources({ + css: [ "ui.core", "ui.selectable" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.selectable.js" + ] + }); + </script> + + <script src="selectable_common.js"></script> + <script src="selectable_core.js"></script> + <script src="selectable_events.js"></script> + <script src="selectable_methods.js"></script> + <script src="selectable_options.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Selectable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<ul id="selectable1"> + <li>Item 1</li> + <li>Item 2</li> + <li class="special">Item 3</li> + <li>Item 4</li> + <li>Item 5</li> +</ul> + +</div> +</body> +</html> diff --git a/apps/it/static/js/ui/tests/unit/selectable/selectable_common.js b/apps/it/static/js/ui/tests/unit/selectable/selectable_common.js new file mode 100644 index 0000000..d00a47b --- /dev/null +++ b/apps/it/static/js/ui/tests/unit/selectable/selectable_common.js @@ -0,0 +1,21 @@ +TestHelpers.commonWidgetTests("selectable", { + defaults: { + appendTo: "body", + autoRefresh: true, + cancel: "input,textarea,button,select,option", + delay: 0, + disabled: false, + distance: 0, + filter: "*", + tolerance: "touch", + + // callbacks + create: null, + selected: null, + selecting: null, + start: null, + stop: null, + unselected: null, + unselecting: null + } +}); diff --git a/apps/it/static/js/ui/tests/unit/selectable/selectable_core.js b/apps/it/static/js/ui/tests/unit/selectable/selectable_core.js new file mode 100644 index 0000000..9953b6c --- /dev/null +++ b/apps/it/static/js/ui/tests/unit/selectable/selectable_core.js @@ -0,0 +1,3 @@ +/* + * selectable_core.js + */
\ No newline at end of file diff --git a/apps/it/static/js/ui/tests/unit/selectable/selectable_events.js b/apps/it/static/js/ui/tests/unit/selectable/selectable_events.js new file mode 100644 index 0000000..ae35fa3 --- /dev/null +++ b/apps/it/static/js/ui/tests/unit/selectable/selectable_events.js @@ -0,0 +1,69 @@ +/* + * selectable_events.js + */ +(function( $ ) { + +module("selectable: events"); + +test( "start", function() { + expect( 2 ); + var el = $("#selectable1"); + el.selectable({ + start: function() { + ok( true, "drag fired start callback" ); + equal( this, el[0], "context of callback" ); + } + }); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); +}); + +test( "stop", function() { + expect( 2 ); + var el = $("#selectable1"); + el.selectable({ + start: function() { + ok( true, "drag fired stop callback" ); + equal( this, el[0], "context of callback" ); + } + }); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); +}); + +test( "mousedown: initial position of helper", function() { + expect( 2 ); + + var helperOffset, + element = $( "#selectable1" ).selectable(), + contentToForceScroll = $( "<div>" ).css({ + height: "10000px", + width: "10000px" + }); + + contentToForceScroll.appendTo( "body" ); + $( window ).scrollTop( 100 ).scrollLeft( 100 ); + + element.simulate( "mousedown", { + clientX: 10, + clientY: 10 + }); + + // we do a GTE comparison here because IE7 erroneously subtracts + // 2 pixels from a simulated mousedown for clientX/Y + // Support: IE7 + helperOffset = $( ".ui-selectable-helper" ).offset(); + ok( helperOffset.top >= 99, "Scroll top should be accounted for." ); + ok( helperOffset.left >= 99, "Scroll left should be accounted for." ); + + // Cleanup + element.simulate( "mouseup" ); + contentToForceScroll.remove(); + $( window ).scrollTop( 0 ).scrollLeft( 0 ); +}); + +})( jQuery ); diff --git a/apps/it/static/js/ui/tests/unit/selectable/selectable_methods.js b/apps/it/static/js/ui/tests/unit/selectable/selectable_methods.js new file mode 100644 index 0000000..72f9bb2 --- /dev/null +++ b/apps/it/static/js/ui/tests/unit/selectable/selectable_methods.js @@ -0,0 +1,104 @@ +/* + * selectable_methods.js + */ +(function($) { + +module("selectable: methods"); + +test("init", function() { + expect( 5 ); + + $("<div></div>").appendTo("body").selectable().remove(); + ok(true, ".selectable() called on element"); + + $([]).selectable().remove(); + ok(true, ".selectable() called on empty collection"); + + $("<div></div>").selectable().remove(); + ok(true, ".selectable() called on disconnected DOMElement"); + + var el = $("<div></div>").selectable(); + el.selectable("option", "foo"); + el.remove(); + ok(true, "arbitrary option getter after init"); + + $("<div></div>").selectable().selectable("option", "foo", "bar").remove(); + ok(true, "arbitrary option setter after init"); +}); + +test("destroy", function() { + expect( 4 ); + + $("<div></div>").appendTo("body").selectable().selectable("destroy").remove(); + ok(true, ".selectable('destroy') called on element"); + + $([]).selectable().selectable("destroy").remove(); + ok(true, ".selectable('destroy') called on empty collection"); + + $("<div></div>").selectable().selectable("destroy").remove(); + ok(true, ".selectable('destroy') called on disconnected DOMElement"); + + var expected = $("<div></div>").selectable(), + actual = expected.selectable("destroy"); + equal(actual, expected, "destroy is chainable"); +}); + +test("enable", function() { + expect(3); + var expected, actual, + fired = false, + el = $("#selectable1"); + + el.selectable({ + disabled: true, + start: function() { fired = true; } + }); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); + equal(fired, false, "start fired"); + el.selectable("enable"); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); + equal(fired, true, "start fired"); + el.selectable("destroy"); + + expected = $("<div></div>").selectable(); + actual = expected.selectable("enable"); + equal(actual, expected, "enable is chainable"); +}); + +test("disable", function() { + expect(3); + var expected, actual, + fired = false, + el = $("#selectable1"); + + el.selectable({ + disabled: false, + start: function() { fired = true; } + }); + el.simulate( "drag", { + dx: 20, + dy: 20 + }); + equal(fired, true, "start fired"); + el.selectable("disable"); + fired = false; + + el.simulate( "drag", { + dx: 20, + dy: 20 + }); + equal(fired, false, "start fired"); + el.selectable("destroy"); + + expected = $("<div></div>").selectable(); + actual = expected.selectable("disable"); + equal(actual, expected, "disable is chainable"); +}); + +})(jQuery); diff --git a/apps/it/static/js/ui/tests/unit/selectable/selectable_options.js b/apps/it/static/js/ui/tests/unit/selectable/selectable_options.js new file mode 100644 index 0000000..973247f --- /dev/null +++ b/apps/it/static/js/ui/tests/unit/selectable/selectable_options.js @@ -0,0 +1,65 @@ +/* + * selectable_options.js + */ +(function($) { + +module("selectable: options"); + +test("autoRefresh", function() { + expect(3); + + var actual = 0, + el = $("#selectable1"), + sel = $("*", el), + selected = function() { actual += 1; }; + + el = $("#selectable1").selectable({ autoRefresh: false, selected: selected }); + sel.hide(); + el.simulate( "drag", { + dx: 1000, + dy: 1000 + }); + equal(actual, sel.length); + el.selectable("destroy"); + + actual = 0; + sel.show(); + el = $("#selectable1").selectable({ autoRefresh: true, selected: selected }); + sel.hide(); + el.simulate( "drag", { + dx: 1000, + dy: 1000 + }); + equal(actual, 0); + + sel.show(); + $( sel[ 0 ] ).simulate( "drag", { + dx: 1000, + dy: 1000 + }); + equal(actual, sel.length); + + el.selectable("destroy"); + sel.show(); +}); + +test("filter", function() { + expect(2); + + var actual =0, + el = $("#selectable1"), + sel = $("*", el), + selected = function() { actual += 1; }; + + + el = $("#selectable1").selectable({ filter: ".special", selected: selected }); + el.simulate( "drag", { + dx: 1000, + dy: 1000 + }); + ok(sel.length !== 1, "this test assumes more than 1 selectee"); + equal(actual, 1); + el.selectable("destroy"); +}); + +})(jQuery); |