2014-06-11 04:34:49 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
|
2015-08-11 13:45:24 +00:00
|
|
|
QUnit.module( 'ext.popups.renderer.renderers.article', QUnit.newMwEnvironment() );
|
2015-03-25 20:53:27 +00:00
|
|
|
|
2016-05-10 21:11:01 +00:00
|
|
|
QUnit.test( 'render.article.createImgThumbnail', 1, function ( assert ) {
|
|
|
|
var $container = mw.popups.render.renderers.article.createImgThumbnail( 'foo', '/w/test "123"(bar).gif' );
|
|
|
|
assert.equal( $container.css( 'background-image' ), 'url("/w/test \\"123\\"(bar).gif")' );
|
|
|
|
} );
|
|
|
|
|
2014-12-02 08:08:47 +00:00
|
|
|
QUnit.test( 'render.article.getProcessedElements', function ( assert ) {
|
2015-01-08 12:53:26 +00:00
|
|
|
QUnit.expect( 15 );
|
2014-06-11 04:34:49 +00:00
|
|
|
|
2015-08-26 10:15:16 +00:00
|
|
|
function test( extract, title, expected, msg ) {
|
2014-12-02 08:08:47 +00:00
|
|
|
var $div = $( '<div>' ).append(
|
2015-08-11 13:45:24 +00:00
|
|
|
mw.popups.render.renderers.article.getProcessedElements( extract, title )
|
2014-06-11 04:34:49 +00:00
|
|
|
);
|
2014-12-02 08:08:47 +00:00
|
|
|
assert.equal( $div.html(), expected, msg );
|
2014-06-11 04:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Isaac Newton was born in', 'Isaac Newton',
|
2014-12-02 08:08:47 +00:00
|
|
|
'<b>Isaac Newton</b> was born in',
|
|
|
|
'Title as first word'
|
2014-06-11 04:34:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
test(
|
|
|
|
'The C* language not to be confused with C# or C', 'C*',
|
2014-12-02 08:08:47 +00:00
|
|
|
'The <b>C*</b> language not to be confused with C# or C',
|
|
|
|
'Title containing *'
|
2014-06-11 04:34:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Person (was born in Location) is good', 'Person',
|
2014-12-02 08:08:47 +00:00
|
|
|
'<b>Person</b> is good',
|
|
|
|
'Extract with text in parentheses'
|
2014-06-11 04:34:49 +00:00
|
|
|
);
|
|
|
|
|
2015-01-02 10:57:35 +00:00
|
|
|
test(
|
|
|
|
'Person, (was born in Location) is good', 'Person',
|
|
|
|
'<b>Person</b>, is good',
|
|
|
|
'Comma after title'
|
|
|
|
);
|
|
|
|
|
2014-06-11 04:34:49 +00:00
|
|
|
test(
|
|
|
|
'Person (was born in Location (at Time)) is good', 'Person',
|
2014-12-02 08:08:47 +00:00
|
|
|
'<b>Person</b> is good',
|
|
|
|
'Extract with nested parentheses'
|
2014-06-11 04:34:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Person (was born in Location (at Time) ) is good', 'Person',
|
2014-12-02 08:08:47 +00:00
|
|
|
'<b>Person</b> is good',
|
|
|
|
'Extract with nested parentheses and random spaces'
|
2014-06-11 04:34:49 +00:00
|
|
|
);
|
|
|
|
|
2015-01-02 10:57:35 +00:00
|
|
|
test(
|
|
|
|
'I like trains', 'Train',
|
|
|
|
'I like <b>train</b>s',
|
|
|
|
'Make the simple plural bold'
|
|
|
|
);
|
|
|
|
|
2014-06-11 04:34:49 +00:00
|
|
|
test(
|
|
|
|
'Brackets ) are funny ( when not used properly', 'Brackets',
|
2014-12-02 08:08:47 +00:00
|
|
|
'<b>Brackets</b> ) are funny ( when not used properly',
|
|
|
|
'Extract with unbalanced parentheses'
|
2014-06-11 04:34:49 +00:00
|
|
|
);
|
|
|
|
|
2015-01-02 11:31:12 +00:00
|
|
|
test(
|
|
|
|
'Vappu (born August 7), also known as Lexy', 'Vappu',
|
|
|
|
'<b>Vappu</b>, also known as Lexy',
|
|
|
|
'Spaces around bracketed text should be removed'
|
|
|
|
);
|
|
|
|
|
2014-11-26 02:21:03 +00:00
|
|
|
test(
|
|
|
|
'Epic XSS <script>alert("XSS")</script> is epic', 'Epic XSS',
|
2014-12-02 08:08:47 +00:00
|
|
|
'<b>Epic XSS</b> <script>alert</script> is epic',
|
|
|
|
'XSS Attack'
|
|
|
|
);
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Foo\'s pub is a pub in Bar', 'Foo\'s pub',
|
2015-03-26 08:12:01 +00:00
|
|
|
'<b>Foo\'s pub</b> is a pub in Bar',
|
2014-12-02 08:08:47 +00:00
|
|
|
'Correct escaping'
|
|
|
|
);
|
|
|
|
|
2015-03-26 08:12:01 +00:00
|
|
|
test(
|
|
|
|
'\"Heroes\" is a David Bowie album', '\"Heroes\"',
|
|
|
|
'<b>\"Heroes\"</b> is a David Bowie album',
|
|
|
|
'Quotes in title'
|
|
|
|
);
|
|
|
|
|
2014-12-02 08:08:47 +00:00
|
|
|
test(
|
|
|
|
'*Testing if Things are correctly identified', 'Things',
|
|
|
|
'*Testing if <b>Things</b> are correctly identified',
|
|
|
|
'Article that begins with asterisk'
|
2014-11-26 02:21:03 +00:00
|
|
|
);
|
|
|
|
|
2016-04-13 15:54:42 +00:00
|
|
|
test(
|
|
|
|
'Testing if repeated words are not matched when repeated', 'Repeated',
|
|
|
|
'Testing if <b>repeated</b> words are not matched when repeated',
|
|
|
|
'Repeated title'
|
|
|
|
);
|
|
|
|
|
2015-01-08 12:53:26 +00:00
|
|
|
test(
|
|
|
|
'Evil Empire is the second studio album', 'Evil Empire (album)',
|
|
|
|
'<b>Evil Empire</b> is the second studio album',
|
|
|
|
'Extra information in title in paranthesis'
|
|
|
|
);
|
|
|
|
|
2014-06-11 04:34:49 +00:00
|
|
|
} );
|
2015-10-06 16:07:05 +00:00
|
|
|
QUnit.test( 'render.article.getClosestYPosition', function ( assert ) {
|
|
|
|
QUnit.expect( 3 );
|
|
|
|
assert.equal( mw.popups.render.getClosestYPosition( 100, [
|
|
|
|
{
|
|
|
|
top: 99,
|
|
|
|
bottom: 119
|
|
|
|
},
|
|
|
|
{
|
|
|
|
top: 120,
|
|
|
|
bottom: 140
|
|
|
|
}
|
|
|
|
] ), 119, 'Correct lower Y.' );
|
|
|
|
|
|
|
|
assert.equal( mw.popups.render.getClosestYPosition( 100, [
|
|
|
|
{
|
|
|
|
top: 99,
|
|
|
|
bottom: 119
|
|
|
|
},
|
|
|
|
{
|
|
|
|
top: 120,
|
|
|
|
bottom: 140
|
|
|
|
}
|
|
|
|
], true ), 99, 'Correct upper Y.' );
|
|
|
|
|
|
|
|
assert.equal( mw.popups.render.getClosestYPosition( 135, [
|
|
|
|
{
|
|
|
|
top: 99,
|
|
|
|
bottom: 119
|
|
|
|
},
|
|
|
|
{
|
|
|
|
top: 120,
|
|
|
|
bottom: 140
|
|
|
|
}
|
|
|
|
], true ), 120, 'Correct upper Y 2.' );
|
|
|
|
} );
|
2014-06-11 04:34:49 +00:00
|
|
|
|
2015-08-26 10:15:16 +00:00
|
|
|
} )( jQuery, mediaWiki );
|