From 88b909b04ec43443514867f83171cbc9760bb638 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Wed, 31 Mar 2010 16:39:16 +0200 Subject: Autocomplete unit tests: Replace unreliable setTimeout with gobal ajax event handler --- tests/unit/autocomplete/autocomplete_options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js index 6639e9014..c5aa7c961 100644 --- a/tests/unit/autocomplete/autocomplete_options.js +++ b/tests/unit/autocomplete/autocomplete_options.js @@ -120,7 +120,7 @@ function source_test(source, async) { } if (async) { stop(); - setTimeout(result, 100); + $(document).one("ajaxStop", result); } else { result(); } -- cgit v1.2.3 From ab8d15521785e764a6bf47beee0cfd18929607d3 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Thu, 1 Apr 2010 09:24:39 +0200 Subject: Disabling interaction testsuites until we get to their rewrites; required to get 100% passing on TestSwarm now --- tests/unit/draggable/draggable.html | 3 +++ tests/unit/droppable/droppable.html | 3 +++ tests/unit/resizable/resizable.html | 3 +++ tests/unit/selectable/selectable.html | 3 +++ tests/unit/sortable/sortable.html | 3 +++ 5 files changed, 15 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html index a48f3c092..308951c0c 100644 --- a/tests/unit/draggable/draggable.html +++ b/tests/unit/draggable/draggable.html @@ -15,12 +15,15 @@ + + diff --git a/tests/unit/droppable/droppable.html b/tests/unit/droppable/droppable.html index 9f2c14a1d..648afbbaa 100644 --- a/tests/unit/droppable/droppable.html +++ b/tests/unit/droppable/droppable.html @@ -16,12 +16,15 @@ + + diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html index fe100d2aa..2aba18d6e 100644 --- a/tests/unit/resizable/resizable.html +++ b/tests/unit/resizable/resizable.html @@ -17,12 +17,15 @@ + + diff --git a/tests/unit/selectable/selectable.html b/tests/unit/selectable/selectable.html index 74a10584a..b5ac76391 100644 --- a/tests/unit/selectable/selectable.html +++ b/tests/unit/selectable/selectable.html @@ -15,12 +15,15 @@ + + diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html index 2a50f85a1..8d53bfd7f 100644 --- a/tests/unit/sortable/sortable.html +++ b/tests/unit/sortable/sortable.html @@ -15,12 +15,15 @@ + + -- cgit v1.2.3 From eccb95a8cdc539987712956824d947c2d37b2644 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Thu, 1 Apr 2010 09:49:13 +0200 Subject: Tuning disabled testsuites to run with ?draggable that TestSwarm adds --- tests/unit/draggable/draggable.html | 2 +- tests/unit/droppable/droppable.html | 2 +- tests/unit/resizable/resizable.html | 2 +- tests/unit/selectable/selectable.html | 2 +- tests/unit/sortable/sortable.html | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/draggable/draggable.html b/tests/unit/draggable/draggable.html index 308951c0c..050d37704 100644 --- a/tests/unit/draggable/draggable.html +++ b/tests/unit/draggable/draggable.html @@ -23,7 +23,7 @@ --> - + diff --git a/tests/unit/droppable/droppable.html b/tests/unit/droppable/droppable.html index 648afbbaa..bc9a9d416 100644 --- a/tests/unit/droppable/droppable.html +++ b/tests/unit/droppable/droppable.html @@ -24,7 +24,7 @@ --> - + diff --git a/tests/unit/resizable/resizable.html b/tests/unit/resizable/resizable.html index 2aba18d6e..08c4c8798 100644 --- a/tests/unit/resizable/resizable.html +++ b/tests/unit/resizable/resizable.html @@ -25,7 +25,7 @@ --> - + diff --git a/tests/unit/selectable/selectable.html b/tests/unit/selectable/selectable.html index b5ac76391..e71d20e22 100644 --- a/tests/unit/selectable/selectable.html +++ b/tests/unit/selectable/selectable.html @@ -23,7 +23,7 @@ --> - + diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html index 8d53bfd7f..f956d6df0 100644 --- a/tests/unit/sortable/sortable.html +++ b/tests/unit/sortable/sortable.html @@ -23,7 +23,7 @@ --> - + -- cgit v1.2.3 From 5ffd3ab36a6c7d6c0aaad7d84c20b8d78c149a1f Mon Sep 17 00:00:00 2001 From: "Richard D. Worth" Date: Thu, 1 Apr 2010 15:00:45 -0400 Subject: Align slider value to step. Fixes #5471 - value not aligned to step when set programatically --- tests/unit/slider/slider_options.js | 41 +++++++++++++++++++++++++++++++++---- ui/jquery.ui.slider.js | 41 ++++++++++++++++++++----------------- 2 files changed, 59 insertions(+), 23 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/slider/slider_options.js b/tests/unit/slider/slider_options.js index cc36923b3..b9a766539 100644 --- a/tests/unit/slider/slider_options.js +++ b/tests/unit/slider/slider_options.js @@ -88,17 +88,50 @@ test("range", function() { ok(false, "missing test - untested code is broken code."); }); +//spec: http://wiki.jqueryui.com/Slider#specs +// value option/method: the value option is not restricted by min/max/step. +// What is returned by the value method is restricted by min (>=), max (<=), and step (even multiple) test("step", function() { var el = $('
').slider({ - step: 10 + min: 0, + value: 0, + step: 10, + max: 100, }); - equals( el.slider("value"), 0 ) + equals( el.slider("value"), 0 ); + el.slider("value", 1); + equals( el.slider("value"), 0 ); + + el.slider("value", 9); equals( el.slider("value"), 10 ); - el.slider("value", 10); - equals( el.slider("value"), 10 ); + el.slider("value", 11); + equals( el.slider("value"), 10 ); + + el.slider("value", 19); equals( el.slider("value"), 20 ); + +el = $('
').slider({ + min: 0, + value: 0, + step: 20, + max: 100, + }); + el.slider("value", 0); + + el.slider("option", "value", 1); + equals( el.slider("value"), 0 ); + + el.slider("option", "value", 9); + equals( el.slider("value"), 0 ); + + el.slider("option", "value", 11); + equals( el.slider("value"), 20 ); + + el.slider("option", "value", 19); + equals( el.slider("value"), 20 ); + el.slider('destroy'); }); diff --git a/ui/jquery.ui.slider.js b/ui/jquery.ui.slider.js index 185fe809c..dd79cb730 100644 --- a/ui/jquery.ui.slider.js +++ b/ui/jquery.ui.slider.js @@ -340,17 +340,9 @@ $.widget("ui.slider", $.ui.mouse, { percentMouse = 1 - percentMouse; var valueTotal = this._valueMax() - this._valueMin(), - valueMouse = percentMouse * valueTotal, - valueMouseModStep = valueMouse % this.options.step, - normValue = this._valueMin() + valueMouse - valueMouseModStep; - - if (valueMouseModStep > (this.options.step / 2)) - normValue += this.options.step; - - // Since JavaScript has problems with large floats, round - // the final value to 5 digits after the decimal point (see #4124) - return parseFloat(normValue.toFixed(5)); + valueMouse = percentMouse * valueTotal; + return this._trimAlignValue(valueMouse); }, _start: function(event, index) { @@ -440,7 +432,7 @@ $.widget("ui.slider", $.ui.mouse, { value: function(newValue) { if (arguments.length) { - this.options.value = this._trimValue(newValue); + this.options.value = this._trimAlignValue(newValue); this._refreshValue(); this._change(null, 0); } @@ -452,7 +444,7 @@ $.widget("ui.slider", $.ui.mouse, { values: function(index, newValue) { if (arguments.length > 1) { - this.options.values[index] = this._trimValue(newValue); + this.options.values[index] = this._trimAlignValue(newValue); this._refreshValue(); this._change(null, index); } @@ -461,7 +453,7 @@ $.widget("ui.slider", $.ui.mouse, { if ($.isArray(arguments[0])) { var vals = this.options.values, newValues = arguments[0]; for (var i = 0, l = vals.length; i < l; i++) { - vals[i] = this._trimValue(newValues[i]); + vals[i] = this._trimAlignValue(newValues[i]); this._change(null, i); } this._refreshValue(); @@ -528,9 +520,9 @@ $.widget("ui.slider", $.ui.mouse, { _value: function() { //internal value getter - // _value() returns value trimmed by min and max + // _value() returns value trimmed by min and max, aligned by step var val = this.options.value; - val = this._trimValue(val); + val = this._trimAlignValue(val); return val; }, @@ -542,7 +534,7 @@ $.widget("ui.slider", $.ui.mouse, { if (arguments.length) { var val = this.options.values[index]; - val = this._trimValue(val); + val = this._trimAlignValue(val); return val; } else { @@ -550,7 +542,7 @@ $.widget("ui.slider", $.ui.mouse, { // this copy gets trimmed by min and max and then returned var vals = this.options.values.slice(); for (var i = 0, l = vals.length; i < l; i++) { - vals[i] = this._trimValue(vals[i]); + vals[i] = this._trimAlignValue(vals[i]); } return vals; @@ -558,14 +550,25 @@ $.widget("ui.slider", $.ui.mouse, { }, - _trimValue: function(val) { + // returns the step-aligned value that val is closest to, between (inclusive) min and max + _trimAlignValue: function(val) { if (val < this._valueMin()) { return this._valueMin(); } if (val > this._valueMax()) { return this._valueMax(); } - return val; + var step = this.options.step, + valModStep = val % step, + alignValue = this._valueMin() + val - valModStep; + + if (valModStep >= (step / 2)) { + alignValue += step; + } + + // Since JavaScript has problems with large floats, round + // the final value to 5 digits after the decimal point (see #4124) + return parseFloat(alignValue.toFixed(5)); }, _valueMin: function() { -- cgit v1.2.3 From 178c3b5b6ea39ccd3c8ebd252857cf0a47e81840 Mon Sep 17 00:00:00 2001 From: "Richard D. Worth" Date: Fri, 2 Apr 2010 11:59:17 -0400 Subject: tabs: core ajax unit test - run two loads as two separate asyncs so IE7 will run remaining tests --- tests/unit/tabs/tabs_core.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/tabs/tabs_core.js b/tests/unit/tabs/tabs_core.js index 20ab2b1fd..641f1f2e1 100644 --- a/tests/unit/tabs/tabs_core.js +++ b/tests/unit/tabs/tabs_core.js @@ -35,6 +35,8 @@ test('ajax', function() { selected: 2, load: function() { // spinner: default spinner + start(); + stop(); equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed"); equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed"); el.tabs('destroy'); -- cgit v1.2.3 From 9ba45f3b76bba7daeb341b2c44fc1ad17ac412ab Mon Sep 17 00:00:00 2001 From: "Richard D. Worth" Date: Fri, 2 Apr 2010 12:43:22 -0400 Subject: tabs: core ajax unit test - more refactoring, seems IE7 needs a quick setTimeout for the first async test to work on first load --- tests/unit/tabs/tabs_core.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/tabs/tabs_core.js b/tests/unit/tabs/tabs_core.js index 641f1f2e1..652788bba 100644 --- a/tests/unit/tabs/tabs_core.js +++ b/tests/unit/tabs/tabs_core.js @@ -35,21 +35,21 @@ test('ajax', function() { selected: 2, load: function() { // spinner: default spinner - start(); - stop(); - equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed"); - equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed"); - el.tabs('destroy'); - el.tabs({ - selected: 2, - spinner: '', - load: function() { - // spinner: image - equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed"); - equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed"); - start(); - } - }); + setTimeout(function() { + equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed"); + equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed"); + el.tabs('destroy'); + el.tabs({ + selected: 2, + spinner: '', + load: function() { + // spinner: image + equals($('li:eq(2) > a > span', el).length, 1, "should restore tab markup after spinner is removed"); + equals($('li:eq(2) > a > span', el).html(), '3', "should restore tab label after spinner is removed"); + start(); + } + }); + }, 1); } }); -- cgit v1.2.3 From ad5bfc7f604bf298ecfeac77db50081fc33dbfd0 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:08:45 +0200 Subject: Accordion unit tests: Refactored state-helper function --- tests/unit/accordion/accordion.html | 12 ++++++++++++ tests/unit/accordion/accordion_core.js | 11 ----------- tests/unit/accordion/accordion_methods.js | 9 --------- tests/unit/accordion/accordion_options.js | 10 ---------- 4 files changed, 12 insertions(+), 30 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index df0979803..9b6cb63f2 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -16,6 +16,18 @@ + diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index 47d2509e6..2bef43149 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -5,17 +5,6 @@ (function($) { -$.ui.accordion.prototype.options.animated = false; - -function state(accordion) { - var args = $.makeArray(arguments).slice(1); - var result = []; - $.each(args, function(i, n) { - result.push( accordion.find(".ui-accordion-content").eq(i).is(":visible") ? 1 : 0 ); - }); - same(args, result) -} - module("accordion: core"); test("handle click on header-descendant", function() { diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index d15a0b710..c31f22008 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -3,15 +3,6 @@ */ (function($) { -function state(accordion) { - var expected = $.makeArray(arguments).slice(1); - var actual = []; - $.each(expected, function(i, n) { - actual.push( accordion.find(".ui-accordion-content").eq(i).is(":visible") ? 1 : 0 ); - }); - same(actual, expected) -} - module("accordion: methods"); test("init", function() { diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index cc7fc0369..e46795993 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -3,16 +3,6 @@ */ (function($) { -function state(accordion) { - var expected = $.makeArray(arguments).slice(1); - var actual = []; - $.each(expected, function(i, n) { - actual.push( accordion.find(".ui-accordion-content").eq(i).is(":visible") ? 1 : 0 ); - }); - same(actual, expected) -} - - module("accordion: options"); test("{ active: first child }, default", function() { -- cgit v1.2.3 From da0fe50ec5c6ce6a7e59deb936d341b0af1ae912 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:10:50 +0200 Subject: Accordion unit tests: Use display!=none instead of :visible to work around :visible issue in IE8 --- tests/unit/accordion/accordion.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 9b6cb63f2..2b4ae2045 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -23,7 +23,9 @@ var args = $.makeArray(arguments).slice(1); var result = []; $.each(args, function(i, n) { - result.push( accordion.find(".ui-accordion-content").eq(i).is(":visible") ? 1 : 0 ); + result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() { + return $(this).css("display") != "none" + }).length ? 1 : 0 ); }); same(args, result) } -- cgit v1.2.3 From cf2b0ca0d8b803c046e219dd6efed120f8e14fea Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:14:58 +0200 Subject: Accordion unit tests: Cleanup --- tests/unit/accordion/accordion_methods.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index c31f22008..37807964a 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -103,8 +103,7 @@ test("activate, string expression", function() { ac.accordion("activate", ":last"); state(ac, 0, 0, 1); }); -//[ 0, 1, 1 ] result: [ 0, 0, 1 ] -//[ 0, 1, 1] result: [ 0, 0, 1] + test("activate, jQuery or DOM element", function() { var ac = $('#list1').accordion({ active: $("#list1 a:last") }); state(ac, 0, 0, 1); -- cgit v1.2.3 From 7d1c9cd3484b3705ce570468146431e31e7d4847 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:21:31 +0200 Subject: Accordion: Rewrote the resize method test; fails in IE8, probably related to :visible issue --- tests/unit/accordion/accordion.html | 2 +- tests/unit/accordion/accordion_methods.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 2b4ae2045..b54db7c33 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -39,7 +39,7 @@ diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index 37807964a..22b19a75a 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -114,7 +114,9 @@ test("activate, jQuery or DOM element", function() { }); test("resize", function() { - var expected = $('#list1').accordion(); + var expected = $('#list1').accordion({ + fillSpace: true + }); var sizes = []; expected.find(".ui-accordion-content").each(function() { @@ -128,10 +130,15 @@ test("resize", function() { expected.find(".ui-accordion-content").each(function() { sizes2.push($(this).outerHeight()); }); - same(sizes, sizes2); + same(sizes, [38, 38, 38]); - expected.find(".ui-accordion-content:first").height(500) - var sizes3 = []; + expected.parent().height(500); + expected.accordion("resize"); + var sizes2 = []; + expected.find(".ui-accordion-content").each(function() { + sizes2.push($(this).outerHeight()); + }); + same(sizes2, [446, 446, 446]); }); })(jQuery); -- cgit v1.2.3 From 7902d3945fc99e0718622f65690dd8556fea40c7 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:27:00 +0200 Subject: Accordion: Improved resize-method test, starting with a fixed container height --- tests/unit/accordion/accordion_methods.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index 22b19a75a..894d1f30c 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -114,7 +114,7 @@ test("activate, jQuery or DOM element", function() { }); test("resize", function() { - var expected = $('#list1').accordion({ + var expected = $('#list1').parent().height(300).end().accordion({ fillSpace: true }); @@ -130,7 +130,7 @@ test("resize", function() { expected.find(".ui-accordion-content").each(function() { sizes2.push($(this).outerHeight()); }); - same(sizes, [38, 38, 38]); + same(sizes, [246, 246, 246]); expected.parent().height(500); expected.accordion("resize"); -- cgit v1.2.3 From 6d5e9b5e7acb8f5b676d9027d899ef7feb013fd7 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:31:04 +0200 Subject: Accordion: more useless markup for getting consistent results for the destroy test --- tests/unit/accordion/accordion.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index b54db7c33..765048c32 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -55,7 +55,7 @@
There is one obvious advantage: -
+

