Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/315684
Change subject: Add search() integration test for jquery.ui.commonssuggester ...................................................................... Add search() integration test for jquery.ui.commonssuggester Bug: T147917 Change-Id: I53d2584f50dc04f8c4107656e8becab367545699 --- M lib/jquery.ui/jquery.ui.commonssuggester.js M tests/lib/jquery.ui/jquery.ui.commonssuggester.tests.js M tests/lib/jquery.ui/jquery.ui.suggester.tests.js 3 files changed, 44 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/data-values/value-view refs/changes/84/315684/1 diff --git a/lib/jquery.ui/jquery.ui.commonssuggester.js b/lib/jquery.ui/jquery.ui.commonssuggester.js index 6979cf5..2720637 100644 --- a/lib/jquery.ui/jquery.ui.commonssuggester.js +++ b/lib/jquery.ui/jquery.ui.commonssuggester.js @@ -14,6 +14,14 @@ * @constructor */ $.widget( 'ui.commonssuggester', $.ui.suggester, { + + /** + * @see jQuery.ui.suggester.options + */ + options: { + ajax: $.ajax + }, + /** * @inheritdoc * @protected @@ -37,7 +45,7 @@ return function( term ) { var deferred = $.Deferred(); - $.ajax( { + self.options.ajax( { url: 'https://commons.wikimedia.org/w/api.php', dataType: 'jsonp', data: { diff --git a/tests/lib/jquery.ui/jquery.ui.commonssuggester.tests.js b/tests/lib/jquery.ui/jquery.ui.commonssuggester.tests.js index 54b0d77..fa779ec 100644 --- a/tests/lib/jquery.ui/jquery.ui.commonssuggester.tests.js +++ b/tests/lib/jquery.ui/jquery.ui.commonssuggester.tests.js @@ -5,11 +5,15 @@ ( function( $, QUnit ) { 'use strict'; - var newTestSuggester = function() { + /** + * @param {Object} [options] + * @return {jQuery} + */ + var newTestSuggester = function( options ) { return $( '<input>' ) .addClass( 'test_suggester' ) .appendTo( 'body' ) - .commonssuggester(); + .commonssuggester( options ); }; QUnit.module( 'jquery.ui.commonssuggester', { @@ -73,16 +77,38 @@ // Do not do anything with invalid URL encoding '1%': '1%', 'title=1%.jpg': 'title=1%.jpg' - }; + }, + numberOfTestCases = Object.keys( testCases ).length; - assert.expect( Object.keys( testCases ).length ); + assert.expect( numberOfTestCases ); - for ( var input in testCases ) { - var actual = suggester._grepFileTitleFromTerm( input ), - expected = testCases[input]; + $.each( testCases, function( input, expected ) { + var actual = suggester._grepFileTitleFromTerm( input ); assert.strictEqual( actual, expected ); - } + } ); + } ); + + QUnit.test( 'search integration', function( assert ) { + assert.expect( 2 ); + var $suggester = newTestSuggester( { ajax: function( options ) { + var response = [ , [] ]; + + response[1]._requestTerm = options.data.search; + + return $.Deferred().resolve( response ).promise(); + } } ), + suggester = $suggester.data( 'commonssuggester' ), + input = 'title=Foo/Bar', + done = assert.async(); + + $suggester.val( input ); + suggester.search().done( function( suggestions, term ) { + assert.strictEqual( suggestions._requestTerm, 'Bar' ); + assert.strictEqual( term, input ); + + done(); + } ); } ); }( jQuery, QUnit ) ); diff --git a/tests/lib/jquery.ui/jquery.ui.suggester.tests.js b/tests/lib/jquery.ui/jquery.ui.suggester.tests.js index 7be3e36..51cf201 100644 --- a/tests/lib/jquery.ui/jquery.ui.suggester.tests.js +++ b/tests/lib/jquery.ui/jquery.ui.suggester.tests.js @@ -17,6 +17,7 @@ * Factory creating a jQuery.ui.suggester widget suitable for testing. * * @param {Object} [options] + * @return {jQuery} */ var newTestSuggester = function( options ) { options = $.extend( { -- To view, visit https://gerrit.wikimedia.org/r/315684 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I53d2584f50dc04f8c4107656e8becab367545699 Gerrit-PatchSet: 1 Gerrit-Project: data-values/value-view Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits