Debian Codegraph @

extensions/VisualEditor/lib/ve/tests/ui/datatransferhandlers/ve.ui.UrlStringTransferHandler.test.js

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