Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232269
Change subject: Improve ve.ui.UrlStringTransferHandler.test.js
......................................................................
Improve ve.ui.UrlStringTransferHandler.test.js
Used cases instead of separate QUnit.test; also added a test for the
"DnD standard URI list with HTML" case.
Change-Id: I62e2440f294039c2a85f0258513e9f91aa3c8227
---
M tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js
1 file changed, 103 insertions(+), 73 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/69/232269/1
diff --git
a/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js
b/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js
index 8b360e0..e61e4a5 100644
--- a/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js
+++ b/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js
@@ -8,10 +8,10 @@
/* Tests */
-function runUrlStringHandlerTest( assert, string, mimeType, expectedData ) {
- var handler,
+function runUrlStringHandlerTest( assert, string, htmlString, mimeType,
expectedDataFunc, msg ) {
+ var handler, i, j,
done = assert.async(),
- item = ve.ui.DataTransferItem.static.newFromString( string,
mimeType ),
+ item = ve.ui.DataTransferItem.static.newFromString( string,
mimeType, htmlString ),
doc = ve.dm.example.createExampleDocument(),
mockSurface = {
getModel: function () {
@@ -20,9 +20,6 @@
return doc;
}
};
- },
- getImportRules: function () {
- return ve.init.mw.Target.static.importRules;
}
},
linkAction = ve.ui.actionFactory.create( 'link', mockSurface ),
@@ -30,81 +27,114 @@
return linkAction.getLinkAnnotation( href ).element;
};
+ // Invoke the handler
handler = ve.ui.dataTransferHandlerFactory.create( 'urlString',
mockSurface, item );
handler.getInsertableData().done( function ( actualData ) {
ve.dm.example.postprocessAnnotations( actualData,
doc.getStore() );
- assert.equalLinearData( actualData, expectedData(
makeLinkAnnotation ), 'data match' );
+ assert.equalLinearData( actualData, expectedDataFunc(
makeLinkAnnotation ), msg + ': data match' );
done();
} );
}
-QUnit.test( 'simple external link', 1, function ( assert ) {
- runUrlStringHandlerTest( assert, 'http://example.com', 'text/plain',
function ( makeAnnotation ) {
- var a = makeAnnotation( 'http://example.com' );
- return [
- [ 'h', [ a ] ],
- [ 't', [ a ] ],
- [ 't', [ a ] ],
- [ 'p', [ a ] ],
- [ ':', [ a ] ],
- [ '/', [ a ] ],
- [ '/', [ a ] ],
- [ 'e', [ a ] ],
- [ 'x', [ a ] ],
- [ 'a', [ a ] ],
- [ 'm', [ a ] ],
- [ 'p', [ a ] ],
- [ 'l', [ a ] ],
- [ 'e', [ a ] ],
- [ '.', [ a ] ],
- [ 'c', [ a ] ],
- [ 'o', [ a ] ],
- [ 'm', [ a ] ],
- ' '
+QUnit.test( 'paste', function ( assert ) {
+ var i,
+ cases = [
+ {
+ msg: 'Simple external link',
+ pasteString: 'http://example.com',
+ pasteType: 'text/plain',
+ expectedData: function ( makeAnnotation ) {
+ var a = makeAnnotation(
'http://example.com' );
+ return [
+ [ 'h', [ a ] ],
+ [ 't', [ a ] ],
+ [ 't', [ a ] ],
+ [ 'p', [ a ] ],
+ [ ':', [ a ] ],
+ [ '/', [ a ] ],
+ [ '/', [ a ] ],
+ [ 'e', [ a ] ],
+ [ 'x', [ a ] ],
+ [ 'a', [ a ] ],
+ [ 'm', [ a ] ],
+ [ 'p', [ a ] ],
+ [ 'l', [ a ] ],
+ [ 'e', [ a ] ],
+ [ '.', [ a ] ],
+ [ 'c', [ a ] ],
+ [ 'o', [ a ] ],
+ [ 'm', [ a ] ],
+ ' '
+ ];
+ }
+ },
+ {
+ msg: 'DnD standard URI list without HTML',
+ pasteString: '#comment\nhttp://example.com\n',
+ pasteType: 'text/uri-list',
+ expectedData: function ( makeAnnotation ) {
+ var a = makeAnnotation(
'http://example.com' );
+ return [
+ [ 'h', [ a ] ],
+ [ 't', [ a ] ],
+ [ 't', [ a ] ],
+ [ 'p', [ a ] ],
+ [ ':', [ a ] ],
+ [ '/', [ a ] ],
+ [ '/', [ a ] ],
+ [ 'e', [ a ] ],
+ [ 'x', [ a ] ],
+ [ 'a', [ a ] ],
+ [ 'm', [ a ] ],
+ [ 'p', [ a ] ],
+ [ 'l', [ a ] ],
+ [ 'e', [ a ] ],
+ [ '.', [ a ] ],
+ [ 'c', [ a ] ],
+ [ 'o', [ a ] ],
+ [ 'm', [ a ] ],
+ ' '
+ ];
+ }
+ },
+ {
+ msg: 'DnD standard URI list with HTML',
+ pasteString: '#comment\nhttp://example.com\n',
+ pasteType: 'text/uri-list',
+ pasteHtml: '<a
href="http://example.com/foo">Foo</a>',
+ expectedData: function ( makeAnnotation ) {
+ var a = makeAnnotation(
'http://example.com/foo' );
+ return [
+ [ 'F', [ a ] ],
+ [ 'o', [ a ] ],
+ [ 'o', [ a ] ],
+ ' '
+ ];
+ }
+ },
+ {
+ msg: 'Mozilla URI list',
+ pasteString: 'http://example.com\n[[Foo]]',
+ pasteType: 'text/x-moz-url',
+ expectedData: function ( makeAnnotation ) {
+ var a = makeAnnotation(
'http://example.com' );
+ return [
+ [ '[', [ a ] ],
+ [ '[', [ a ] ],
+ [ 'F', [ a ] ],
+ [ 'o', [ a ] ],
+ [ 'o', [ a ] ],
+ [ ']', [ a ] ],
+ [ ']', [ a ] ],
+ ' '
+ ];
+ }
+ }
];
- } );
-} );
-QUnit.test( 'DnD standard URI list', 1, function ( assert ) {
- runUrlStringHandlerTest( assert, '#comment\nhttp://example.com\n',
'text/uri-list', function ( makeAnnotation ) {
- var a = makeAnnotation( 'http://example.com' );
- return [
- [ 'h', [ a ] ],
- [ 't', [ a ] ],
- [ 't', [ a ] ],
- [ 'p', [ a ] ],
- [ ':', [ a ] ],
- [ '/', [ a ] ],
- [ '/', [ a ] ],
- [ 'e', [ a ] ],
- [ 'x', [ a ] ],
- [ 'a', [ a ] ],
- [ 'm', [ a ] ],
- [ 'p', [ a ] ],
- [ 'l', [ a ] ],
- [ 'e', [ a ] ],
- [ '.', [ a ] ],
- [ 'c', [ a ] ],
- [ 'o', [ a ] ],
- [ 'm', [ a ] ],
- ' '
- ];
- } );
-} );
-
-QUnit.test( 'Mozilla URI list', 1, function ( assert ) {
- runUrlStringHandlerTest( assert, 'http://example.com\n[[Foo]]',
'text/x-moz-url', function ( makeAnnotation ) {
- var a = makeAnnotation( 'http://example.com' );
- return [
- [ '[', [ a ] ],
- [ '[', [ a ] ],
- [ 'F', [ a ] ],
- [ 'o', [ a ] ],
- [ 'o', [ a ] ],
- [ ']', [ a ] ],
- [ ']', [ a ] ],
- ' '
- ];
- } );
+ QUnit.expect( cases.length );
+ for ( i = 0; i < cases.length; i++ ) {
+ runUrlStringHandlerTest( assert, cases[i].pasteString,
cases[i].pasteHtml, cases[i].pasteType, cases[i].expectedData, cases[i].msg );
+ }
} );
--
To view, visit https://gerrit.wikimedia.org/r/232269
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I62e2440f294039c2a85f0258513e9f91aa3c8227
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits