2015-08-17 16:28:57 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface Actions MWLinkAction tests.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2015-08-17 16:28:57 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
QUnit.module( 've.ui.MWLinkAction' );
|
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
|
|
|
QUnit.test( 'MW autolink', function ( assert ) {
|
2020-08-18 12:16:49 +00:00
|
|
|
var 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 );
|
2015-08-18 20:24:45 +00:00
|
|
|
}
|
2020-08-18 12:16:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Autolink valid RFC',
|
|
|
|
html: '<p><b>RFC 1234 xyz</b></p>',
|
|
|
|
rangeOrSelection: new ve.Range( 1, 9 ),
|
|
|
|
method: 'autolinkMagicLink',
|
|
|
|
expectedRangeOrSelection: new ve.Range( 3 ),
|
|
|
|
expectedOriginalRangeOrSelection: new ve.Range( 9 ),
|
|
|
|
expectedData: function ( data ) {
|
|
|
|
data.splice( 1, 8, {
|
|
|
|
type: 'link/mwMagic',
|
|
|
|
attributes: {
|
|
|
|
content: 'RFC 1234'
|
|
|
|
},
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
|
|
|
}, {
|
|
|
|
type: '/link/mwMagic'
|
|
|
|
} );
|
2015-08-18 20:24:45 +00:00
|
|
|
},
|
2020-08-18 12:16:49 +00:00
|
|
|
undo: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Don\'t autolink invalid RFC',
|
|
|
|
html: '<p><b>RFC 123x xyz</b></p>',
|
|
|
|
rangeOrSelection: new ve.Range( 1, 9 ),
|
|
|
|
method: 'autolinkMagicLink',
|
|
|
|
expectedRangeOrSelection: new ve.Range( 1, 9 ),
|
|
|
|
expectedData: function () {
|
|
|
|
/* no change, no link */
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Autolink valid PMID',
|
|
|
|
html: '<p><b>PMID 1234 xyz</b></p>',
|
|
|
|
rangeOrSelection: new ve.Range( 1, 10 ),
|
|
|
|
method: 'autolinkMagicLink',
|
|
|
|
expectedRangeOrSelection: new ve.Range( 3 ),
|
|
|
|
expectedOriginalRangeOrSelection: new ve.Range( 10 ),
|
|
|
|
expectedData: function ( data ) {
|
|
|
|
data.splice( 1, 9, {
|
|
|
|
type: 'link/mwMagic',
|
|
|
|
attributes: {
|
|
|
|
content: 'PMID 1234'
|
|
|
|
},
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
|
|
|
}, {
|
|
|
|
type: '/link/mwMagic'
|
|
|
|
} );
|
2015-08-18 20:24:45 +00:00
|
|
|
},
|
2020-08-18 12:16:49 +00:00
|
|
|
undo: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Don\'t autolink invalid PMID',
|
|
|
|
html: '<p><b>PMID 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 ISBN',
|
|
|
|
html: '<p><b>ISBN 978-0596517748 xyz</b></p>',
|
|
|
|
rangeOrSelection: new ve.Range( 1, 20 ),
|
|
|
|
method: 'autolinkMagicLink',
|
|
|
|
expectedRangeOrSelection: new ve.Range( 3 ),
|
|
|
|
expectedOriginalRangeOrSelection: new ve.Range( 20 ),
|
|
|
|
expectedData: function ( data ) {
|
|
|
|
data.splice( 1, 19, {
|
|
|
|
type: 'link/mwMagic',
|
|
|
|
attributes: {
|
|
|
|
content: 'ISBN 978-0596517748'
|
|
|
|
},
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
|
|
|
}, {
|
|
|
|
type: '/link/mwMagic'
|
|
|
|
} );
|
2015-08-18 20:24:45 +00:00
|
|
|
},
|
2020-08-18 12:16:49 +00:00
|
|
|
undo: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Don\'t autolink invalid ISBN',
|
|
|
|
html: '<p><b>ISBN 978-059651774 xyz</b></p>',
|
|
|
|
rangeOrSelection: new ve.Range( 1, 19 ),
|
|
|
|
method: 'autolinkMagicLink',
|
|
|
|
expectedRangeOrSelection: new ve.Range( 1, 19 ),
|
|
|
|
expectedData: function () {
|
|
|
|
/* no change, no link */
|
2015-08-17 16:28:57 +00:00
|
|
|
}
|
2020-08-18 12:16:49 +00:00
|
|
|
}
|
|
|
|
];
|
2015-08-17 16:28:57 +00:00
|
|
|
|
2020-08-18 12:16:49 +00:00
|
|
|
cases.forEach( function ( caseItem ) {
|
2016-05-11 11:57:36 +00:00
|
|
|
ve.test.utils.runActionTest(
|
2020-08-18 12:16:49 +00:00
|
|
|
'link', assert, caseItem.html, false, caseItem.method, [], caseItem.rangeOrSelection, caseItem.msg,
|
2016-05-11 11:57:36 +00:00
|
|
|
{
|
2020-08-18 12:16:49 +00:00
|
|
|
expectedData: caseItem.expectedData,
|
|
|
|
expectedRangeOrSelection: caseItem.expectedRangeOrSelection,
|
|
|
|
expectedOriginalRangeOrSelection: caseItem.expectedOriginalRangeOrSelection,
|
|
|
|
undo: caseItem.undo
|
2016-05-11 11:57:36 +00:00
|
|
|
}
|
|
|
|
);
|
2020-08-18 12:16:49 +00:00
|
|
|
} );
|
2015-08-17 16:28:57 +00:00
|
|
|
} );
|