2015-08-17 16:28:57 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface Actions MWLinkAction tests.
|
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 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 ) {
|
|
|
|
var i,
|
|
|
|
cases = [
|
|
|
|
{
|
2015-08-18 20:24:45 +00:00
|
|
|
msg: 'Strip trailing punctuation (but not matched parens)',
|
2015-09-15 21:27:28 +00:00
|
|
|
html: '<p><b>https://en.wikipedia.org/wiki/Red_(disambiguation) xyz</b></p>',
|
2017-03-14 19:45:59 +00:00
|
|
|
rangeOrSelection: new ve.Range( 1, 51 ),
|
2015-08-17 16:28:57 +00:00
|
|
|
method: 'autolinkUrl',
|
2017-03-14 19:45:59 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 51 ),
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedData: function ( data, action ) {
|
2015-08-18 20:24:45 +00:00
|
|
|
var i,
|
2016-05-11 11:57:36 +00:00
|
|
|
a = action.getLinkAnnotation( 'https://en.wikipedia.org/wiki/Red_(disambiguation)' );
|
2015-08-19 18:05:01 +00:00
|
|
|
for ( i = 1; i < 51; i++ ) {
|
2016-05-11 11:57:36 +00:00
|
|
|
data[ i ][ 1 ].push( a.element );
|
2015-08-17 16:28:57 +00:00
|
|
|
}
|
2015-08-18 20:24:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Autolink valid RFC',
|
2015-09-15 21:27:28 +00:00
|
|
|
html: '<p><b>RFC 1234 xyz</b></p>',
|
2017-03-06 08:57:49 +00:00
|
|
|
rangeOrSelection: new ve.Range( 1, 9 ),
|
2015-08-18 20:24:45 +00:00
|
|
|
method: 'autolinkMagicLink',
|
2017-03-06 08:57:49 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 3 ),
|
|
|
|
expectedOriginalRangeOrSelection: new ve.Range( 9 ),
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedData: function ( data ) {
|
2015-09-15 20:59:58 +00:00
|
|
|
data.splice( 1, 8, {
|
|
|
|
type: 'link/mwMagic',
|
|
|
|
attributes: {
|
|
|
|
content: 'RFC 1234'
|
2015-09-15 21:27:28 +00:00
|
|
|
},
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
2015-09-15 20:59:58 +00:00
|
|
|
}, {
|
2015-09-15 21:27:28 +00:00
|
|
|
type: '/link/mwMagic',
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
2015-09-15 20:59:58 +00:00
|
|
|
} );
|
2016-05-11 11:57:36 +00:00
|
|
|
},
|
|
|
|
undo: true
|
2015-08-18 20:24:45 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Don\'t autolink invalid RFC',
|
2015-09-15 21:27:28 +00:00
|
|
|
html: '<p><b>RFC 123x xyz</b></p>',
|
2017-03-06 08:57:49 +00:00
|
|
|
rangeOrSelection: new ve.Range( 1, 9 ),
|
2015-08-18 20:24:45 +00:00
|
|
|
method: 'autolinkMagicLink',
|
2017-03-06 08:57:49 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 1, 9 ),
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedData: function () {
|
2015-08-18 20:24:45 +00:00
|
|
|
/* no change, no link */
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Autolink valid PMID',
|
2015-09-15 21:27:28 +00:00
|
|
|
html: '<p><b>PMID 1234 xyz</b></p>',
|
2017-03-06 08:57:49 +00:00
|
|
|
rangeOrSelection: new ve.Range( 1, 10 ),
|
2015-08-18 20:24:45 +00:00
|
|
|
method: 'autolinkMagicLink',
|
2017-03-06 08:57:49 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 3 ),
|
|
|
|
expectedOriginalRangeOrSelection: new ve.Range( 10 ),
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedData: function ( data ) {
|
2015-09-15 20:59:58 +00:00
|
|
|
data.splice( 1, 9, {
|
|
|
|
type: 'link/mwMagic',
|
|
|
|
attributes: {
|
|
|
|
content: 'PMID 1234'
|
2015-09-15 21:27:28 +00:00
|
|
|
},
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
2015-09-15 20:59:58 +00:00
|
|
|
}, {
|
2015-09-15 21:27:28 +00:00
|
|
|
type: '/link/mwMagic',
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
2015-09-15 20:59:58 +00:00
|
|
|
} );
|
2016-05-11 11:57:36 +00:00
|
|
|
},
|
|
|
|
undo: true
|
2015-08-18 20:24:45 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Don\'t autolink invalid PMID',
|
2015-09-15 21:27:28 +00:00
|
|
|
html: '<p><b>PMID 123x xyz</b></p>',
|
2017-03-06 08:57:49 +00:00
|
|
|
rangeOrSelection: new ve.Range( 1, 10 ),
|
2015-08-18 20:24:45 +00:00
|
|
|
method: 'autolinkMagicLink',
|
2017-03-06 08:57:49 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 1, 10 ),
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedData: function () {
|
2015-08-18 20:24:45 +00:00
|
|
|
/* no change, no link */
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Autolink valid ISBN',
|
2015-09-15 21:27:28 +00:00
|
|
|
html: '<p><b>ISBN 978-0596517748 xyz</b></p>',
|
2017-03-06 08:57:49 +00:00
|
|
|
rangeOrSelection: new ve.Range( 1, 20 ),
|
2015-08-18 20:24:45 +00:00
|
|
|
method: 'autolinkMagicLink',
|
2017-03-06 08:57:49 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 3 ),
|
|
|
|
expectedOriginalRangeOrSelection: new ve.Range( 20 ),
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedData: function ( data ) {
|
2015-09-15 20:59:58 +00:00
|
|
|
data.splice( 1, 19, {
|
|
|
|
type: 'link/mwMagic',
|
|
|
|
attributes: {
|
|
|
|
content: 'ISBN 978-0596517748'
|
2015-09-15 21:27:28 +00:00
|
|
|
},
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
2015-09-15 20:59:58 +00:00
|
|
|
}, {
|
2015-09-15 21:27:28 +00:00
|
|
|
type: '/link/mwMagic',
|
|
|
|
annotations: data[ 1 ][ 1 ]
|
2015-09-15 20:59:58 +00:00
|
|
|
} );
|
2016-05-11 11:57:36 +00:00
|
|
|
},
|
|
|
|
undo: true
|
2015-08-18 20:24:45 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Don\'t autolink invalid ISBN',
|
2015-09-15 21:27:28 +00:00
|
|
|
html: '<p><b>ISBN 978-059651774 xyz</b></p>',
|
2017-03-06 08:57:49 +00:00
|
|
|
rangeOrSelection: new ve.Range( 1, 19 ),
|
2015-08-18 20:24:45 +00:00
|
|
|
method: 'autolinkMagicLink',
|
2017-03-06 08:57:49 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( 1, 19 ),
|
2016-05-11 11:57:36 +00:00
|
|
|
expectedData: function () {
|
2015-08-18 20:24:45 +00:00
|
|
|
/* no change, no link */
|
|
|
|
}
|
2015-08-17 16:28:57 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
2016-05-11 11:57:36 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
);
|
2015-08-17 16:28:57 +00:00
|
|
|
}
|
|
|
|
} );
|