mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 22:35:41 +00:00
tests: MWInternalLinkAnnotation getFragment
Also, fix docs for it. It could also return null for a missing fragment. Change-Id: Ib6df379c5c3686a59026b6b66f26b3050ede231a
This commit is contained in:
parent
fefb76eebc
commit
88f3191926
|
@ -204,12 +204,12 @@ ve.dm.MWInternalLinkAnnotation.static.getLookupTitle = function ( original ) {
|
|||
*
|
||||
* @static
|
||||
* @param {string|mw.Title} original Original title
|
||||
* @return {string} Fragment for the title, or an empty string if it was invalid
|
||||
* @return {string|null} Fragment for the title, or null if it was invalid or missing
|
||||
*/
|
||||
ve.dm.MWInternalLinkAnnotation.static.getFragment = function ( original ) {
|
||||
var title = original instanceof mw.Title ? original : mw.Title.newFromText( original );
|
||||
if ( !title ) {
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
return title.getFragment();
|
||||
};
|
||||
|
|
|
@ -61,3 +61,50 @@ QUnit.test( 'toDataElement', function ( assert ) {
|
|||
assert.deepEqual( ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], converter ), cases[ i ].expected, cases[ i ].msg );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit.test( 'getFragment', function ( assert ) {
|
||||
var i, l,
|
||||
cases = [
|
||||
{
|
||||
msg: 'No fragment returns null',
|
||||
original: 'Foo',
|
||||
expected: null
|
||||
},
|
||||
{
|
||||
msg: 'Invalid title returns null',
|
||||
original: 'A%20B',
|
||||
expected: null
|
||||
},
|
||||
{
|
||||
msg: 'Blank fragment returns empty string',
|
||||
original: 'Foo#',
|
||||
expected: ''
|
||||
},
|
||||
{
|
||||
msg: 'Extant fragment returns same string',
|
||||
original: 'Foo#bar',
|
||||
expected: 'bar'
|
||||
},
|
||||
{
|
||||
msg: 'Hash-bang works returns full string',
|
||||
original: 'Foo#!bar',
|
||||
expected: '!bar'
|
||||
},
|
||||
{
|
||||
msg: 'Double-hash returns everything after the first hash',
|
||||
original: 'Foo##bar',
|
||||
expected: '#bar'
|
||||
},
|
||||
{
|
||||
msg: 'Multi-fragment returns everything after the first hash',
|
||||
original: 'Foo#bar#baz#bat',
|
||||
expected: 'bar#baz#bat'
|
||||
}
|
||||
];
|
||||
|
||||
QUnit.expect( cases.length );
|
||||
|
||||
for ( i = 0, l = cases.length; i < l; i++ ) {
|
||||
assert.deepEqual( ve.dm.MWInternalLinkAnnotation.static.getFragment( cases[ i ].original ), cases[ i ].expected, cases[ i ].msg );
|
||||
}
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue