mediawiki-extensions-Popups/tests/node-qunit/formatter.test.js
Stephen Niedzielski ece4670710 Hygiene: use arrow for anonymous functions
In some places, the arrow function seems more natural. This patch
approximates the following with manual amendments:

  find \
    -not \( \( -name node_modules -o -name .git -o -name vendor -o -name doc -o -name resources \) -prune \) \
    -iname \*.js|
  xargs -rd\\n sed -ri 's%function\s*(\([^)]*\))%\1 =>%g'

Files to focus on were identified with:

  rg -slg\!/resources/dist/ -g\!/i18n/ -g\!/doc/ 'this|self|arguments|bind|call|apply|new'|
  xargs -rd\\n git difftool -y

Bug: T165036
Change-Id: Ic66b6000b8fc000f9bfde39749f9cfa69924a13c
2018-03-20 09:27:08 -05:00

68 lines
1.6 KiB
JavaScript

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