diff options
Diffstat (limited to 'tests/unit/resizable')
-rw-r--r-- | tests/unit/resizable/resizable.html | 11 | ||||
-rw-r--r-- | tests/unit/resizable/resizable_core.js | 68 | ||||
-rw-r--r-- | tests/unit/resizable/resizable_events.js | 4 | ||||
-rw-r--r-- | tests/unit/resizable/resizable_methods.js | 3 | ||||
-rw-r--r-- | tests/unit/resizable/resizable_options.js | 66 | ||||
-rw-r--r-- | tests/unit/resizable/resizable_test_helpers.js | 15 |
6 files changed, 99 insertions, 68 deletions
diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html index 558574c5f..eca465ae9 100644 --- a/tests/unit/resizable/resizable.html +++ b/tests/unit/resizable/resizable.html @@ -26,17 +26,8 @@ <script src="resizable_events.js"></script> <script src="resizable_methods.js"></script> <script src="resizable_options.js"></script> + <script src="resizable_test_helpers.js"></script> - <script> - // disable this stale testsuite for testswarm only - var url = window.location.search; - url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); - if ( url && url.indexOf("http") == 0 ) { - // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script - QUnit.init(); - test("resizable", function() { ok(true, "disabled resizable testsuite"); }); - } - </script> <script src="../swarminject.js"></script> </head> <body> diff --git a/tests/unit/resizable/resizable_core.js b/tests/unit/resizable/resizable_core.js index aef2ae15c..a1ac22272 100644 --- a/tests/unit/resizable/resizable_core.js +++ b/tests/unit/resizable/resizable_core.js @@ -2,22 +2,6 @@ * resizable_core.js */ -var el; - -var drag = function(el, dx, dy, complete) { - - // speed = sync -> Drag syncrhonously. - // speed = fast|slow -> Drag asyncrhonously - animated. - - //this mouseover is to work around a limitation in resizable - //TODO: fix resizable so handle doesn't require mouseover in order to be used - $(el).simulate("mouseover"); - - return $(el).simulate("drag", { - dx: dx||0, dy: dy||0, speed: 'sync', complete: complete - }); -}; - (function($) { module("resizable: core"); @@ -46,10 +30,10 @@ test("n", function() { var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' }); - drag(handle, 0, -50); + TestHelpers.resizable.drag(handle, 0, -50); equal( target.height(), 150, "compare height" ); - drag(handle, 0, 50); + TestHelpers.resizable.drag(handle, 0, 50); equal( target.height(), 100, "compare height" ); }); @@ -58,10 +42,10 @@ test("s", function() { var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' }); - drag(handle, 0, 50); + TestHelpers.resizable.drag(handle, 0, 50); equal( target.height(), 150, "compare height" ); - drag(handle, 0, -50); + TestHelpers.resizable.drag(handle, 0, -50); equal( target.height(), 100, "compare height" ); }); @@ -70,10 +54,10 @@ test("e", function() { var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' }); - drag(handle, 50); + TestHelpers.resizable.drag(handle, 50); equal( target.width(), 150, "compare width"); - drag(handle, -50); + TestHelpers.resizable.drag(handle, -50); equal( target.width(), 100, "compare width" ); }); @@ -82,10 +66,10 @@ test("w", function() { var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' }); - drag(handle, -50); + TestHelpers.resizable.drag(handle, -50); equal( target.width(), 150, "compare width" ); - drag(handle, 50); + TestHelpers.resizable.drag(handle, 50); equal( target.width(), 100, "compare width" ); }); @@ -94,11 +78,11 @@ test("ne", function() { var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' }); - drag(handle, -50, -50); + TestHelpers.resizable.drag(handle, -50, -50); equal( target.width(), 50, "compare width" ); equal( target.height(), 150, "compare height" ); - drag(handle, 50, 50); + TestHelpers.resizable.drag(handle, 50, 50); equal( target.width(), 100, "compare width" ); equal( target.height(), 100, "compare height" ); }); @@ -108,11 +92,11 @@ test("se", function() { var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' }); - drag(handle, 50, 50); + TestHelpers.resizable.drag(handle, 50, 50); equal( target.width(), 150, "compare width" ); equal( target.height(), 150, "compare height" ); - drag(handle, -50, -50); + TestHelpers.resizable.drag(handle, -50, -50); equal( target.width(), 100, "compare width" ); equal( target.height(), 100, "compare height" ); }); @@ -122,11 +106,11 @@ test("sw", function() { var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' }); - drag(handle, -50, -50); + TestHelpers.resizable.drag(handle, -50, -50); equal( target.width(), 150, "compare width" ); equal( target.height(), 50, "compare height" ); - drag(handle, 50, 50); + TestHelpers.resizable.drag(handle, 50, 50); equal( target.width(), 100, "compare width" ); equal( target.height(), 100, "compare height" ); }); @@ -136,13 +120,33 @@ test("nw", function() { var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' }); - drag(handle, -50, -50); + TestHelpers.resizable.drag(handle, -50, -50); equal( target.width(), 150, "compare width" ); equal( target.height(), 150, "compare height" ); - drag(handle, 50, 50); + TestHelpers.resizable.drag(handle, 50, 50); equal( target.width(), 100, "compare width" ); equal( target.height(), 100, "compare height" ); }); +test("handle with complex markup (#8756)", function() { + expect(2); + + $('#resizable1') + .append( + $('<div>') + .addClass("ui-resizable-handle") + .addClass("ui-resizable-w") + .append($('<div>')) + ); + + var handle = '.ui-resizable-w div', target = $('#resizable1').resizable({ handles: 'all' }); + + TestHelpers.resizable.drag(handle, -50); + equal( target.width(), 150, "compare width" ); + + TestHelpers.resizable.drag(handle, 50); + equal( target.width(), 100, "compare width" ); +}); + })(jQuery); diff --git a/tests/unit/resizable/resizable_events.js b/tests/unit/resizable/resizable_events.js index 52d55731c..d7793ff2f 100644 --- a/tests/unit/resizable/resizable_events.js +++ b/tests/unit/resizable/resizable_events.js @@ -5,4 +5,8 @@ module("resizable: events"); +// this is here to make JSHint pass "unused", and we don't want to +// remove the parameter for when we finally implement +$.noop(); + })(jQuery); diff --git a/tests/unit/resizable/resizable_methods.js b/tests/unit/resizable/resizable_methods.js index 87859acf7..b12f3035a 100644 --- a/tests/unit/resizable/resizable_methods.js +++ b/tests/unit/resizable/resizable_methods.js @@ -5,5 +5,8 @@ module("resizable: methods"); +// this is here to make JSHint pass "unused", and we don't want to +// remove the parameter for when we finally implement +$.noop(); })(jQuery); diff --git a/tests/unit/resizable/resizable_options.js b/tests/unit/resizable/resizable_options.js index e10a55a31..4b47762ab 100644 --- a/tests/unit/resizable/resizable_options.js +++ b/tests/unit/resizable/resizable_options.js @@ -10,11 +10,11 @@ test("aspectRatio: 'preserve' (e)", function() { var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - drag(handle, 80); + TestHelpers.resizable.drag(handle, 80); equal( target.width(), 130, "compare maxWidth"); equal( target.height(), 130, "compare maxHeight"); - drag(handle, -130); + TestHelpers.resizable.drag(handle, -130); equal( target.width(), 70, "compare minWidth"); equal( target.height(), 70, "compare minHeight"); }); @@ -24,11 +24,11 @@ test("aspectRatio: 'preserve' (w)", function() { var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - drag(handle, -80); + TestHelpers.resizable.drag(handle, -80); equal( target.width(), 130, "compare maxWidth"); equal( target.height(), 130, "compare maxHeight"); - drag(handle, 130); + TestHelpers.resizable.drag(handle, 130); equal( target.width(), 70, "compare minWidth"); equal( target.height(), 70, "compare minHeight"); }); @@ -38,11 +38,11 @@ test("aspectRatio: 'preserve' (n)", function() { var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - drag(handle, 0, -80); + TestHelpers.resizable.drag(handle, 0, -80); equal( target.width(), 130, "compare maxWidth"); equal( target.height(), 130, "compare maxHeight"); - drag(handle, 0, 80); + TestHelpers.resizable.drag(handle, 0, 80); equal( target.width(), 70, "compare minWidth"); equal( target.height(), 70, "compare minHeight"); }); @@ -52,11 +52,11 @@ test("aspectRatio: 'preserve' (s)", function() { var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - drag(handle, 0, 80); + TestHelpers.resizable.drag(handle, 0, 80); equal( target.width(), 130, "compare maxWidth"); equal( target.height(), 130, "compare maxHeight"); - drag(handle, 0, -80); + TestHelpers.resizable.drag(handle, 0, -80); equal( target.width(), 70, "compare minWidth"); equal( target.height(), 70, "compare minHeight"); }); @@ -66,11 +66,11 @@ test("aspectRatio: 'preserve' (se)", function() { var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - drag(handle, 80, 80); + TestHelpers.resizable.drag(handle, 80, 80); equal( target.width(), 130, "compare maxWidth"); equal( target.height(), 130, "compare maxHeight"); - drag(handle, -80, -80); + TestHelpers.resizable.drag(handle, -80, -80); equal( target.width(), 70, "compare minWidth"); equal( target.height(), 70, "compare minHeight"); }); @@ -80,11 +80,11 @@ test("aspectRatio: 'preserve' (sw)", function() { var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - drag(handle, -80, 80); + TestHelpers.resizable.drag(handle, -80, 80); equal( target.width(), 130, "compare maxWidth"); equal( target.height(), 130, "compare maxHeight"); - drag(handle, 80, -80); + TestHelpers.resizable.drag(handle, 80, -80); equal( target.width(), 70, "compare minWidth"); equal( target.height(), 70, "compare minHeight"); }); @@ -94,11 +94,11 @@ test("aspectRatio: 'preserve' (ne)", function() { var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); - drag(handle, 80, -80); + TestHelpers.resizable.drag(handle, 80, -80); equal( target.width(), 130, "compare maxWidth"); equal( target.height(), 130, "compare maxHeight"); - drag(handle, -80, 80); + TestHelpers.resizable.drag(handle, -80, 80); equal( target.width(), 70, "compare minWidth"); equal( target.height(), 70, "compare minHeight"); }); @@ -108,25 +108,39 @@ test("grid", function() { var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] }); - drag(handle, 3, 9); + TestHelpers.resizable.drag(handle, 3, 9); equal( target.width(), 103, "compare width"); equal( target.height(), 100, "compare height"); - drag(handle, 15, 11); + TestHelpers.resizable.drag(handle, 15, 11); equal( target.width(), 118, "compare width"); equal( target.height(), 120, "compare height"); }); +test("grid (min/max dimensions)", function() { + expect(4); + + var handle = ".ui-resizable-se", target = $("#resizable1").resizable({ handles: "all", grid: 20, minWidth: 65, minHeight: 65, maxWidth: 135, maxHeight: 135 }); + + TestHelpers.resizable.drag(handle, 50, 50); + equal( target.width(), 120, "grid should respect maxWidth"); + equal( target.height(), 120, "grid should respect maxHeight"); + + TestHelpers.resizable.drag(handle, -100, -100); + equal( target.width(), 80, "grid should respect minWidth"); + equal( target.height(), 80, "grid should respect minHeight"); +}); + test("grid (wrapped)", function() { expect(4); var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] }); - drag(handle, 3, 9); + TestHelpers.resizable.drag(handle, 3, 9); equal( target.width(), 103, "compare width"); equal( target.height(), 100, "compare height"); - drag(handle, 15, 11); + TestHelpers.resizable.drag(handle, 15, 11); equal( target.width(), 118, "compare width"); equal( target.height(), 120, "compare height"); }); @@ -136,11 +150,11 @@ test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1 var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - drag(handle, -50, -50); + TestHelpers.resizable.drag(handle, -50, -50); equal( target.width(), 60, "compare minWidth" ); equal( target.height(), 60, "compare minHeight" ); - drag(handle, 70, 70); + TestHelpers.resizable.drag(handle, 70, 70); equal( target.width(), 100, "compare maxWidth" ); equal( target.height(), 100, "compare maxHeight" ); }); @@ -150,11 +164,11 @@ test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1 var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - drag(handle, 50, -50); + TestHelpers.resizable.drag(handle, 50, -50); equal( target.width(), 60, "compare minWidth" ); equal( target.height(), 60, "compare minHeight" ); - drag(handle, -70, 70); + TestHelpers.resizable.drag(handle, -70, 70); equal( target.width(), 100, "compare maxWidth" ); equal( target.height(), 100, "compare maxHeight" ); }); @@ -164,11 +178,11 @@ test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1 var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - drag(handle, -50, 50); + TestHelpers.resizable.drag(handle, -50, 50); equal( target.width(), 60, "compare minWidth" ); equal( target.height(), 60, "compare minHeight" ); - drag(handle, 70, -70); + TestHelpers.resizable.drag(handle, 70, -70); equal( target.width(), 100, "compare maxWidth" ); equal( target.height(), 100, "compare maxHeight" ); }); @@ -178,11 +192,11 @@ test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 1 var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); - drag(handle, 70, 70); + TestHelpers.resizable.drag(handle, 70, 70); equal( target.width(), 60, "compare minWidth" ); equal( target.height(), 60, "compare minHeight" ); - drag(handle, -70, -70); + TestHelpers.resizable.drag(handle, -70, -70); equal( target.width(), 100, "compare maxWidth" ); equal( target.height(), 100, "compare maxHeight" ); }); diff --git a/tests/unit/resizable/resizable_test_helpers.js b/tests/unit/resizable/resizable_test_helpers.js new file mode 100644 index 000000000..fe6c84900 --- /dev/null +++ b/tests/unit/resizable/resizable_test_helpers.js @@ -0,0 +1,15 @@ +TestHelpers.resizable = { + drag: function(el, dx, dy, complete) { + + // speed = sync -> Drag syncrhonously. + // speed = fast|slow -> Drag asyncrhonously - animated. + + //this mouseover is to work around a limitation in resizable + //TODO: fix resizable so handle doesn't require mouseover in order to be used + $(el).simulate("mouseover"); + + return $(el).simulate("drag", { + dx: dx||0, dy: dy||0, speed: 'sync', complete: complete + }); + } +};
\ No newline at end of file |