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

Change subject: Hygiene: Convert WatchstarApi to a gateway
......................................................................


Hygiene: Convert WatchstarApi to a gateway

Convert WatchstarApi to the new gateway concept.

Changes:
* Renames WatchListGateway::load to loadWatchlist to avoid confusion
with WatchstarGateway:load. Rename WatchstarGateway:load to
loadWatchStatus
* isWatchedPage no longer throws an exception under any circumstance
Bug: T113753
Change-Id: I6a5b43afebb355589dcb510755563933b076f31f
---
M includes/Resources.php
M resources/mobile.pagelist.scripts/WatchstarPageList.js
M resources/mobile.search/SearchOverlay.js
M resources/mobile.watchlist/WatchList.js
M resources/mobile.watchlist/WatchListGateway.js
M resources/mobile.watchstar/Watchstar.js
R resources/mobile.watchstar/WatchstarGateway.js
M resources/skins.minerva.scripts/search.js
M resources/skins.minerva.watchstar/init.js
M tests/qunit/mobile.nearby/test_Nearby.js
M tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js
M tests/qunit/mobile.watchlist/test_WatchListGateway.js
M tests/qunit/mobile.watchstar/test_Watchstar.js
D tests/qunit/mobile.watchstar/test_WatchstarApi.js
A tests/qunit/mobile.watchstar/test_WatchstarGateway.js
15 files changed, 117 insertions(+), 97 deletions(-)

