diff --git a/tests/qunit/ext.popups.renderer.article.test.js b/tests/qunit/ext.popups.renderer.article.test.js index 6d0099a17..0fb0b31ce 100644 --- a/tests/qunit/ext.popups.renderer.article.test.js +++ b/tests/qunit/ext.popups.renderer.article.test.js @@ -3,6 +3,7 @@ QUnit.module( 'ext.popups.renderer.renderers.article', { setup: function () { mw.popups.render.cache[ '/wiki/Kittens' ] = {}; + this.sandbox.stub( mw.popups, 'getTitle' ).returns( 'Kittens' ); this.pageInfo = { thumbnail: { source: 'http://commons.wikimedia.org/kittypic.svg', @@ -15,6 +16,16 @@ pagelanguagehtmlcode: 'en', pagelanguagedir: 'ltr' }; + this.kittenResponse = { + query: { + pages: [ + this.pageInfo + ] + } + }; + this.apiStub = this.sandbox.stub( mw.popups.api, 'get' ).returns( + $.Deferred().resolve( this.kittenResponse ) + ); } } ); @@ -198,4 +209,19 @@ 'thumbnail information got cached' ); } ); + QUnit.asyncTest( 'render.article.init', function ( assert ) { + var $kittyLink = $( '' ), + apiStub = this.apiStub; + + QUnit.expect( 2 ); + mw.popups.render.renderers.article.init( $kittyLink ); + mw.popups.render.renderers.article.init( $kittyLink ).done( function () { + var cache = mw.popups.render.cache[ '/wiki/Kittens' ]; + QUnit.start(); + assert.ok( cache.popup.length, 'The popup is stored in cache.' ); + assert.ok( apiStub.calledTwice, + 'This method in current form is dumb and if called more than once will not load from cache.' ); + } ); + } ); + } )( jQuery, mediaWiki );