'use strict';
/*!
* VisualEditor UserInterface MWWikitextStringTransferHandler tests.
*
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
* @license MIT
*/
QUnit.module( 've.ui.MWWikitextStringTransferHandler (Cite)', ve.test.utils.newMwEnvironment( {
beforeEach: function () {
// Mock XHR for mw.Api()
this.server = this.sandbox.useFakeServer();
}
} ) );
/* Tests */
QUnit.test( 'convert', function ( assert ) {
const cases = [
{
msg: 'Simple reference',
pasteString: '[Foo]',
pasteType: 'text/plain',
parsoidResponse: ve.dm.example.singleLine`
[1]
- ↑ Foo
`,
annotations: [],
expectedData: [
{ type: 'paragraph' },
{
type: 'mwReference',
attributes: {
listGroup: 'mwReference/',
listIndex: 0,
listKey: 'auto/0',
refGroup: '',
refListItemId: 'mw-reference-text-cite_note-1'
}
},
{ type: '/mwReference' },
{ type: '/paragraph' },
{ type: 'internalList' },
{ type: 'internalItem' },
{ type: 'paragraph', internal: { generated: 'wrapper' } },
'F', 'o', 'o',
{ type: '/paragraph' },
{ type: '/internalItem' },
{ type: '/internalList' }
]
},
{
msg: 'Reference template with autoGenerated content',
pasteString: '{{reference}}',
pasteType: 'text/plain',
parsoidResponse: ve.dm.example.singleLine`
[1]
- Reference list
`,
annotations: [],
expectedData: [
{ type: 'paragraph' },
{
type: 'mwTransclusionInline',
attributes: {
mw: {}
}
},
{
type: '/mwTransclusionInline'
},
{ type: '/paragraph' },
{ type: 'internalList' },
{ type: '/internalList' }
]
}
];
const server = this.server;
cases.forEach( function ( caseItem ) {
ve.test.utils.runWikitextStringHandlerTest(
assert, server, caseItem.pasteString, caseItem.pasteType,
caseItem.parsoidResponse, caseItem.expectedData, caseItem.annotations,
caseItem.assertDom, caseItem.msg
);
} );
} );