You've seen it coming!
@@ -65,7 +65,7 @@

Now that you've got... -
+

your bear, you have to admit it!
@@ -76,7 +76,7 @@

Rent one bear, ... -
+

get two for three beer.

-- cgit v1.2.3 From d9c0b626cfc6a12a9b469eaa9f67a0e569499461 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:35:02 +0200 Subject: Accordion: Trying some styl resets, maybe finding the one for Safari 3.x --- tests/unit/accordion/accordion.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 765048c32..26b0355e9 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -39,7 +39,7 @@ -- cgit v1.2.3 From 0cb9c7d96330e972b983452280bd11c57ddfb35f Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Sat, 3 Apr 2010 17:48:39 +0200 Subject: Accordion: different useless markup for getting consistent results for the destroy test --- tests/unit/accordion/accordion.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 26b0355e9..3badebda9 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -55,7 +55,7 @@
There is one obvious advantage: -
+

You've seen it coming!
@@ -65,7 +65,7 @@

Now that you've got... -
+

your bear, you have to admit it!
@@ -76,7 +76,7 @@

Rent one bear, ... -
+

get two for three beer.

-- cgit v1.2.3 From c01b3baef97808a3a7dfafaea084c03a27e92564 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Thu, 8 Apr 2010 12:05:52 +0200 Subject: Autocomplete: Track input changes and fire change-event on blur, along with selected item, if available. Fix for #5490 --- tests/unit/autocomplete/autocomplete_events.js | 25 +++++++++++++++++++++---- ui/jquery.ui.autocomplete.js | 11 +++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/autocomplete/autocomplete_events.js b/tests/unit/autocomplete/autocomplete_events.js index ccbe66c1b..28a72145e 100644 --- a/tests/unit/autocomplete/autocomplete_events.js +++ b/tests/unit/autocomplete/autocomplete_events.js @@ -12,7 +12,7 @@ module("autocomplete: events", { var data = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"]; test("all events", function() { - expect(11); + expect(12); var ac = $("#autocomplete").autocomplete({ delay: 0, source: data, @@ -34,21 +34,38 @@ test("all events", function() { same(event.type, "autocompleteselect"); same(ui.item, {label:"java", value:"java"}); }, - change: function(event) { + change: function(event, ui) { same(event.type, "autocompletechange"); + same(ui.item, {label:"java", value:"java"}); same( $(".ui-menu:visible").length, 0 ); + start(); } }); stop(); - ac.val("ja").keydown(); + ac.focus().val("ja").keydown(); setTimeout(function() { same( $(".ui-menu:visible").length, 1 ); ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); ac.simulate("keydown", { keyCode: $.ui.keyCode.ENTER }); - start(); + ac.blur(); }, 50); }); +test("change without selection", function() { + expect(2); + stop(); + var ac = $("#autocomplete").autocomplete({ + delay: 0, + source: data, + change: function(event, ui) { + same(event.type, "autocompletechange"); + same(ui.item, null); + start(); + } + }); + ac.focus().val("ja").blur(); +}); + test("cancel search", function() { expect(6); var first = true; diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index a1d798c59..14a19e4b2 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -83,6 +83,7 @@ $.widget( "ui.autocomplete", { } }) .bind( "focus.autocomplete", function() { + self.selectedItem = null; self.previous = self.element.val(); }) .bind( "blur.autocomplete", function( event ) { @@ -91,6 +92,7 @@ $.widget( "ui.autocomplete", { // TODO try to implement this without a timeout, see clearTimeout in search() self.closing = setTimeout(function() { self.close( event ); + self._change( event ); }, 150 ); }); this._initSource(); @@ -116,11 +118,13 @@ $.widget( "ui.autocomplete", { self.element.val( item.value ); } self.close( event ); - self.previous = self.element.val(); // only trigger when focus was lost (click on menu) + var previous = self.previous; if ( self.element[0] !== doc.activeElement ) { self.element.focus(); + self.previous = previous; } + self.selectedItem = item; }, blur: function( event, ui ) { if ( self.menu.element.is(":visible") ) { @@ -219,8 +223,11 @@ $.widget( "ui.autocomplete", { this.menu.element.hide(); this.menu.deactivate(); } + }, + + _change: function( event ) { if ( this.previous !== this.element.val() ) { - this._trigger( "change", event ); + this._trigger( "change", event, { item: this.selectedItem } ); } }, -- cgit v1.2.3