jenkins-bot has submitted this change and it was merged.

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(-)

Approvals:
  Hoo man: Looks good to me, but someone else must approve
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



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..8dd7eba 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: merged
Gerrit-Change-Id: I53d2584f50dc04f8c4107656e8becab367545699
Gerrit-PatchSet: 2
Gerrit-Project: data-values/value-view
Gerrit-Branch: master
Gerrit-Owner: Thiemo M├Ąttig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to