mediawiki-extensions-Popups/tests/qunit/ext.popups.renderer/desktopRenderer.test.js
jdlrobson 7f3be6dcd4 Do not directly manipulate the cached object
Popups currently makes use of a render cache. Using a cache in this
way without protection causes problems (I will look at cleaning this up)

The hack below it
`mw.popups.$popup.html( mw.popups.$popup.html() );`
will lead to the html of the cached object being wiped out on IE9 meaning
future loads will show an empty popup.

Add a unit test (which previously would fail in IE9) to protect against this
in future.

Bug: T68496
Change-Id: Icef784fb389b0ab1856e2ba7464c9423ebcd62ab
2016-05-12 16:56:19 -07:00

28 lines
746 B
JavaScript

( function ( $, mw ) {
QUnit.module( 'ext.popups.renderer.desktopRenderer', {
setup: function () {
mw.popups.$popup = $( '<div>' );
mw.popups.render.cache[ '/wiki/Kittens' ] = {
settings: {
title: 'Kittens'
},
popup: $( '<div>hello</div>' ),
getClasses: function () {
return [ 'foo' ];
},
process: $.noop,
getOffset: function () {
return {};
}
};
}
} );
QUnit.test( 'mw.popups.render.openPopup (T68496)', 1, function ( assert ) {
mw.popups.render.openPopup( $( '<a href="/wiki/Kittens">' ) );
mw.popups.render.openPopup( $( '<a href="/wiki/Kittens">' ) );
assert.strictEqual( mw.popups.render.cache[ '/wiki/Kittens' ].popup.text(), 'hello' );
} );
} )( jQuery, mediaWiki );