2017-07-28 17:32:46 +00:00
|
|
|
import * as formatter from '../../src/formatter';
|
|
|
|
|
2017-06-08 00:58:30 +00:00
|
|
|
QUnit.module( 'ext.popups.formatter', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.util = {
|
2019-10-17 07:37:24 +00:00
|
|
|
escapeRegExp: 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() {
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.util = 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'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2018-09-11 11:53:15 +00:00
|
|
|
function runTest( 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_ ) => {
|
2018-09-11 11:53:15 +00:00
|
|
|
runTest( case_[ 0 ], case_[ 1 ], case_[ 2 ], case_[ 3 ] );
|
2017-06-08 00:58:30 +00:00
|
|
|
} );
|
|
|
|
} );
|