mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 23:24:39 +00:00
QA: Test renderer#createEmptyPreview
Bug: T133022 Change-Id: If93d2c679bd7edcf98946e1cb688bc5c3744f69b
This commit is contained in:
parent
4fe195657b
commit
a46a5fc02f
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.map
vendored
BIN
resources/dist/index.js.map
vendored
Binary file not shown.
|
@ -690,6 +690,7 @@ module.exports = {
|
|||
init: init,
|
||||
// The following are exposed for teseting purposes only
|
||||
createPokeyMasks: createPokeyMasks,
|
||||
createEmptyPreview: createEmptyPreview,
|
||||
createThumbnailElement: createThumbnailElement,
|
||||
renderExtract: renderExtract,
|
||||
getClasses: getClasses,
|
||||
|
|
|
@ -3,14 +3,36 @@ var $ = jQuery,
|
|||
|
||||
QUnit.module( 'ext.popups#renderer', {
|
||||
beforeEach: function () {
|
||||
var self = this;
|
||||
|
||||
window.mediaWiki.RegExp = {
|
||||
escape: this.sandbox.spy( function( str ) {
|
||||
return str.replace( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' );
|
||||
} )
|
||||
};
|
||||
|
||||
window.mediaWiki.msg = function ( key ) {
|
||||
switch ( key ) {
|
||||
case 'popups-preview-no-preview':
|
||||
return 'Looks like there isn\'t a preview for this page';
|
||||
case 'popups-preview-footer-read':
|
||||
return 'Read';
|
||||
}
|
||||
};
|
||||
|
||||
this.renderSpy = this.sandbox.spy();
|
||||
window.mediaWiki.template = {
|
||||
get: function () {
|
||||
return {
|
||||
render: self.renderSpy
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
afterEach: function () {
|
||||
window.mediaWiki.RegExp = null;
|
||||
window.mediaWiki.msg = null;
|
||||
window.mediaWiki.template = null;
|
||||
}
|
||||
} );
|
||||
|
||||
|
@ -33,6 +55,45 @@ QUnit.test( 'createPokeyMasks', function ( assert ) {
|
|||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'createEmptyPreview', function ( assert ) {
|
||||
var model = {
|
||||
title: 'Test',
|
||||
url: 'https://en.wikipedia.org/wiki/Test',
|
||||
languageCode: 'en',
|
||||
languageDirection: 'ltr',
|
||||
extract: 'This is a test page.',
|
||||
thumbnail: {
|
||||
source: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/409px-President_Barack_Obama.jpg',
|
||||
width: 409,
|
||||
height: 512
|
||||
}
|
||||
},
|
||||
emptyPreview = renderer.createEmptyPreview( model );
|
||||
|
||||
assert.equal(
|
||||
emptyPreview.hasThumbnail,
|
||||
false,
|
||||
'Empty preview doesn\'t have a thumbnail (even though one is provided).'
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
emptyPreview.isTall,
|
||||
false,
|
||||
'Empty preview is never tall (even though the supplied thumbnail is tall).'
|
||||
);
|
||||
|
||||
assert.ok( this.renderSpy.calledOnce, 'Template has been rendered.' );
|
||||
|
||||
assert.deepEqual(
|
||||
this.renderSpy.getCall( 0 ).args[ 0 ],
|
||||
$.extend( {}, model, {
|
||||
extractMsg: 'Looks like there isn\'t a preview for this page',
|
||||
readMsg: 'Read'
|
||||
} ),
|
||||
'Template is called with the correct data.'
|
||||
);
|
||||
} );
|
||||
|
||||
QUnit.test( 'createThumbnailElement', function ( assert ) {
|
||||
var className = 'thumb-class',
|
||||
url = 'https://thumbnail.url',
|
||||
|
|
Loading…
Reference in a new issue