1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*!
* VisualEditor UserInterface UrlStringTransferHandler tests.
*
* @copyright See AUTHORS.txt
*/
QUnit.module( 've.ui.UrlStringTransferHandler' );
/* Tests */
ve.test.utils.runUrlStringHandlerTest = function ( assert, string, htmlString, mimeType, expectedDataFunc, base, msg ) {
const done = assert.async(),
item = ve.ui.DataTransferItem.static.newFromString( string, mimeType, htmlString ),
doc = ve.dm.example.createExampleDocument( null, null, base ),
mockSurface = {
getModel: function () {
return {
getDocument: function () {
return doc;
}
};
}
},
linkAction = ve.ui.actionFactory.create( 'link', mockSurface ),
makeLinkAnnotation = function ( href ) {
return linkAction.getLinkAnnotation( href ).element;
};
// Invoke the handler
const handler = ve.ui.dataTransferHandlerFactory.create( 'urlString', mockSurface, item );
handler.getInsertableData().done( ( actualData ) => {
ve.dm.example.postprocessAnnotations( actualData, doc.getStore() );
assert.equalLinearData( actualData, expectedDataFunc( makeLinkAnnotation ), msg + ': data match' );
done();
} );
};
QUnit.test( 'paste', ( assert ) => {
const cases = [
{
msg: 'Simple external link',
pasteString: 'http://example.com',
pasteType: 'text/plain',
expectedData: function ( makeAnnotation ) {
const 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 ) {
const 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 ) {
const a = makeAnnotation( 'http://example.com/foo' );
return [
[ 'F', [ a ] ],
[ 'o', [ a ] ],
[ 'o', [ a ] ]
];
}
},
{
msg: 'Mozilla URI list',
pasteString: 'http://example.com\n[[Foo]]\nhttp://example.org\nBar',
pasteType: 'text/x-moz-url',
expectedData: function ( makeAnnotation ) {
const a1 = makeAnnotation( 'http://example.com' ),
a2 = makeAnnotation( 'http://example.org' );
return [
[ '[', [ a1 ] ],
[ '[', [ a1 ] ],
[ 'F', [ a1 ] ],
[ 'o', [ a1 ] ],
[ 'o', [ a1 ] ],
[ ']', [ a1 ] ],
[ ']', [ a1 ] ],
' ',
[ 'B', [ a2 ] ],
[ 'a', [ a2 ] ],
[ 'r', [ a2 ] ]
];
}
}
];
cases.forEach( ( caseItem ) => {
ve.test.utils.runUrlStringHandlerTest( assert, caseItem.pasteString, caseItem.pasteHtml, caseItem.pasteType, caseItem.expectedData, ve.dm.example.baseUri, caseItem.msg );
} );
} );
|