]> source.dussan.org Git - jquery-ui.git/commitdiff
Dev: Standardized the selectable test suite. Fixed #8752 - Dev: Get selectable test...
authorMike Sherov <mike.sherov@gmail.com>
Wed, 31 Oct 2012 01:50:08 +0000 (21:50 -0400)
committerScott González <scott.gonzalez@gmail.com>
Wed, 31 Oct 2012 02:19:55 +0000 (22:19 -0400)
build/tasks/testswarm.js
grunt.js
tests/unit/all-active.html
tests/unit/all.html
tests/unit/selectable/selectable_common.js
tests/unit/selectable/selectable_core.js
tests/unit/selectable/selectable_events.js
tests/unit/selectable/selectable_methods.js
tests/unit/selectable/selectable_options.js
ui/jquery.ui.selectable.js

index e7d96f516e0178e573cc35cfca91e57227f753a6..62433232fb5f191d8b1d3d9fb98f416e4d88094d 100644 (file)
@@ -22,7 +22,7 @@ var versions = {
                "Position": "position/position.html",
                "Progressbar": "progressbar/progressbar.html",
                //"Resizable": "resizable/resizable.html",
-               //"Selectable": "selectable/selectable.html",
+               "Selectable": "selectable/selectable.html",
                //"Slider": "slider/slider.html",
                //"Sortable": "sortable/sortable.html",
                "Spinner": "spinner/spinner.html",
index e70a32871402953356d6ddb35f62d8e68bc8758c..9c2999e3b4425bc89f249649ce1b01e69793c242 100644 (file)
--- a/grunt.js
+++ b/grunt.js
@@ -281,13 +281,13 @@ grunt.initConfig({
                files: grunt.file.expandFiles( "tests/unit/**/*.html" ).filter(function( file ) {
                        // disabling everything that doesn't (quite) work with PhantomJS for now
                        // TODO except for all|index|test, try to include more as we go
-                       return !( /(all|all-active|index|test|droppable|selectable|resizable|sortable|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file );
+                       return !( /(all|all-active|index|test|droppable|resizable|sortable|dialog|slider|datepicker|tabs|tooltip)\.html$/ ).test( file );
                })
        },
        lint: {
                ui: grunt.file.expandFiles( "ui/*.js" ).filter(function( file ) {
                        // TODO remove items from this list once rewritten
-                       return !( /(mouse|datepicker|droppable|resizable|selectable|sortable)\.js$/ ).test( file );
+                       return !( /(mouse|datepicker|droppable|resizable|sortable)\.js$/ ).test( file );
                }),
                grunt: [ "grunt.js", "build/**/*.js" ],
                tests: "tests/unit/**/*.js"
index 200a6a53d2f629adc2c340274c769c9c5b89cd27..350aca7b9d69f0ae345a137230485c2e0268d3f7 100644 (file)
@@ -29,7 +29,7 @@
                        "position/position.html",
                        "progressbar/progressbar.html",
                        //"resizable/resizable.html",
-                       //"selectable/selectable.html",
+                       "selectable/selectable.html",
                        //"slider/slider.html",
                        //"sortable/sortable.html",
                        "spinner/spinner.html",
index 8020e26865cf1368013cc93a7926e769fc82e852..e37878c1c86350e58007b663136d0c1fa8ec958a 100644 (file)
@@ -29,7 +29,7 @@
                        "position/position.html",
                        "progressbar/progressbar.html",
                        //"resizable/resizable.html",
-                       //"selectable/selectable.html",
+                       "selectable/selectable.html",
                        "slider/slider.html",
                        //"sortable/sortable.html",
                        "spinner/spinner.html",
index 885e7940128202b236aa863bb3d3fe49bf2869da..aee6a15acdcfc5e4e33e4885b6e1da4b31791ae7 100644 (file)
@@ -3,6 +3,7 @@ TestHelpers.commonWidgetTests('selectable', {
                appendTo: 'body',
                autoRefresh: true,
                cancel: 'input,textarea,button,select,option',
+               create: null,
                delay: 0,
                disabled: false,
                distance: 0,
index d2e885fc71308ead0a3b86fee6e20e34afeb3cb0..de89e66a73b1fb564aacf01b6afda4879c79349a 100644 (file)
@@ -2,15 +2,15 @@
  * selectable_core.js
  */
 
-var el;
-
-TestHelpers.selectableDrag = function drag(dx, dy) {
-       var off = el.offset(), pos = { clientX: off.left, clientY: off.top };
-       el.simulate("mousedown", pos);
-       $(document).simulate("mousemove", pos);
-       pos.clientX += dx;
-       pos.clientY += dy;
-       $(document).simulate("mousemove", pos);
-       $(document).simulate("mouseup", pos);
-};
-
+TestHelpers.selectable = {
+       drag: function drag(el, dx, dy) {
+               var off = el.offset(),
+                       pos = { clientX: off.left, clientY: off.top };
+               el.simulate("mousedown", pos);
+               $(document).simulate("mousemove", pos);
+               pos.clientX += dx;
+               pos.clientY += dy;
+               $(document).simulate("mousemove", pos);
+               $(document).simulate("mouseup", pos);
+       }
+};
\ No newline at end of file
index bfd431bd8d1cdef0e68c3cfb474dad31a04fe72f..331bae1465f720dad8228618528311b5e5f7623b 100644 (file)
@@ -7,7 +7,7 @@ module("selectable: events");
 
 test("start", function() {
        expect(2);
-       el = $("#selectable1");
+       var el = $("#selectable1");
        el.selectable({
                start: function() {
                        ok(true, "drag fired start callback");
@@ -19,7 +19,7 @@ test("start", function() {
 
 test("stop", function() {
        expect(2);
-       el = $("#selectable1");
+       var el = $("#selectable1");
        el.selectable({
                start: function() {
                        ok(true, "drag fired stop callback");
index ee7242d9b06193e3a5ee312442857056b4d2a1e1..aa8924176939931636fdd413f46de3c54fadffed 100644 (file)
@@ -6,7 +6,7 @@
 module("selectable: methods");
 
 test("init", function() {
-       expect(6);
+       expect( 5 );
 
        $("<div></div>").appendTo('body').selectable().remove();
        ok(true, '.selectable() called on element');
@@ -17,10 +17,7 @@ test("init", function() {
        $("<div></div>").selectable().remove();
        ok(true, '.selectable() called on disconnected DOMElement');
 
-       $("<div></div>").selectable().selectable("foo").remove();
-       ok(true, 'arbitrary method called after init');
-
-       el = $("<div></div>").selectable();
+       var el = $("<div></div>").selectable();
        el.selectable("option", "foo");
        el.remove();
        ok(true, 'arbitrary option getter after init');
@@ -30,6 +27,8 @@ test("init", function() {
 });
 
 test("destroy", function() {
+       expect( 4 );
+
        $("<div></div>").appendTo('body').selectable().selectable("destroy").remove();
        ok(true, '.selectable("destroy") called on element');
 
@@ -39,9 +38,6 @@ test("destroy", function() {
        $("<div></div>").selectable().selectable("destroy").remove();
        ok(true, '.selectable("destroy") called on disconnected DOMElement');
 
-       $("<div></div>").selectable().selectable("destroy").selectable("foo").remove();
-       ok(true, 'arbitrary method called after destroy');
-
        var expected = $('<div></div>').selectable(),
                actual = expected.selectable('destroy');
        equal(actual, expected, 'destroy is chainable');
@@ -50,9 +46,9 @@ test("destroy", function() {
 test("enable", function() {
        expect(3);
        var expected, actual,
-               fired = false;
+               fired = false,
+               el = $("#selectable1");
 
-       el = $("#selectable1");
        el.selectable({
                disabled: true,
                start: function() { fired = true; }
@@ -72,9 +68,9 @@ test("enable", function() {
 test("disable", function() {
        expect(3);
        var expected, actual,
-               fired = false;
+               fired = false,
+               el = $("#selectable1");
 
-       el = $("#selectable1");
        el.selectable({
                disabled: false,
                start: function() { fired = true; }
index ad57000a9e5f1c4184ab95f4c6e00553065cffe6..2b7fc16487fff7c31925e447161ff323ff569cba 100644 (file)
@@ -7,13 +7,15 @@ module("selectable: options");
 
 test("autoRefresh", function() {
        expect(3);
-       el = $("#selectable1");
-       var actual, sel = $("*", el), selected = function() { actual += 1; };
 
-       actual = 0;
+       var actual = 0,
+               el = $("#selectable1"),
+               sel = $("*", el),
+               selected = function() { actual += 1; };
+
        el = $("#selectable1").selectable({ autoRefresh: false, selected: selected });
        sel.hide();
-       TestHelpers.selectableDrag(1000, 1000);
+       TestHelpers.selectable.drag(el, 1000, 1000);
        equal(actual, sel.length);
        el.selectable("destroy");
 
@@ -21,10 +23,10 @@ test("autoRefresh", function() {
        sel.show();
        el = $("#selectable1").selectable({ autoRefresh: true,  selected: selected });
        sel.hide();
-       TestHelpers.selectableDrag(1000, 1000);
+       TestHelpers.selectable.drag(el, 1000, 1000);
        equal(actual, 0);
        sel.show();
-       TestHelpers.selectableDrag(1000, 1000);
+       TestHelpers.selectable.drag(el, 1000, 1000);
        equal(actual, sel.length);
        el.selectable("destroy");
        sel.show();
@@ -32,12 +34,15 @@ test("autoRefresh", function() {
 
 test("filter", function() {
        expect(2);
-       el = $("#selectable1");
-       var actual, sel = $("*", el), selected = function() { actual += 1; };
 
-       actual = 0;
+       var actual =0,
+               el = $("#selectable1"),
+               sel = $("*", el),
+               selected = function() { actual += 1; };
+
+
        el = $("#selectable1").selectable({ filter: '.special', selected: selected });
-       TestHelpers.selectableDrag(1000, 1000);
+       TestHelpers.selectable.drag(el, 1000, 1000);
        ok(sel.length !== 1, "this test assumes more than 1 selectee");
        equal(actual, 1);
        el.selectable("destroy");
index 80e32ca7a5e2b4e36fac428c445e34a9f90c5fe1..a9b15b20b7f67fe43a8389e8beba315a3ebcc033 100644 (file)
@@ -25,20 +25,20 @@ $.widget("ui.selectable", $.ui.mouse, {
                tolerance: 'touch'
        },
        _create: function() {
-               var that = this;
+               var selectees,
+                       that = this;
 
                this.element.addClass("ui-selectable");
 
                this.dragged = false;
 
                // cache selectee children based on filter
-               var selectees;
                this.refresh = function() {
                        selectees = $(that.options.filter, that.element[0]);
                        selectees.addClass("ui-selectee");
                        selectees.each(function() {
-                               var $this = $(this);
-                               var pos = $this.offset();
+                               var $this = $(this),
+                                       pos = $this.offset();
                                $.data(this, "selectable-item", {
                                        element: this,
                                        $element: $this,
@@ -72,14 +72,14 @@ $.widget("ui.selectable", $.ui.mouse, {
        },
 
        _mouseStart: function(event) {
-               var that = this;
+               var that = this,
+                       options = this.options;
 
                this.opos = [event.pageX, event.pageY];
 
-               if (this.options.disabled)
+               if (this.options.disabled) {
                        return;
-
-               var options = this.options;
+               }
 
                this.selectees = $(options.filter, this.element[0]);
 
@@ -114,9 +114,10 @@ $.widget("ui.selectable", $.ui.mouse, {
                });
 
                $(event.target).parents().andSelf().each(function() {
-                       var selectee = $.data(this, "selectable-item");
+                       var doSelect,
+                               selectee = $.data(this, "selectable-item");
                        if (selectee) {
-                               var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
+                               doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
                                selectee.$element
                                        .removeClass(doSelect ? "ui-unselecting" : "ui-selected")
                                        .addClass(doSelect ? "ui-selecting" : "ui-unselecting");
@@ -140,28 +141,37 @@ $.widget("ui.selectable", $.ui.mouse, {
        },
 
        _mouseDrag: function(event) {
-               var that = this;
+
                this.dragged = true;
 
-               if (this.options.disabled)
+               if (this.options.disabled) {
                        return;
+               }
 
-               var options = this.options;
+               var tmp,
+                       that = this,
+                       options = this.options,
+                       x1 = this.opos[0],
+                       y1 = this.opos[1],
+                       x2 = event.pageX,
+                       y2 = event.pageY;
 
-               var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
-               if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
-               if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
+               if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; }
+               if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; }
                this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
 
                this.selectees.each(function() {
-                       var selectee = $.data(this, "selectable-item");
+                       var selectee = $.data(this, "selectable-item"),
+                               hit = false;
+
                        //prevent helper from being selected if appendTo: selectable
-                       if (!selectee || selectee.element == that.element[0])
+                       if (!selectee || selectee.element === that.element[0]) {
                                return;
-                       var hit = false;
-                       if (options.tolerance == 'touch') {
+                       }
+
+                       if (options.tolerance === 'touch') {
                                hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
-                       } else if (options.tolerance == 'fit') {
+                       } else if (options.tolerance === 'fit') {
                                hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
                        }
 
@@ -228,8 +238,6 @@ $.widget("ui.selectable", $.ui.mouse, {
 
                this.dragged = false;
 
-               var options = this.options;
-
                $('.ui-unselecting', this.element[0]).each(function() {
                        var selectee = $.data(this, "selectable-item");
                        selectee.$element.removeClass('ui-unselecting');