mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 10:59:56 +00:00
6ab24fe9f0
New changes: 1e12d0174 Generalize DiffElement logic (improves lists and tables) 24e0c7a94 Localisation updates from https://translatewiki.net. 32759ae86 Allow variable-length sequences without a fake space terminator, use for autolinking 82c204ba0 QUnit.assert.equalHash: Correctly compare JSON representation 2e5462610 DiffElement: Allow a node change to be an attribute change *and* a linear diff 41134af2b ve.ui.LinkAction: Allow autolinking ranges including trailing spaces again Local changes: Updated tests for 32759ae86: the autolinkUrl command no longer expects trailing whitespace to be included in the range. Bug: T117165 Bug: T149537 Bug: T158518 Change-Id: I5c2d5b97894fc93f49ce6270a198f3dfdcd09986
137 lines
3.8 KiB
JavaScript
137 lines
3.8 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface Actions MWLinkAction tests.
|
|
*
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.ui.MWLinkAction' );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'MW autolink', function ( assert ) {
|
|
var i,
|
|
cases = [
|
|
{
|
|
msg: 'Strip trailing punctuation (but not matched parens)',
|
|
html: '<p><b>https://en.wikipedia.org/wiki/Red_(disambiguation) xyz</b></p>',
|
|
rangeOrSelection: new ve.Range( 1, 51 ),
|
|
method: 'autolinkUrl',
|
|
expectedRangeOrSelection: new ve.Range( 51 ),
|
|
expectedData: function ( data, action ) {
|
|
var i,
|
|
a = action.getLinkAnnotation( 'https://en.wikipedia.org/wiki/Red_(disambiguation)' );
|
|
for ( i = 1; i < 51; i++ ) {
|
|
data[ i ][ 1 ].push( a.element );
|
|
}
|
|
}
|
|
},
|
|
{
|
|
msg: 'Autolink valid RFC',
|
|
html: '<p><b>RFC 1234 xyz</b></p>',
|
|
rangeOrSelection: new ve.Range( 1, 10 ),
|
|
method: 'autolinkMagicLink',
|
|
expectedRangeOrSelection: new ve.Range( 4 ),
|
|
expectedOriginalRangeOrSelection: new ve.Range( 10 ),
|
|
expectedData: function ( data ) {
|
|
data.splice( 1, 8, {
|
|
type: 'link/mwMagic',
|
|
attributes: {
|
|
content: 'RFC 1234'
|
|
},
|
|
annotations: data[ 1 ][ 1 ]
|
|
}, {
|
|
type: '/link/mwMagic',
|
|
annotations: data[ 1 ][ 1 ]
|
|
} );
|
|
},
|
|
undo: true
|
|
},
|
|
{
|
|
msg: 'Don\'t autolink invalid RFC',
|
|
html: '<p><b>RFC 123x xyz</b></p>',
|
|
rangeOrSelection: new ve.Range( 1, 10 ),
|
|
method: 'autolinkMagicLink',
|
|
expectedRangeOrSelection: new ve.Range( 1, 10 ),
|
|
expectedData: function () {
|
|
/* no change, no link */
|
|
}
|
|
},
|
|
{
|
|
msg: 'Autolink valid PMID',
|
|
html: '<p><b>PMID 1234 xyz</b></p>',
|
|
rangeOrSelection: new ve.Range( 1, 11 ),
|
|
method: 'autolinkMagicLink',
|
|
expectedRangeOrSelection: new ve.Range( 4 ),
|
|
expectedOriginalRangeOrSelection: new ve.Range( 11 ),
|
|
expectedData: function ( data ) {
|
|
data.splice( 1, 9, {
|
|
type: 'link/mwMagic',
|
|
attributes: {
|
|
content: 'PMID 1234'
|
|
},
|
|
annotations: data[ 1 ][ 1 ]
|
|
}, {
|
|
type: '/link/mwMagic',
|
|
annotations: data[ 1 ][ 1 ]
|
|
} );
|
|
},
|
|
undo: true
|
|
},
|
|
{
|
|
msg: 'Don\'t autolink invalid PMID',
|
|
html: '<p><b>PMID 123x xyz</b></p>',
|
|
rangeOrSelection: new ve.Range( 1, 11 ),
|
|
method: 'autolinkMagicLink',
|
|
expectedRangeOrSelection: new ve.Range( 1, 11 ),
|
|
expectedData: function () {
|
|
/* no change, no link */
|
|
}
|
|
},
|
|
{
|
|
msg: 'Autolink valid ISBN',
|
|
html: '<p><b>ISBN 978-0596517748 xyz</b></p>',
|
|
rangeOrSelection: new ve.Range( 1, 21 ),
|
|
method: 'autolinkMagicLink',
|
|
expectedRangeOrSelection: new ve.Range( 4 ),
|
|
expectedOriginalRangeOrSelection: new ve.Range( 21 ),
|
|
expectedData: function ( data ) {
|
|
data.splice( 1, 19, {
|
|
type: 'link/mwMagic',
|
|
attributes: {
|
|
content: 'ISBN 978-0596517748'
|
|
},
|
|
annotations: data[ 1 ][ 1 ]
|
|
}, {
|
|
type: '/link/mwMagic',
|
|
annotations: data[ 1 ][ 1 ]
|
|
} );
|
|
},
|
|
undo: true
|
|
},
|
|
{
|
|
msg: 'Don\'t autolink invalid ISBN',
|
|
html: '<p><b>ISBN 978-059651774 xyz</b></p>',
|
|
rangeOrSelection: new ve.Range( 1, 20 ),
|
|
method: 'autolinkMagicLink',
|
|
expectedRangeOrSelection: new ve.Range( 1, 20 ),
|
|
expectedData: function () {
|
|
/* no change, no link */
|
|
}
|
|
}
|
|
];
|
|
|
|
QUnit.expect( ve.test.utils.countActionTests( cases ) );
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
ve.test.utils.runActionTest(
|
|
'link', assert, cases[ i ].html, false, cases[ i ].method, [], cases[ i ].rangeOrSelection, cases[ i ].msg,
|
|
{
|
|
expectedData: cases[ i ].expectedData,
|
|
expectedRangeOrSelection: cases[ i ].expectedRangeOrSelection,
|
|
expectedOriginalRangeOrSelection: cases[ i ].expectedOriginalRangeOrSelection,
|
|
undo: cases[ i ].undo
|
|
}
|
|
);
|
|
}
|
|
} );
|