2017-07-28 17:32:46 +00:00
|
|
|
import * as formatter from '../../src/formatter';
|
|
|
|
|
2018-03-19 19:39:41 +00:00
|
|
|
const $ = jQuery;
|
2017-06-08 00:58:30 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups.formatter', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2018-06-21 15:47:13 +00:00
|
|
|
mediaWiki.RegExp = {
|
2018-03-14 23:50:09 +00:00
|
|
|
escape: this.sandbox.spy( ( str ) => {
|
2017-10-09 14:56:15 +00:00
|
|
|
return str.replace( /([\\{}()|.?*+\-^$[\]])/g, '\\$1' );
|
2017-06-08 00:58:30 +00:00
|
|
|
} )
|
|
|
|
};
|
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
afterEach() {
|
2018-06-21 15:47:13 +00:00
|
|
|
mediaWiki.RegExp = null;
|
2017-06-08 00:58:30 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( 'Title is bold', ( assert ) => {
|
2018-03-19 19:39:41 +00:00
|
|
|
const cases = [
|
2017-06-08 00:58:30 +00:00
|
|
|
[
|
|
|
|
'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'
|
|
|
|
],
|
|
|
|
[
|
2017-10-09 14:56:15 +00:00
|
|
|
'"Heroes" is a David Bowie album', '"Heroes"',
|
|
|
|
'<b>"Heroes"</b> is a David Bowie album',
|
2017-06-08 00:58:30 +00:00
|
|
|
'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 ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const $div = $( '<div>' ).append(
|
2017-06-08 13:29:57 +00:00
|
|
|
formatter.formatPlainTextExtract( extract, title )
|
2017-06-08 00:58:30 +00:00
|
|
|
);
|
2018-05-20 12:32:51 +00:00
|
|
|
assert.strictEqual( $div.html(), expected, msg );
|
2017-06-08 00:58:30 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
cases.forEach( ( case_ ) => {
|
2017-06-08 00:58:30 +00:00
|
|
|
test( case_[ 0 ], case_[ 1 ], case_[ 2 ], case_[ 3 ] );
|
|
|
|
} );
|
|
|
|
} );
|