Approvals:
  Jhobs: Looks good to me, but someone else must approve
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Resources.php b/includes/Resources.php
index dad4e7b..8dc8884 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -976,7 +976,7 @@
                        'mobile.loggingSchemas',
                ),
                'scripts' => array(
-                       'resources/mobile.watchstar/WatchstarApi.js',
+                       'resources/mobile.watchstar/WatchstarGateway.js',
                        'resources/mobile.watchstar/Watchstar.js',
                ),
                'styles' => array(
diff --git a/resources/mobile.pagelist.scripts/WatchstarPageList.js 
b/resources/mobile.pagelist.scripts/WatchstarPageList.js
index 8526554..ce777cb 100644
--- a/resources/mobile.pagelist.scripts/WatchstarPageList.js
+++ b/resources/mobile.pagelist.scripts/WatchstarPageList.js
@@ -4,24 +4,29 @@
                mWatchstar,
                PageList = M.require( 'mobile.pagelist/PageList' ),
                Watchstar = M.require( 'mobile.watchstar/Watchstar' ),
-               WatchstarApi = M.require( 'mobile.watchstar/WatchstarApi' ),
                user = M.require( 'mobile.user/user' ),
-               Page = M.require( 'mobile.startup/Page' );
+               Page = M.require( 'mobile.startup/Page' ),
+               WatchstarGateway = M.require( 
'mobile.watchstar/WatchstarGateway' );
 
        /**
         * List of items page view
         * @class WatchstarPageList
         * @uses Page
-        * @uses WatchstarApi
+        * @uses WatchstarGateway
         * @uses Watchstar
         * @extends View
         */
        WatchstarPageList = PageList.extend( {
                /**
                 * @inheritdoc
+                * @cfg {Object} defaults Default options hash.
+                * @cfg {Api} defaults.api
+                */
+               /**
+                * @inheritdoc
                 */
                initialize: function ( options ) {
-                       this.api = new WatchstarApi( options );
+                       this.wsGateway = new WatchstarGateway( options.api );
                        PageList.prototype.initialize.apply( this, arguments );
                },
                /**
@@ -32,7 +37,7 @@
                 * @return {jQuery.Deferred}
                 */
                getPages: function ( ids ) {
-                       return this.api.load( ids );
+                       return this.wsGateway.loadWatchStatus( ids );
                },
                /**
                 * @inheritdoc
@@ -41,7 +46,7 @@
                        var $li,
                                self = this,
                                pages = [],
-                               api = this.api;
+                               gateway = this.wsGateway;
 
                        PageList.prototype.postRender.apply( this );
 
@@ -67,9 +72,10 @@
                                                        } );
 
                                                watchstar = new Watchstar( {
+                                                       api: self.options.api,
                                                        funnel: 
self.options.funnel,
                                                        isAnon: false,
-                                                       isWatched: 
api.isWatchedPage( page ),
+                                                       isWatched: 
gateway.isWatchedPage( page ),
                                                        page: page,
                                                        el: $( '<div>' 
).appendTo( this )
                                                } );
diff --git a/resources/mobile.search/SearchOverlay.js 
b/resources/mobile.search/SearchOverlay.js
index ea91af5..059c2f0 100644
--- a/resources/mobile.search/SearchOverlay.js
+++ b/resources/mobile.search/SearchOverlay.js
@@ -28,7 +28,8 @@
                /**
                 * @inheritdoc
                 * @cfg {Object} defaults Default options hash.
-                * @cfg {SearchGateway} defaults.gateway An API gateway to use 
to retrieve search results
+                * @cfg {SearchGateway} defaults.gatewayClass The class to use 
to setup an API gateway.
+                *  FIXME: Should be removed when wikidata descriptions in 
stable (T101719)
                 * @cfg {Object} defaults.clearIcon options for the button that 
clears the search text.
                 * @cfg {Object} defaults.searchContentIcon options for the 
button that allows you to search within content
                 * @cfg {String} defaults.searchTerm Search text.
@@ -103,7 +104,8 @@
                initialize: function ( options ) {
                        var self = this;
                        Overlay.prototype.initialize.call( this, options );
-                       this.gateway = options.gateway;
+                       this.api = options.api;
+                       this.gateway = new options.gatewayClass( this.api );
 
                        // FIXME: Remove when search registers route with 
overlay manager
                        // we need this because of the focus/delay hack in 
search.js
@@ -293,6 +295,7 @@
                performSearch: function () {
                        var
                                self = this,
+                               api = this.api,
                                pageList,
                                query = this.$input.val(),
                                $resultContainer = this.$( '.results' );
@@ -334,6 +337,7 @@
                                                                        .show();
                                                                self.$( 
'.spinner' ).hide();
                                                                pageList = new 
WatchstarPageList( {
+                                                                       api: 
api,
                                                                        funnel: 
'search',
                                                                        pages: 
data.results,
                                                                        el: 
$resultContainer
diff --git a/resources/mobile.watchlist/WatchList.js 
b/resources/mobile.watchlist/WatchList.js
index 03ea561..aa3435b 100644
--- a/resources/mobile.watchlist/WatchList.js
+++ b/resources/mobile.watchlist/WatchList.js
@@ -39,7 +39,7 @@
                 * @return {jQuery.Deferred}
                 */
                getPages: function ( ids ) {
-                       return this.api.load( ids, true );
+                       return this.wsGateway.loadWatchStatus( ids, true );
                },
                /**
                 * Also sets a watch uploads funnel.
@@ -55,7 +55,7 @@
                 */
                _loadPages: function () {
                        var self = this;
-                       this.gateway.load().done( function ( pages ) {
+                       this.gateway.loadWatchlist().done( function ( pages ) {
                                $.each( pages, function ( i, page ) {
                                        self.appendPage( page );
                                } );
diff --git a/resources/mobile.watchlist/WatchListGateway.js 
b/resources/mobile.watchlist/WatchListGateway.js
index 1b34abd..3b1e50c 100644
--- a/resources/mobile.watchlist/WatchListGateway.js
+++ b/resources/mobile.watchlist/WatchListGateway.js
@@ -31,7 +31,7 @@
                 * Load the list of items on the watchlist
                 * @returns {jQuery.Deferred}
                 */
-               load: function () {
+               loadWatchlist: function () {
                        var self = this,
                                params = $.extend( {
                                        action: 'query',
diff --git a/resources/mobile.watchstar/Watchstar.js 
b/resources/mobile.watchstar/Watchstar.js
index f4a9477..79c3e06 100644
--- a/resources/mobile.watchstar/Watchstar.js
+++ b/resources/mobile.watchstar/Watchstar.js
@@ -3,7 +3,7 @@
        var Watchstar,
                View = M.require( 'mobile.view/View' ),
                SchemaMobileWebWatching = M.require( 
'mobile.loggingSchemas/SchemaMobileWebWatching' ),
-               WatchstarApi = M.require( 'mobile.watchstar/WatchstarApi' ),
+               WatchstarGateway = M.require( 
'mobile.watchstar/WatchstarGateway' ),
                Icon = M.require( 'mobile.startup/Icon' ),
                watchIcon = new Icon( {
                        name: 'watch',
@@ -15,7 +15,6 @@
                } ),
                toast = M.require( 'mobile.toast/toast' ),
                user = M.require( 'mobile.user/user' ),
-               api = new WatchstarApi(),
                CtaDrawer = M.require( 'mobile.drawers/CtaDrawer' );
 
        /**
@@ -24,7 +23,7 @@
         * @extends View
         * @uses CtaDrawer
         * @uses Icon
-        * @uses WatchstarApi
+        * @uses WatchstarGateway
         * @uses Toast
         */
        Watchstar = View.extend( {
@@ -38,6 +37,7 @@
                },
                /**
                 * @cfg {Object} defaults Default options hash.
+                * @cfg {mw.Api} defaults.api
                 * @cfg {Page} defaults.page Current page.
                 * @cfg {String} defaults.funnel to log events with
                 */
@@ -68,15 +68,19 @@
                                _super = View.prototype.initialize,
                                page = options.page;
 
+                       // FIXME: Remove default when Gather has been updated 
to use new gateway. (T113753)
+                       options.api = options.api || new mw.Api();
+                       this.gateway = new WatchstarGateway( options.api );
+
                        if ( user.isAnon() ) {
                                _super.call( self, options );
                        } else if ( options.isWatched === undefined ) {
-                               api.load( page.getId() ).done( function () {
-                                       options.isWatched = api.isWatchedPage( 
page );
+                               this.gateway.loadWatchStatus( page.getId() 
).done( function () {
+                                       options.isWatched = 
self.gateway.isWatchedPage( page );
                                        _super.call( self, options );
                                } );
                        } else {
-                               api.setWatchedPage( options.page, 
options.isWatched );
+                               this.gateway.setWatchedPage( options.page, 
options.isWatched );
                                _super.call( self, options );
                        }
                        this.schema = new SchemaMobileWebWatching( {
@@ -90,6 +94,7 @@
                /** @inheritdoc */
                postRender: function () {
                        var self = this,
+                               gateway = this.gateway,
                                unwatchedClass = watchIcon.getGlyphClassName(),
                                watchedClass = watchedIcon.getGlyphClassName() 
+ ' watched',
                                page = self.options.page,
@@ -99,7 +104,7 @@
                        this.$el.attr( 'title', self.options.tooltip );
 
                        // Add watched class if necessary
-                       if ( !user.isAnon() && api.isWatchedPage( page ) ) {
+                       if ( !user.isAnon() && gateway.isWatchedPage( page ) ) {
                                $el.addClass( watchedClass ).removeClass( 
unwatchedClass );
                        } else {
                                $el.addClass( unwatchedClass ).removeClass( 
watchedClass );
@@ -133,6 +138,7 @@
                 */
                onStatusToggleUser: function () {
                        var self = this,
+                               gateway = this.gateway,
                                page = this.options.page,
                                checker;
 
@@ -142,10 +148,10 @@
                        this.schema.log( {
                                isWatched: self.options.isWatched
                        } );
-                       api.toggleStatus( page ).always( function () {
+                       gateway.toggleStatus( page ).always( function () {
                                clearInterval( checker );
                        } ).done( function () {
-                               if ( api.isWatchedPage( page ) ) {
+                               if ( gateway.isWatchedPage( page ) ) {
                                        self.options.isWatched = true;
                                        self.render();
                                        /**
diff --git a/resources/mobile.watchstar/WatchstarApi.js 
b/resources/mobile.watchstar/WatchstarGateway.js
similarity index 78%
rename from resources/mobile.watchstar/WatchstarApi.js
rename to resources/mobile.watchstar/WatchstarGateway.js
index 06e3e00..e893b81 100644
--- a/resources/mobile.watchstar/WatchstarApi.js
+++ b/resources/mobile.watchstar/WatchstarGateway.js
@@ -1,15 +1,14 @@
 ( function ( M, $ ) {
-
-       var Api = M.require( 'mobile.startup/api' ).Api,
-               WatchstarApi;
-
        /**
         * API for managing clickable watchstar
         *
-        * @class WatchstarApi
-        * @extends Api
+        * @class WatchstarGateway
         */
-       WatchstarApi = Api.extend( {
+       function WatchstarGateway( api ) {
+               this.api = api;
+       }
+
+       WatchstarGateway.prototype = {
                _cache: {},
 
                /**
@@ -33,7 +32,7 @@
                 * @param {Boolean} markAsAllWatched When true will assume all 
given ids are watched without a lookup.
                 * @return {jQuery.Deferred}
                 */
-               load: function ( ids, markAsAllWatched ) {
+               loadWatchStatus: function ( ids, markAsAllWatched ) {
                        var self = this,
                                result = $.Deferred();
 
@@ -43,7 +42,7 @@
                                } );
                                result.resolve();
                        } else {
-                               this.get( {
+                               this.api.get( {
                                        action: 'query',
                                        prop: 'info',
                                        inprop: 'watched',
@@ -70,16 +69,11 @@
                 * Check if a given page is watched
                 * @method
                 * @param {Page} page Page view object
-                * @return {Boolean}
-                * @throws {Error} when the status of the page has not been 
loaded.
+                * @return {Boolean|undefined} undefined when the watch status 
is not known.
                 */
                isWatchedPage: function ( page ) {
                        var id = page.getId();
-                       if ( this._cache.hasOwnProperty( id ) ) {
-                               return this._cache[id];
-                       } else {
-                               throw new Error( 'WatchstarApi unable to check 
watch status: Did you call load first?' );
-                       }
+                       return this._cache[id];
                },
 
                /**
@@ -106,14 +100,14 @@
                        if ( this.isWatchedPage( page ) ) {
                                data.unwatch = true;
                        }
-                       return this.postWithToken( 'watch', data ).done( 
function () {
+                       return this.api.postWithToken( 'watch', data ).done( 
function () {
                                var newStatus = !self.isWatchedPage( page );
                                self.setWatchedPage( page, newStatus );
                                M.emit( 'watched', page, newStatus );
                        } );
                }
-       } );
+       };
 
-       M.define( 'mobile.watchstar/WatchstarApi', WatchstarApi );
+       M.define( 'mobile.watchstar/WatchstarGateway', WatchstarGateway );
 
 }( mw.mobileFrontend, jQuery ) );
diff --git a/resources/skins.minerva.scripts/search.js 
b/resources/skins.minerva.scripts/search.js
index 4eb100a..a6b0616 100644
--- a/resources/skins.minerva.scripts/search.js
+++ b/resources/skins.minerva.scripts/search.js
@@ -40,7 +40,8 @@
                        SearchOverlay = M.require( moduleConfig.overlay );
 
                        new SearchOverlay( {
-                               gateway: new SearchGateway( new mw.Api() ),
+                               gatewayClass: SearchGateway,
+                               api: new mw.Api(),
                                searchTerm: searchTerm,
                                placeholderMsg: placeholder
                        } ).show();
diff --git a/resources/skins.minerva.watchstar/init.js 
b/resources/skins.minerva.watchstar/init.js
index 940dc29..e7d7e69 100644
--- a/resources/skins.minerva.watchstar/init.js
+++ b/resources/skins.minerva.watchstar/init.js
@@ -14,6 +14,7 @@
                var $container = $( '#ca-watch' );
                if ( !page.inNamespace( 'special' ) ) {
                        new Watchstar( {
+                               api: new mw.Api(),
                                el: $container,
                                isWatched: page.isWatched(),
                                page: page,
diff --git a/tests/qunit/mobile.nearby/test_Nearby.js 
b/tests/qunit/mobile.nearby/test_Nearby.js
index d7e48a2..38f03d0 100644
--- a/tests/qunit/mobile.nearby/test_Nearby.js
+++ b/tests/qunit/mobile.nearby/test_Nearby.js
@@ -1,7 +1,7 @@
 ( function ( M, $ ) {
 
        var NearbyGateway = M.require( 'mobile.nearby/NearbyGateway' ),
-               WatchstarApi = M.require( 'mobile.watchstar/WatchstarApi' ),
+               api = new mw.Api(),
                Nearby = M.require( 'mobile.nearby/Nearby' );
 
        QUnit.module( 'MobileFrontend modules/nearby/Nearby (1 - no results)', {
@@ -14,6 +14,7 @@
        QUnit.test( '#render empty list', 4, function ( assert ) {
                var $el = $( '<div>' );
                new Nearby( {
+                       api: api,
                        latitude: 37.7,
                        longitude: -122,
                        range: 1000,
@@ -42,7 +43,7 @@
                                }
                        };
                        // prevent hits to api due to watch status lookup
-                       this.sandbox.stub( WatchstarApi.prototype, 'get' 
).returns( $.Deferred().resolve( resp ) );
+                       this.sandbox.stub( mw.Api.prototype, 'get' ).returns( 
$.Deferred().resolve( resp ) );
 
                        this.getLocation = this.sandbox.stub( Nearby.prototype, 
'getCurrentPosition' )
                                .returns( $.Deferred().resolve( {
@@ -70,6 +71,7 @@
        QUnit.test( '#render with a location', 2, function ( assert ) {
                var $el = $( '<div>' );
                new Nearby( {
+                       api: api,
                        latitude: 37.7,
                        longitude: -122,
                        range: 1000,
@@ -99,6 +101,7 @@
        QUnit.test( '#render with current location', 2, function ( assert ) {
                var $el = $( '<div>' );
                new Nearby( {
+                       api: api,
                        useCurrentLocation: true,
                        range: 1000,
                        el: $el
@@ -117,6 +120,7 @@
        QUnit.test( '#render with a server error', 3, function ( assert ) {
                var $el = $( '<div>' ),
                        n = new Nearby( {
+                               api: api,
                                latitude: 37.7,
                                longitude: -122,
                                range: 1000,
@@ -142,6 +146,7 @@
                var $el = $( '<div>' ),
                        pageTitle = 'Hello Friends!';
                new Nearby( {
+                       api: api,
                        pageTitle: pageTitle,
                        range: 1000,
                        el: $el
diff --git a/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js 
b/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js
index a9e2033..a04eb25 100644
--- a/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js
+++ b/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js
@@ -5,8 +5,7 @@
                Icon = M.require( 'mobile.startup/Icon' ),
                watchIcon = new Icon( {
                        name: 'watched'
-               } ),
-               WatchstarApi = M.require( 'mobile.watchstar/WatchstarApi' );
+               } );
 
        QUnit.module( 'MobileFrontend 
mobile.pagelist.scripts/WatchstarPageList', {
                setup: function () {
@@ -21,7 +20,8 @@
                                }
                        };
 
-                       this.spy = this.sandbox.stub( WatchstarApi.prototype, 
'get' )
+                       // stub out the watchstar call
+                       this.spy = this.sandbox.stub( mw.Api.prototype, 'get' )
                                .returns( $.Deferred().resolve( resp ) );
                        this.sandbox.stub( user, 'isAnon' ).returns( false );
                }
@@ -29,6 +29,7 @@
 
        QUnit.test( 'Checks watchlist status once', 4, function ( assert ) {
                var pl = new PageList( {
+                       api: new mw.Api(),
                        pages: [ {
                                id: 30
                        }, {
diff --git a/tests/qunit/mobile.watchlist/test_WatchListGateway.js 
b/tests/qunit/mobile.watchlist/test_WatchListGateway.js
index f352f85..6c3d29c 100644
--- a/tests/qunit/mobile.watchlist/test_WatchListGateway.js
+++ b/tests/qunit/mobile.watchlist/test_WatchListGateway.js
@@ -90,12 +90,12 @@
        QUnit.module( 'MobileFrontend: WatchListGateway', {} );
 
        QUnit.test( 'load results from the first page', 3, function ( assert ) {
-               var api = new WatchListGateway( new mw.Api() );
+               var gateway = new WatchListGateway( new mw.Api() );
 
                this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( response ) );
 
-               api.load().done( function ( pages ) {
+               gateway.loadWatchlist().done( function ( pages ) {
                        var params = mw.Api.prototype.get.firstCall.args[0];
 
                        assert.strictEqual( params.continue, '', 'It should set 
the continue parameter' );
@@ -107,7 +107,7 @@
 
        QUnit.test( 'load results from the second page from last item of 
first', 6, function ( assert ) {
                var lastTitle = 'Albert Einstein',
-                       api = new WatchListGateway( new mw.Api(), lastTitle ),
+                       gateway = new WatchListGateway( new mw.Api(), lastTitle 
),
                        response1 = $.extend( {}, response, {
                                'continue': {
                                        watchlistraw: {
@@ -121,7 +121,7 @@
                stub = this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( response1 ) );
 
-               api.load().done( function ( pages ) {
+               gateway.loadWatchlist().done( function ( pages ) {
                        var params = mw.Api.prototype.get.firstCall.args[0];
 
                        assert.strictEqual( params.continue, 'gwrcontinue||', 
'It should set the continue parameter' );
@@ -135,7 +135,7 @@
                        // Let's call for the next page
                        stub.returns( $.Deferred().resolve( response ) );
 
-                       api.load().done( function ( pages ) {
+                       gateway.loadWatchlist().done( function ( pages ) {
                                // Albert Einstein should be the first result 
of the next page (not removed)
                                assert.equal( pages.length, 7, 'Albert should 
be in the results' );
                                assert.equal( pages[0].displayTitle, 'Albert 
Einstein', 'First item should be Albert' );
@@ -144,27 +144,25 @@
        } );
 
        QUnit.test( 'it doesn\'t throw an error when no pages are returned', 1, 
function ( assert ) {
-               var api = new WatchListGateway( new mw.Api() );
+               var gateway = new WatchListGateway( new mw.Api() );
 
                this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( {
                                batchcomplete: ''
                        } ) );
 
-               api.load().done( function ( pages ) {
+               gateway.loadWatchlist().done( function ( pages ) {
                        assert.deepEqual( pages, [] );
                } );
        } );
 
        QUnit.test( 'it should mark pages as new if necessary', 2, function ( 
assert ) {
-               var api;
+               var gateway = new WatchListGateway( new mw.Api() );
 
                this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( response ) );
 
-               api = new WatchListGateway( new mw.Api() );
-
-               api.load().done( function ( pages ) {
+               gateway.loadWatchlist().done( function ( pages ) {
                        assert.equal( pages[0].isMissing, false, 'Albert 
Einstein page isn\'t marked as new' );
                        assert.equal( pages[6].isMissing, true, 'zzzz page is 
marked as new' );
                } );
diff --git a/tests/qunit/mobile.watchstar/test_Watchstar.js 
b/tests/qunit/mobile.watchstar/test_Watchstar.js
index 0e3902e..7409b15 100644
--- a/tests/qunit/mobile.watchstar/test_Watchstar.js
+++ b/tests/qunit/mobile.watchstar/test_Watchstar.js
@@ -1,7 +1,6 @@
 ( function ( $, M ) {
 
        var Watchstar = M.require( 'mobile.watchstar/Watchstar' ),
-               WatchstarApi = M.require( 'mobile.watchstar/WatchstarApi' ),
                CtaDrawer = M.require( 'mobile.drawers/CtaDrawer' ),
                toast = M.require( 'mobile.toast/toast' ),
                Icon = M.require( 'mobile.startup/Icon' ),
@@ -23,6 +22,7 @@
                var $el = $( '<div>' );
 
                new Watchstar( {
+                       api: new mw.Api(),
                        el: $el,
                        page: new Page( {
                                id: 10
@@ -38,7 +38,7 @@
        QUnit.module( 'MobileFrontend: Watchstar.js', {
                setup: function () {
                        this.sandbox.stub( user, 'isAnon' ).returns( false );
-                       this.spy = this.sandbox.stub( WatchstarApi.prototype, 
'postWithToken' )
+                       this.spy = this.sandbox.stub( mw.Api.prototype, 
'postWithToken' )
                                .returns( $.Deferred().resolve() );
 
                        // FIXME: Should Schema.log be stubbed by default?
@@ -54,6 +54,7 @@
        QUnit.test( 'Logged in user watches article', 3, function ( assert ) {
                var
                        w = new Watchstar( {
+                               api: new mw.Api(),
                                isWatched: false,
                                page: new Page( {
                                        id: 42
@@ -74,6 +75,7 @@
        QUnit.test( 'Logged in user unwatches article', 2, function ( assert ) {
                var
                        w = new Watchstar( {
+                               api: new mw.Api(),
                                isWatched: true,
                                page: new Page( {
                                        id: 42
diff --git a/tests/qunit/mobile.watchstar/test_WatchstarApi.js 
b/tests/qunit/mobile.watchstar/test_WatchstarApi.js
deleted file mode 100644
index 18c11f5..0000000
--- a/tests/qunit/mobile.watchstar/test_WatchstarApi.js
+++ /dev/null
@@ -1,37 +0,0 @@
-( function ( $, M ) {
-
-       var WatchstarApi = M.require( 'mobile.watchstar/WatchstarApi' ),
-               Page = M.require( 'mobile.startup/Page' );
-
-       QUnit.module( 'MobileFrontend: WatchstarApi.js' );
-
-       QUnit.test( '_loadIntoCache', 2, function ( assert ) {
-               var api = new WatchstarApi();
-               api._loadIntoCache( {
-                       query: {
-                               pages: {
-                                       19: {},
-                                       30: {
-                                               watched: ''
-                                       }
-                               }
-                       }
-               } );
-               assert.strictEqual( api.isWatchedPage( new Page( {
-                       id: 30
-               } ) ), true, 'Able to check watch status' );
-               assert.strictEqual( api.isWatchedPage( new Page( {
-                       id: 19
-               } ) ), false, 'Able to check watch status' );
-       } );
-
-       QUnit.test( 'isWatchedPage', 1, function ( assert ) {
-               var api = new WatchstarApi();
-               assert.throws( function () {
-                       api.isWatchedPage( new Page( {
-                               id: 3000
-                       } ) );
-               }, 'throws an exception' );
-       } );
-
-}( jQuery, mw.mobileFrontend ) );
diff --git a/tests/qunit/mobile.watchstar/test_WatchstarGateway.js 
b/tests/qunit/mobile.watchstar/test_WatchstarGateway.js
new file mode 100644
index 0000000..8ca43a8
--- /dev/null
+++ b/tests/qunit/mobile.watchstar/test_WatchstarGateway.js
@@ -0,0 +1,39 @@
+( function ( $, M ) {
+
+       var WatchstarGateway = M.require( 'mobile.watchstar/WatchstarGateway' ),
+               Page = M.require( 'mobile.startup/Page' );
+
+       QUnit.module( 'MobileFrontend: WatchstarGateway.js' );
+
+       QUnit.test( '_loadIntoCache', 2, function ( assert ) {
+               var gateway = new WatchstarGateway( new mw.Api() );
+               gateway._loadIntoCache( {
+                       query: {
+                               pages: {
+                                       19: {},
+                                       30: {
+                                               watched: ''
+                                       }
+                               }
+                       }
+               } );
+               assert.strictEqual( gateway.isWatchedPage( new Page( {
+                       id: 30
+               } ) ), true, 'Able to check watch status' );
+               assert.strictEqual( gateway.isWatchedPage( new Page( {
+                       id: 19
+               } ) ), false, 'Able to check watch status' );
+       } );
+
+       QUnit.test( 'isWatchedPage', 1, function ( assert ) {
+               var gateway = new WatchstarGateway( new mw.Api() );
+               assert.ok(
+                       gateway.isWatchedPage(
+                               new Page( {
+                                       id: 3000
+                               } )
+                       ) === undefined,
+                       'unloaded pages are marked as undefined' );
+       } );
+
+}( jQuery, mw.mobileFrontend ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6a5b43afebb355589dcb510755563933b076f31f
Gerrit-PatchSet: 20
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhobs <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to