mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 03:08:42 +00:00
dm.MWInternalLinkAnnotation: Add some test cases
Change-Id: Ie338d5538959ea2cc296886b623e9dc2cd84fa8f
This commit is contained in:
parent
550a685d70
commit
5bc54fd036
|
@ -832,6 +832,7 @@ class VisualEditorHooks {
|
|||
'modules/ve-mw/tests/dm/ve.dm.mwExample.js',
|
||||
'modules/ve-mw/tests/dm/ve.dm.Converter.test.js',
|
||||
'modules/ve-mw/tests/dm/ve.dm.MWImageModel.test.js',
|
||||
'modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js',
|
||||
// VisualEditor ContentEditable Tests
|
||||
'lib/ve/tests/ce/ve.ce.test.js',
|
||||
'lib/ve/tests/ce/ve.ce.Document.test.js',
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*!
|
||||
* VisualEditor DataModel MWInternalLinkAnnotation tests.
|
||||
*
|
||||
* @copyright 2011-2016 VisualEditor Team and others; see http://ve.mit-license.org
|
||||
*/
|
||||
|
||||
QUnit.module( 've.dm.MWInternalLinkAnnotation' );
|
||||
|
||||
QUnit.test( 'toDataElement', function ( assert ) {
|
||||
var i, l,
|
||||
doc = ve.dm.example.createExampleDocument(),
|
||||
internalLink = function ( pageTitle ) {
|
||||
var link = document.createElement( 'a' );
|
||||
link.setAttribute( 'href', location.origin + mw.Title.newFromText( pageTitle ).getUrl() );
|
||||
return link;
|
||||
},
|
||||
cases = [
|
||||
{
|
||||
msg: 'Simple',
|
||||
element: internalLink( 'Foo' ),
|
||||
expected: {
|
||||
type: 'link/mwInternal',
|
||||
attributes: {
|
||||
hrefPrefix: '',
|
||||
lookupTitle: 'Foo',
|
||||
normalizedTitle: 'Foo',
|
||||
origTitle: 'Foo',
|
||||
title: 'Foo'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
// Because percent-encoded URLs aren't valid titles, but what they decode to might be
|
||||
msg: 'Percent encoded characters',
|
||||
element: internalLink( 'Foo?' ),
|
||||
expected: {
|
||||
type: 'link/mwInternal',
|
||||
attributes: {
|
||||
hrefPrefix: '',
|
||||
lookupTitle: 'Foo?',
|
||||
normalizedTitle: 'Foo?',
|
||||
origTitle: 'Foo?',
|
||||
title: 'Foo?'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
converter = new ve.dm.Converter( ve.dm.modelRegistry, ve.dm.nodeFactory, ve.dm.annotationFactory, ve.dm.metaItemFactory );
|
||||
|
||||
// toDataElement is called during a converter run, so we need to fake up a bit of state to test it.
|
||||
// This would normally be done by ve.dm.converter.getModelFromDom.
|
||||
converter.doc = doc.getHtmlDocument();
|
||||
converter.targetDoc = doc.getHtmlDocument();
|
||||
converter.store = doc.getStore();
|
||||
converter.internalList = doc.getInternalList();
|
||||
converter.contextStack = [];
|
||||
|
||||
QUnit.expect( cases.length );
|
||||
|
||||
for ( i = 0, l = cases.length; i < l; i++ ) {
|
||||
assert.deepEqual( ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], converter ), cases[ i ].expected, cases[ i ].msg );
|
||||
}
|
||||
} );
|
Loading…
Reference in a new issue