DLynch has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312028

Change subject: dm.MWInternalLinkAnnotation: Add some test cases
......................................................................

dm.MWInternalLinkAnnotation: Add some test cases

Change-Id: Ie338d5538959ea2cc296886b623e9dc2cd84fa8f
---
M VisualEditor.hooks.php
M lib/ve
A modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js
3 files changed, 66 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/28/312028/1

diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index fcf8124..f9eb001 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -832,6 +832,7 @@
                                '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',
diff --git a/lib/ve b/lib/ve
index ed76839..e3192e2 160000
--- a/lib/ve
+++ b/lib/ve
@@ -1 +1 @@
-Subproject commit ed7683959c28e78851480a2e0573c6fac7048771
+Subproject commit e3192e2d398fcd643b564141879d12a685173548
diff --git a/modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js 
b/modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js
new file mode 100644
index 0000000..d5bea5f
--- /dev/null
+++ b/modules/ve-mw/tests/dm/ve.dm.MWInternalLinkAnnotation.test.js
@@ -0,0 +1,64 @@
+/*!
+ * 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(),
+               linkWithAttributes = function ( attributes ) {
+                       var link = document.createElement( 'a' );
+                       ve.setDomAttributes( link, attributes );
+                       return link;
+               },
+               cases = [
+                       {
+                               msg: 'Simple',
+                               element: linkWithAttributes( { href: 
'/wiki/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',
+                               element: linkWithAttributes( { href: 
'/wiki/Foo%3F' } ),
+                               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++ ) {
+               console.log( cases[ i ] );
+               assert.deepEqual( 
ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], 
converter ), cases[ i ].expected, cases[ i ].msg );
+       }
+} );

-- 
To view, visit https://gerrit.wikimedia.org/r/312028
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie338d5538959ea2cc296886b623e9dc2cd84fa8f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <dly...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to