mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 19:50:04 +00:00
a0dc96cac9
Instead of mixing window.mediaWiki / mediaWiki and window.jQuery / jQuery references, always refer to globals which exist whether code is executed in browser or headless Node.js environments. find src tests -iname \*.js| xargs -rd\\n sed -ri 's%window.(mediaWiki|jQuery)%\1%gi' Change-Id: I21d0a602dcbd2bc6774934bee6c487e443270fe0
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
import * as formatter from '../../src/formatter';
|
|
|
|
const $ = jQuery;
|
|
|
|
QUnit.module( 'ext.popups.formatter', {
|
|
beforeEach() {
|
|
mediaWiki.RegExp = {
|
|
escape: this.sandbox.spy( ( str ) => {
|
|
return str.replace( /([\\{}()|.?*+\-^$[\]])/g, '\\$1' );
|
|
} )
|
|
};
|
|
},
|
|
afterEach() {
|
|
mediaWiki.RegExp = null;
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'Title is bold', ( assert ) => {
|
|
const cases = [
|
|
[
|
|
'Isaac Newton was born in', 'Isaac Newton',
|
|
'<b>Isaac Newton</b> was born in',
|
|
'Title as first word'
|
|
],
|
|
[
|
|
'The C* language not to be confused with C# or C', 'C*',
|
|
'The <b>C*</b> language not to be confused with C# or C',
|
|
'Title containing *'
|
|
],
|
|
[
|
|
'I like trains', 'Train',
|
|
'I like <b>train</b>s',
|
|
'Make the simple plural bold'
|
|
],
|
|
[
|
|
'Foo\'s pub is a pub in Bar', 'Foo\'s pub',
|
|
'<b>Foo\'s pub</b> is a pub in Bar',
|
|
'Correct escaping'
|
|
],
|
|
[
|
|
'"Heroes" is a David Bowie album', '"Heroes"',
|
|
'<b>"Heroes"</b> is a David Bowie album',
|
|
'Quotes in title'
|
|
],
|
|
[
|
|
'*Testing if Things are correctly identified', 'Things',
|
|
'*Testing if <b>Things</b> are correctly identified',
|
|
'Article that begins with asterisk'
|
|
],
|
|
[
|
|
'Testing if repeated words are not matched when repeated', 'Repeated',
|
|
'Testing if <b>repeated</b> words are not matched when repeated',
|
|
'Repeated title'
|
|
]
|
|
];
|
|
|
|
function test( extract, title, expected, msg ) {
|
|
const $div = $( '<div>' ).append(
|
|
formatter.formatPlainTextExtract( extract, title )
|
|
);
|
|
assert.strictEqual( $div.html(), expected, msg );
|
|
}
|
|
|
|
cases.forEach( ( case_ ) => {
|
|
test( case_[ 0 ], case_[ 1 ], case_[ 2 ], case_[ 3 ] );
|
|
} );
|
|
} );
|