mediawiki-extensions-Popups/tests/node-qunit/formatter.test.js
jdlrobson ca440dfbed Remove client side formatters in Popups code base for MW API.
Stripping parentheticals were designed specifically for working around
issues with content inside wikimedia wikis and error prone.

This problem for wikimedia wikis is solved by the mobile content
service.

Given we have no intentions to use the MediaWiki API for summaries.
They are not necessarily useful to third parties and it makes little
sense to maintain them (a third party can configure their own API or
use their own REST endpoint if they really do need them).

Bug: T189042
Change-Id: I2729dc9f172af0afee1c6f0cd563c556b4ae0aeb
2018-03-08 21:05:49 +00:00

68 lines
1.6 KiB
JavaScript

import * as formatter from '../../src/formatter';
var $ = jQuery;
QUnit.module( 'ext.popups.formatter', {
beforeEach: function () {
window.mediaWiki.RegExp = {
escape: this.sandbox.spy( function ( str ) {
return str.replace( /([\\{}()|.?*+\-^$[\]])/g, '\\$1' );
} )
};
},
afterEach: function () {
window.mediaWiki.RegExp = null;
}
} );
QUnit.test( 'Title is bold', function ( assert ) {
var 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 ) {
var $div = $( '<div>' ).append(
formatter.formatPlainTextExtract( extract, title )
);
assert.equal( $div.html(), expected, msg );
}
cases.forEach( function ( case_ ) {
test( case_[ 0 ], case_[ 1 ], case_[ 2 ], case_[ 3 ] );
} );
} );