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

Change subject: Rewrite wikidata description search test
......................................................................


Rewrite wikidata description search test

The test actually checks the behaviour of the SearchApi::search method
for the beta module, so simplify the test to check the bare minimum.

In the process get it to work as expected in plain mode.

Bug: T106622
Change-Id: I21b332263c1a7b8a45ba2b5040ef06facca66c12
---
A tests/qunit/mobile.search.beta/test_SearchApi.js
D tests/qunit/mobile.search/test_SearchOverlay.js
2 files changed, 81 insertions(+), 94 deletions(-)

Approvals:
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/qunit/mobile.search.beta/test_SearchApi.js 
b/tests/qunit/mobile.search.beta/test_SearchApi.js
new file mode 100644
index 0000000..909f4ce
--- /dev/null
+++ b/tests/qunit/mobile.search.beta/test_SearchApi.js
@@ -0,0 +1,81 @@
+( function ( $, M ) {
+
+       var SearchApi = M.require( 'modules/search.beta/SearchApi' );
+
+       QUnit.module( 'MobileFrontend SearchApi', {
+               setup: function () {
+                       var data = {
+                               query: {
+                                       pages: {
+                                               2: {
+                                                       pageid: 2,
+                                                       ns: 0,
+                                                       title: 'Brad Pitt',
+                                                       index: 2,
+                                                       terms: {
+                                                               description: [ 
'American actor' ]
+                                                       }
+                                               },
+                                               4: {
+                                                       pageid: 4,
+                                                       ns: 0,
+                                                       title: 'Bradley Cooper',
+                                                       index: 3,
+                                                       terms: {
+                                                               description: [ 
'American actor and film producer' ]
+                                                       }
+                                               },
+                                               5: {
+                                                       pageid: 5,
+                                                       ns: 0,
+                                                       title: 'Braddy',
+                                                       index: 1
+                                               }
+                                       },
+                                       prefixsearch: [
+                                               {
+                                                       ns: 0,
+                                                       title: 'Braddy',
+                                                       pageid: 5
+                                               },
+                                               {
+                                                       ns: 0,
+                                                       title: 'Brad Pitt',
+                                                       pageid: 2
+                                               },
+                                               {
+                                                       ns: 0,
+                                                       title: 'Bradley Cooper',
+                                                       pageid: 4
+                                               }
+                                       ]
+                               }
+                       };
+                       this.stub( SearchApi.prototype, 'get' ).returns( 
$.Deferred().resolve( data ) );
+               }
+       } );
+
+       QUnit.asyncTest( 'Wikidata Description in search results', 3, function 
( assert ) {
+               var searchApi = new SearchApi();
+               searchApi.search( 'brad' ).done( function ( resp ) {
+                       var results = resp.results;
+                       QUnit.start();
+                       assert.ok(
+                               results[0].wikidataDescription === undefined,
+                               'Braddy does not have a Wikidata description.'
+                       );
+                       assert.equal(
+                               results[1].wikidataDescription,
+                               'American actor',
+                               'Yes, Brad Pitt is an actor.'
+                       );
+                       assert.equal(
+                               results[2].wikidataDescription,
+                               'American actor and film producer',
+                               'Yes, Cooper is an actor.'
+                       );
+               } );
+
+       } );
+
+}( jQuery, mw.mobileFrontend ) );
diff --git a/tests/qunit/mobile.search/test_SearchOverlay.js 
b/tests/qunit/mobile.search/test_SearchOverlay.js
deleted file mode 100644
index f20a151..0000000
--- a/tests/qunit/mobile.search/test_SearchOverlay.js
+++ /dev/null
@@ -1,94 +0,0 @@
-( function ( $, M ) {
-
-       var SearchOverlay = M.require( 'modules/search/SearchOverlay' );
-
-       QUnit.module( 'MobileFrontend SearchOverlay', {
-       } );
-
-       QUnit.asyncTest( 'Wikidata Description in search results', 3, function 
( assert ) {
-               var self = this,
-                       deferred = $.Deferred(),
-                       data = {
-                               query: {
-                                       pages: {
-                                               2: {
-                                                       pageid: 2,
-                                                       ns: 0,
-                                                       title: 'Brad Pitt',
-                                                       index: 2,
-                                                       terms: {
-                                                               description: [ 
'American actor' ]
-                                                       }
-                                               },
-                                               4: {
-                                                       pageid: 4,
-                                                       ns: 0,
-                                                       title: 'Bradley Cooper',
-                                                       index: 3,
-                                                       terms: {
-                                                               description: [ 
'American actor and film producer' ]
-                                                       }
-                                               },
-                                               5: {
-                                                       pageid: 5,
-                                                       ns: 0,
-                                                       title: 'Braddy',
-                                                       index: 1
-                                               }
-                                       },
-                                       prefixsearch: [
-                                               {
-                                                       ns: 0,
-                                                       title: 'Braddy',
-                                                       pageid: 5
-                                               },
-                                               {
-                                                       ns: 0,
-                                                       title: 'Brad Pitt',
-                                                       pageid: 2
-                                               },
-                                               {
-                                                       ns: 0,
-                                                       title: 'Bradley Cooper',
-                                                       pageid: 4
-                                               }
-                                       ]
-                               }
-                       },
-                       SearchApi,
-                       searchOverlay;
-
-               mw.loader.using( 'mobile.search.beta' ).done( function () {
-                       SearchApi = M.require( 'modules/search.beta/SearchApi' 
);
-                       self.stub( SearchApi.prototype, 'get' ).returns( 
deferred.promise() );
-                       deferred.resolve( data );
-                       searchOverlay = new SearchOverlay( {
-                               api: new SearchApi()
-                       } );
-                       searchOverlay.$el.find( 'input' ).val( 'brad' );
-                       M.on( 'search-results', function () {
-                               var $pageSummaries = searchOverlay.$el.find( 
'.page-summary' );
-
-                               QUnit.start();
-                               assert.equal(
-                                       $pageSummaries.eq( 0 ).find( 
'.wikidata-description' ).length,
-                                       0,
-                                       'Braddy does not have a Wikidata 
description.'
-                               );
-                               assert.equal(
-                                       $pageSummaries.eq( 1 ).find( 
'.wikidata-description' ).text(),
-                                       'American actor',
-                                       'Yes, Brad Pitt is an actor.'
-                               );
-                               assert.equal(
-                                       $pageSummaries.eq( 2 ).find( 
'.wikidata-description' ).text(),
-                                       'American actor and film producer',
-                                       'Yes, Cooper is an actor.'
-                               );
-                       } );
-                       searchOverlay.performSearch();
-               } );
-
-       } );
-
-}( jQuery, mw.mobileFrontend ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/226942
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I21b332263c1a7b8a45ba2b5040ef06facca66c12
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: BarryTheBrowserTestBot <jdlrobson+ba...@gmail.com>
Gerrit-Reviewer: Bmansurov <bmansu...@wikimedia.org>
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