Debian Codegraph @

extensions/Cite/tests/qunit/ve-cite/ve.ui.MWWikitextStringTransferHandler.test.js

raw symbols SCIP
1 'use strict';
2
3 /*!
4 * VisualEditor UserInterface MWWikitextStringTransferHandler tests.
5 *
6 * @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
7 * @license MIT
8 */
9
10 QUnit.module( 've.ui.MWWikitextStringTransferHandler (Cite)', ve.test.utils.newMwEnvironment( {
11 beforeEach: function () {
12 // Mock XHR for mw.Api()
13 this.server = this.sandbox.useFakeServer();
14 }
15 } ) );
16
17 /* Tests */
18
19 QUnit.test( 'convert', function ( assert ) {
20 const cases = [
21 {
22 msg: 'Simple reference',
23 pasteString: '<ref>Foo</ref>',
24 pasteType: 'text/plain',
25 parsoidResponse: ve.dm.example.singleLine`
26 <p>
27 <span about="#mwt2" class="mw-ref reference" id="cite_ref-1"
28 rel="dc:references" typeof="mw:Extension/ref" data-mw=\'{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}\'>[1]</span>
29 </p>
30 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{},"autoGenerated":true}'>
31 <li about="#cite_note-1" id="cite_note-1">↑ <span id="mw-reference-text-cite_note-1" class="mw-reference-text">Foo</span></li>
32 </ol>
33 `,
34 annotations: [],
35 expectedData: [
36 { type: 'paragraph' },
37 {
38 type: 'mwReference',
39 attributes: {
40 listGroup: 'mwReference/',
41 listIndex: 0,
42 listKey: 'auto/0',
43 refGroup: '',
44 refListItemId: 'mw-reference-text-cite_note-1'
45 }
46 },
47 { type: '/mwReference' },
48 { type: '/paragraph' },
49 { type: 'internalList' },
50 { type: 'internalItem' },
51 { type: 'paragraph', internal: { generated: 'wrapper' } },
52 'F', 'o', 'o',
53 { type: '/paragraph' },
54 { type: '/internalItem' },
55 { type: '/internalList' }
56 ]
57 },
58 {
59 msg: 'Reference template with autoGenerated content',
60 pasteString: '{{reference}}',
61 pasteType: 'text/plain',
62 parsoidResponse: ve.dm.example.singleLine`
63 <p><span typeof="mw:Transclusion">[1]</span></p>
64 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{},"autoGenerated":true}'>
65 <li>Reference list</li>
66 </ol>
67 `,
68 annotations: [],
69 expectedData: [
70 { type: 'paragraph' },
71 {
72 type: 'mwTransclusionInline',
73 attributes: {
74 mw: {}
75 }
76 },
77 {
78 type: '/mwTransclusionInline'
79 },
80 { type: '/paragraph' },
81 { type: 'internalList' },
82 { type: '/internalList' }
83 ]
84 }
85 ];
86
87 const server = this.server;
88 cases.forEach( ( caseItem ) => {
89 ve.test.utils.runWikitextStringHandlerTest(
90 assert, server, caseItem.pasteString, caseItem.pasteType,
91 caseItem.parsoidResponse, caseItem.expectedData, caseItem.annotations,
92 caseItem.assertDom, caseItem.msg
93 );
94 } );
95 } );