mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-23 03:23:09 +00:00
Merge "Update all tests in the ve-mw module to use ES6 syntax"
This commit is contained in:
commit
bbd80ea563
|
@ -10,7 +10,8 @@
|
||||||
"--external": "HTMLDocument,HTMLBodyElement,HTMLHtmlElement,Window,Node,Text,Set,Range,Selection,ClientRect,File,FileList,Blob,DataTransfer,DataTransferItem,KeyboardEvent,MouseEvent,Promise,Storage",
|
"--external": "HTMLDocument,HTMLBodyElement,HTMLHtmlElement,Window,Node,Text,Set,Range,Selection,ClientRect,File,FileList,Blob,DataTransfer,DataTransferItem,KeyboardEvent,MouseEvent,Promise,Storage",
|
||||||
"--warnings": [ "-nodoc(class,public)", "-global" ],
|
"--warnings": [ "-nodoc(class,public)", "-global" ],
|
||||||
"--exclude": [
|
"--exclude": [
|
||||||
"lib/ve/rebaser/src/dm/"
|
"lib/ve/rebaser/src/dm/",
|
||||||
|
"modules/ve-mw/tests/"
|
||||||
],
|
],
|
||||||
"--": [
|
"--": [
|
||||||
".jsduck/external.js",
|
".jsduck/external.js",
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
{
|
{
|
||||||
"extends": [
|
"extends": [
|
||||||
"wikimedia/qunit",
|
"wikimedia/qunit",
|
||||||
"../../../.eslintrc.json"
|
"../../../.eslintrc.json",
|
||||||
|
"wikimedia/language/es6"
|
||||||
],
|
],
|
||||||
"env": {
|
|
||||||
"es6": true
|
|
||||||
},
|
|
||||||
"globals": {
|
"globals": {
|
||||||
"sinon": false
|
"sinon": false
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"compat/compat": [ "error", "last 2 chrome versions, last 2 firefox versions" ],
|
"compat/compat": [ "error", "last 2 chrome versions, last 2 firefox versions" ],
|
||||||
|
"indent": "off",
|
||||||
"no-jquery/no-parse-html-literal": "off"
|
"no-jquery/no-parse-html-literal": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,7 @@ QUnit.module( 've.ce.ContentBranchNode (MW)', ve.test.utils.mwEnvironment );
|
||||||
|
|
||||||
// FIXME runner copypasted from core, use data provider
|
// FIXME runner copypasted from core, use data provider
|
||||||
QUnit.test( 'getRenderedContents', function ( assert ) {
|
QUnit.test( 'getRenderedContents', function ( assert ) {
|
||||||
var i, len, doc, $wrapper,
|
const cases = [ {
|
||||||
cases = [ {
|
|
||||||
msg: 'Annotation spanning text and inline nodes',
|
msg: 'Annotation spanning text and inline nodes',
|
||||||
data: [
|
data: [
|
||||||
{ type: 'paragraph' },
|
{ type: 'paragraph' },
|
||||||
|
@ -40,9 +39,9 @@ QUnit.test( 'getRenderedContents', function ( assert ) {
|
||||||
'</b>'
|
'</b>'
|
||||||
} ];
|
} ];
|
||||||
|
|
||||||
for ( i = 0, len = cases.length; i < len; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( cases[ i ].data ) );
|
const doc = new ve.dm.Document( ve.dm.example.preprocessAnnotations( cases[ i ].data ) ),
|
||||||
$wrapper = $( new ve.ce.ParagraphNode( doc.getDocumentNode().getChildren()[ 0 ] ).getRenderedContents() );
|
$wrapper = $( new ve.ce.ParagraphNode( doc.getDocumentNode().getChildren()[ 0 ] ).getRenderedContents() );
|
||||||
// HACK strip out all the class="ve-ce-textStyleAnnotation ve-ce-textStyleBoldAnnotation" crap
|
// HACK strip out all the class="ve-ce-textStyleAnnotation ve-ce-textStyleBoldAnnotation" crap
|
||||||
$wrapper.find( '.ve-ce-textStyleAnnotation' ).removeAttr( 'class' );
|
$wrapper.find( '.ve-ce-textStyleAnnotation' ).removeAttr( 'class' );
|
||||||
assert.equalDomElement( $wrapper[ 0 ], $( '<div>' ).html( cases[ i ].html )[ 0 ], cases[ i ].msg );
|
assert.equalDomElement( $wrapper[ 0 ], $( '<div>' ).html( cases[ i ].html )[ 0 ], cases[ i ].msg );
|
||||||
|
|
|
@ -9,15 +9,14 @@ QUnit.module( 've.ce.Document (MW)' );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'Converter tests', function ( assert ) {
|
QUnit.test( 'Converter tests', function ( assert ) {
|
||||||
var msg, model, view, caseItem, $documentElement,
|
const cases = ve.dm.mwExample.domToDataCases;
|
||||||
cases = ve.dm.mwExample.domToDataCases;
|
|
||||||
|
|
||||||
for ( msg in cases ) {
|
for ( const msg in cases ) {
|
||||||
if ( cases[ msg ].ceHtml ) {
|
if ( cases[ msg ].ceHtml ) {
|
||||||
caseItem = ve.copy( cases[ msg ] );
|
const caseItem = ve.copy( cases[ msg ] ),
|
||||||
model = ve.test.utils.getModelFromTestCase( caseItem );
|
model = ve.test.utils.getModelFromTestCase( caseItem ),
|
||||||
view = new ve.ce.Document( model );
|
view = new ve.ce.Document( model ),
|
||||||
$documentElement = view.getDocumentNode().$element;
|
$documentElement = view.getDocumentNode().$element;
|
||||||
// Simplify slugs
|
// Simplify slugs
|
||||||
$documentElement.find( '.ve-ce-branchNode-slug' ).contents().remove();
|
$documentElement.find( '.ve-ce-branchNode-slug' ).contents().remove();
|
||||||
assert.equalDomElement(
|
assert.equalDomElement(
|
||||||
|
|
|
@ -10,8 +10,7 @@ QUnit.module( 've.ce.Surface (MW)', ve.test.utils.mwEnvironment );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'handleLinearDelete', function ( assert ) {
|
QUnit.test( 'handleLinearDelete', function ( assert ) {
|
||||||
var done = assert.async(),
|
const done = assert.async(),
|
||||||
promise = Promise.resolve(),
|
|
||||||
blocklength = ve.dm.mwExample.MWBlockImage.data.length,
|
blocklength = ve.dm.mwExample.MWBlockImage.data.length,
|
||||||
cases = [
|
cases = [
|
||||||
// This asserts that getRelativeRange (via getRelativeOffset) doesn't try to
|
// This asserts that getRelativeRange (via getRelativeOffset) doesn't try to
|
||||||
|
@ -54,6 +53,7 @@ QUnit.test( 'handleLinearDelete', function ( assert ) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let promise = Promise.resolve();
|
||||||
cases.forEach( function ( caseItem ) {
|
cases.forEach( function ( caseItem ) {
|
||||||
promise = promise.then( function () {
|
promise = promise.then( function () {
|
||||||
return ve.test.utils.runSurfaceHandleSpecialKeyTest( assert, caseItem );
|
return ve.test.utils.runSurfaceHandleSpecialKeyTest( assert, caseItem );
|
||||||
|
@ -66,7 +66,7 @@ QUnit.test( 'handleLinearDelete', function ( assert ) {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'beforePaste/afterPaste', function ( assert ) {
|
QUnit.test( 'beforePaste/afterPaste', function ( assert ) {
|
||||||
var cases = [
|
const cases = [
|
||||||
{
|
{
|
||||||
documentHtml: '<p></p>',
|
documentHtml: '<p></p>',
|
||||||
rangeOrSelection: new ve.Range( 1 ),
|
rangeOrSelection: new ve.Range( 1 ),
|
||||||
|
|
|
@ -10,7 +10,7 @@ QUnit.module( 've.dm.MWTransclusionNode', ve.test.utils.mwEnvironment );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'getWikitext', function ( assert ) {
|
QUnit.test( 'getWikitext', function ( assert ) {
|
||||||
var i, node, cases = [
|
const cases = [
|
||||||
{
|
{
|
||||||
msg: 'mix of numbered and named parameters',
|
msg: 'mix of numbered and named parameters',
|
||||||
mw: {
|
mw: {
|
||||||
|
@ -103,8 +103,8 @@ QUnit.test( 'getWikitext', function ( assert ) {
|
||||||
wikitext: '{{foo|bar=[[baz|quux]]}}'
|
wikitext: '{{foo|bar=[[baz|quux]]}}'
|
||||||
} ];
|
} ];
|
||||||
|
|
||||||
for ( i = 0; i < cases.length; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
node = new ve.dm.MWTransclusionNode(
|
const node = new ve.dm.MWTransclusionNode(
|
||||||
{ type: 'mwTransclusion', attributes: { mw: cases[ i ].mw } }
|
{ type: 'mwTransclusion', attributes: { mw: cases[ i ].mw } }
|
||||||
);
|
);
|
||||||
assert.strictEqual( node.getWikitext(), cases[ i ].wikitext, cases[ i ].msg );
|
assert.strictEqual( node.getWikitext(), cases[ i ].wikitext, cases[ i ].msg );
|
||||||
|
|
|
@ -8,11 +8,10 @@
|
||||||
QUnit.module( 've.dm.Converter (MW)', ve.test.utils.mwEnvironment );
|
QUnit.module( 've.dm.Converter (MW)', ve.test.utils.mwEnvironment );
|
||||||
|
|
||||||
QUnit.test( 'getModelFromDom', function ( assert ) {
|
QUnit.test( 'getModelFromDom', function ( assert ) {
|
||||||
var msg, caseItem,
|
const cases = ve.dm.mwExample.domToDataCases;
|
||||||
cases = ve.dm.mwExample.domToDataCases;
|
|
||||||
|
|
||||||
for ( msg in cases ) {
|
for ( const msg in cases ) {
|
||||||
caseItem = ve.copy( cases[ msg ] );
|
const caseItem = ve.copy( cases[ msg ] );
|
||||||
if ( caseItem.mwConfig ) {
|
if ( caseItem.mwConfig ) {
|
||||||
mw.config.set( caseItem.mwConfig );
|
mw.config.set( caseItem.mwConfig );
|
||||||
}
|
}
|
||||||
|
@ -22,11 +21,10 @@ QUnit.test( 'getModelFromDom', function ( assert ) {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'getDomFromModel', function ( assert ) {
|
QUnit.test( 'getDomFromModel', function ( assert ) {
|
||||||
var msg, caseItem,
|
const cases = ve.dm.mwExample.domToDataCases;
|
||||||
cases = ve.dm.mwExample.domToDataCases;
|
|
||||||
|
|
||||||
for ( msg in cases ) {
|
for ( const msg in cases ) {
|
||||||
caseItem = ve.copy( cases[ msg ] );
|
const caseItem = ve.copy( cases[ msg ] );
|
||||||
if ( caseItem.mwConfig ) {
|
if ( caseItem.mwConfig ) {
|
||||||
mw.config.set( caseItem.mwConfig );
|
mw.config.set( caseItem.mwConfig );
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,7 @@ QUnit.module( 've.dm.Document (MW)', ve.test.utils.mwEnvironment );
|
||||||
|
|
||||||
// FIXME runner copypasted from core, use data provider
|
// FIXME runner copypasted from core, use data provider
|
||||||
QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert ) {
|
QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert ) {
|
||||||
var documentModel, i, j,
|
const store = new ve.dm.HashValueStore(),
|
||||||
store = new ve.dm.HashValueStore(),
|
|
||||||
storeItems = [
|
storeItems = [
|
||||||
ve.dm.mwExample.MWBlockImage.storeItems,
|
ve.dm.mwExample.MWBlockImage.storeItems,
|
||||||
ve.dm.mwExample.MWInlineImage.storeItems
|
ve.dm.mwExample.MWInlineImage.storeItems
|
||||||
|
@ -228,14 +227,14 @@ QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for ( i = 0; i < storeItems.length; i++ ) {
|
for ( let i = 0; i < storeItems.length; i++ ) {
|
||||||
for ( j = 0; j < storeItems[ i ].length; j++ ) {
|
for ( let j = 0; j < storeItems[ i ].length; j++ ) {
|
||||||
store.hash( storeItems[ i ][ j ].value, storeItems[ i ][ j ].hash );
|
store.hash( storeItems[ i ][ j ].value, storeItems[ i ][ j ].hash );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( i = 0; i < tests.length; i++ ) {
|
for ( let i = 0; i < tests.length; i++ ) {
|
||||||
documentModel = new ve.dm.Document( new ve.dm.ElementLinearData( store, tests[ i ].data ) );
|
const documentModel = new ve.dm.Document( new ve.dm.ElementLinearData( store, tests[ i ].data ) );
|
||||||
for ( j = 0; j < tests[ i ].cases.length; j++ ) {
|
for ( let j = 0; j < tests[ i ].cases.length; j++ ) {
|
||||||
assert.equalRange(
|
assert.equalRange(
|
||||||
documentModel.getRelativeRange(
|
documentModel.getRelativeRange(
|
||||||
tests[ i ].cases[ j ].given,
|
tests[ i ].cases[ j ].given,
|
||||||
|
|
|
@ -10,8 +10,7 @@ QUnit.module( 've.dm.MWImageModel', ve.test.utils.mwEnvironment );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'Create and manipulate image nodes', function ( assert ) {
|
QUnit.test( 'Create and manipulate image nodes', function ( assert ) {
|
||||||
var i, imageType, imageModel, value, result, expected, expectedAlignment, method, dir, dummyDoc,
|
const imageNode = {},
|
||||||
imageNode = {},
|
|
||||||
images = {
|
images = {
|
||||||
mwInlineImage: {
|
mwInlineImage: {
|
||||||
dir: 'ltr',
|
dir: 'ltr',
|
||||||
|
@ -115,7 +114,7 @@ QUnit.test( 'Create and manipulate image nodes', function ( assert ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for ( imageType in images ) {
|
for ( const imageType in images ) {
|
||||||
// Create the node
|
// Create the node
|
||||||
imageNode[ imageType ] = ve.dm.MWImageModel.static.createImageNode(
|
imageNode[ imageType ] = ve.dm.MWImageModel.static.createImageNode(
|
||||||
images[ imageType ].attrs,
|
images[ imageType ].attrs,
|
||||||
|
@ -130,23 +129,23 @@ QUnit.test( 'Create and manipulate image nodes', function ( assert ) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Run tests
|
// Run tests
|
||||||
for ( i = 0; i < images[ imageType ].tests.length; i++ ) {
|
for ( let i = 0; i < images[ imageType ].tests.length; i++ ) {
|
||||||
dir = images[ imageType ].dir;
|
const dir = images[ imageType ].dir,
|
||||||
dummyDoc = new ve.dm.Document( [], null, null, null, null, 'en', images[ imageType ].dir );
|
dummyDoc = new ve.dm.Document( [], null, null, null, null, 'en', images[ imageType ].dir );
|
||||||
|
|
||||||
// Start from original details
|
// Start from original details
|
||||||
imageModel = ve.dm.MWImageModel.static.newFromImageAttributes( images[ imageType ].attrs, dummyDoc );
|
const imageModel = ve.dm.MWImageModel.static.newFromImageAttributes( images[ imageType ].attrs, dummyDoc );
|
||||||
|
|
||||||
// Run attributes
|
// Run attributes
|
||||||
for ( method in images[ imageType ].tests[ i ].methods ) {
|
for ( const method in images[ imageType ].tests[ i ].methods ) {
|
||||||
value = images[ imageType ].tests[ i ].methods[ method ];
|
const value = images[ imageType ].tests[ i ].methods[ method ];
|
||||||
imageModel[ method ]( value );
|
imageModel[ method ]( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check result
|
// Check result
|
||||||
for ( method in images[ imageType ].tests[ i ].results.expect ) {
|
for ( const method in images[ imageType ].tests[ i ].results.expect ) {
|
||||||
result = imageModel[ method ]();
|
const result = imageModel[ method ](),
|
||||||
expected = images[ imageType ].tests[ i ].results.expect[ method ];
|
expected = images[ imageType ].tests[ i ].results.expect[ method ];
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
result,
|
result,
|
||||||
expected,
|
expected,
|
||||||
|
@ -156,6 +155,7 @@ QUnit.test( 'Create and manipulate image nodes', function ( assert ) {
|
||||||
|
|
||||||
// Run language-specific tests
|
// Run language-specific tests
|
||||||
if ( images[ imageType ].tests[ i ].results.position ) {
|
if ( images[ imageType ].tests[ i ].results.position ) {
|
||||||
|
let expectedAlignment;
|
||||||
// Definition:
|
// Definition:
|
||||||
// * withText (document direction; 'left' for ltr, 'right' for rtl)
|
// * withText (document direction; 'left' for ltr, 'right' for rtl)
|
||||||
// * oppositeToText (opposite the document direction; 'right' for ltr, 'left' for rtl)
|
// * oppositeToText (opposite the document direction; 'right' for ltr, 'left' for rtl)
|
||||||
|
|
|
@ -7,15 +7,14 @@
|
||||||
QUnit.module( 've.dm.MWInternalLinkAnnotation' );
|
QUnit.module( 've.dm.MWInternalLinkAnnotation' );
|
||||||
|
|
||||||
QUnit.test( 'toDataElement', function ( assert ) {
|
QUnit.test( 'toDataElement', function ( assert ) {
|
||||||
var i, l,
|
const doc = ve.dm.example.createExampleDocument(),
|
||||||
doc = ve.dm.example.createExampleDocument(),
|
|
||||||
externalLink = function ( href ) {
|
externalLink = function ( href ) {
|
||||||
var link = document.createElement( 'a' );
|
const link = document.createElement( 'a' );
|
||||||
link.setAttribute( 'href', href );
|
link.setAttribute( 'href', href );
|
||||||
return link;
|
return link;
|
||||||
},
|
},
|
||||||
internalLink = function ( pageTitle, params ) {
|
internalLink = function ( pageTitle, params ) {
|
||||||
var link = document.createElement( 'a' );
|
const link = document.createElement( 'a' );
|
||||||
link.setAttribute( 'href', location.origin + mw.Title.newFromText( pageTitle ).getUrl( params ) );
|
link.setAttribute( 'href', location.origin + mw.Title.newFromText( pageTitle ).getUrl( params ) );
|
||||||
return link;
|
return link;
|
||||||
},
|
},
|
||||||
|
@ -130,14 +129,13 @@ QUnit.test( 'toDataElement', function ( assert ) {
|
||||||
converter.contextStack = [];
|
converter.contextStack = [];
|
||||||
converter.fromClipboard = true;
|
converter.fromClipboard = true;
|
||||||
|
|
||||||
for ( i = 0, l = cases.length; i < l; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
assert.deepEqual( ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], converter ), cases[ i ].expected, cases[ i ].msg );
|
assert.deepEqual( ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], converter ), cases[ i ].expected, cases[ i ].msg );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'getFragment', function ( assert ) {
|
QUnit.test( 'getFragment', function ( assert ) {
|
||||||
var i, l,
|
const cases = [
|
||||||
cases = [
|
|
||||||
{
|
{
|
||||||
msg: 'No fragment returns null',
|
msg: 'No fragment returns null',
|
||||||
original: 'Foo',
|
original: 'Foo',
|
||||||
|
@ -175,7 +173,7 @@ QUnit.test( 'getFragment', function ( assert ) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for ( i = 0, l = cases.length; i < l; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
assert.strictEqual( ve.dm.MWInternalLinkAnnotation.static.getFragment( cases[ i ].original ), cases[ i ].expected, cases[ i ].msg );
|
assert.strictEqual( ve.dm.MWInternalLinkAnnotation.static.getFragment( cases[ i ].original ), cases[ i ].expected, cases[ i ].msg );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
( function () {
|
( function () {
|
||||||
var transclusionData = {
|
const transclusionData = {
|
||||||
params: {
|
params: {
|
||||||
foo: { wt: 'Foo value' },
|
foo: { wt: 'Foo value' },
|
||||||
bar: { wt: 'Bar value' },
|
bar: { wt: 'Bar value' },
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
* @return {ve.dm.MWTemplateModel}
|
* @return {ve.dm.MWTemplateModel}
|
||||||
*/
|
*/
|
||||||
function newTemplateModel() {
|
function newTemplateModel() {
|
||||||
var doc = ve.dm.Document.static.newBlankDocument(),
|
const doc = ve.dm.Document.static.newBlankDocument(),
|
||||||
transclusion = new ve.dm.MWTransclusionModel( doc ),
|
transclusion = new ve.dm.MWTransclusionModel( doc ),
|
||||||
clonedTransclusionData = ve.extendObject( {}, transclusionData );
|
clonedTransclusionData = ve.extendObject( {}, transclusionData );
|
||||||
|
|
||||||
|
@ -36,46 +36,43 @@
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'serialize input parameters', function ( assert ) {
|
QUnit.test( 'serialize input parameters', function ( assert ) {
|
||||||
var templateModel = newTemplateModel(),
|
const templateModel = newTemplateModel(),
|
||||||
serializedTransclusionData = templateModel.serialize();
|
serializedTransclusionData = templateModel.serialize();
|
||||||
|
|
||||||
assert.deepEqual( serializedTransclusionData, { template: transclusionData } );
|
assert.deepEqual( serializedTransclusionData, { template: transclusionData } );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'serialize changed input parameters', function ( assert ) {
|
QUnit.test( 'serialize changed input parameters', function ( assert ) {
|
||||||
var templateModel = newTemplateModel(),
|
const templateModel = newTemplateModel(),
|
||||||
newParameterModel = new ve.dm.MWParameterModel( templateModel, 'baz', 'Baz value' ),
|
newParameterModel = new ve.dm.MWParameterModel( templateModel, 'baz', 'Baz value' );
|
||||||
serializedTransclusionData;
|
|
||||||
|
|
||||||
templateModel.addParameter( newParameterModel );
|
templateModel.addParameter( newParameterModel );
|
||||||
|
|
||||||
serializedTransclusionData = templateModel.serialize();
|
const serializedTransclusionData = templateModel.serialize();
|
||||||
|
|
||||||
assert.deepEqual( serializedTransclusionData.template.params.baz, { wt: 'Baz value' } );
|
assert.deepEqual( serializedTransclusionData.template.params.baz, { wt: 'Baz value' } );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// T75134
|
// T75134
|
||||||
QUnit.test( 'serialize after parameter was removed', function ( assert ) {
|
QUnit.test( 'serialize after parameter was removed', function ( assert ) {
|
||||||
var templateModel = newTemplateModel(),
|
const templateModel = newTemplateModel(),
|
||||||
barParam = templateModel.getParameter( 'bar' ),
|
barParam = templateModel.getParameter( 'bar' );
|
||||||
serializedTransclusionData;
|
|
||||||
|
|
||||||
templateModel.removeParameter( barParam );
|
templateModel.removeParameter( barParam );
|
||||||
|
|
||||||
serializedTransclusionData = templateModel.serialize();
|
const serializedTransclusionData = templateModel.serialize();
|
||||||
|
|
||||||
assert.deepEqual( serializedTransclusionData.template.params, { foo: { wt: 'Foo value' }, empty: { wt: '' } } );
|
assert.deepEqual( serializedTransclusionData.template.params, { foo: { wt: 'Foo value' }, empty: { wt: '' } } );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// T101075
|
// T101075
|
||||||
QUnit.test( 'serialize without empty parameter not present in original parameter set', function ( assert ) {
|
QUnit.test( 'serialize without empty parameter not present in original parameter set', function ( assert ) {
|
||||||
var templateModel = newTemplateModel(),
|
const templateModel = newTemplateModel(),
|
||||||
newEmptyParam = new ve.dm.MWParameterModel( templateModel, 'new_empty', '' ),
|
newEmptyParam = new ve.dm.MWParameterModel( templateModel, 'new_empty', '' );
|
||||||
serializedTransclusionData;
|
|
||||||
|
|
||||||
templateModel.addParameter( newEmptyParam );
|
templateModel.addParameter( newEmptyParam );
|
||||||
|
|
||||||
serializedTransclusionData = templateModel.serialize();
|
const serializedTransclusionData = templateModel.serialize();
|
||||||
|
|
||||||
assert.deepEqual( serializedTransclusionData, { template: transclusionData } );
|
assert.deepEqual( serializedTransclusionData, { template: transclusionData } );
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
} ) );
|
} ) );
|
||||||
|
|
||||||
function runAddPartTest( assert, name, response, server, callback ) {
|
function runAddPartTest( assert, name, response, server, callback ) {
|
||||||
var doc = ve.dm.Document.static.newBlankDocument(),
|
const doc = ve.dm.Document.static.newBlankDocument(),
|
||||||
transclusion = new ve.dm.MWTransclusionModel( doc ),
|
transclusion = new ve.dm.MWTransclusionModel( doc ),
|
||||||
part = ve.dm.MWTemplateModel.newFromName( transclusion, name ),
|
part = ve.dm.MWTemplateModel.newFromName( transclusion, name ),
|
||||||
done = assert.async();
|
done = assert.async();
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
QUnit.test( 'fetch template part data', function ( assert ) {
|
QUnit.test( 'fetch template part data', function ( assert ) {
|
||||||
var response = {
|
const response = {
|
||||||
batchcomplete: '',
|
batchcomplete: '',
|
||||||
pages: {
|
pages: {
|
||||||
1331311: {
|
1331311: {
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
runAddPartTest( assert, 'Test', response, this.server, function ( transclusion ) {
|
runAddPartTest( assert, 'Test', response, this.server, function ( transclusion ) {
|
||||||
var parts = transclusion.getParts(),
|
const parts = transclusion.getParts(),
|
||||||
spec = parts[ 0 ].getSpec();
|
spec = parts[ 0 ].getSpec();
|
||||||
|
|
||||||
assert.strictEqual( parts.length, 1 );
|
assert.strictEqual( parts.length, 1 );
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
|
|
||||||
// T243868
|
// T243868
|
||||||
QUnit.test( 'fetch part data for parameterized template with no TemplateData', function ( assert ) {
|
QUnit.test( 'fetch part data for parameterized template with no TemplateData', function ( assert ) {
|
||||||
var response = {
|
const response = {
|
||||||
batchcomplete: '',
|
batchcomplete: '',
|
||||||
pages: {
|
pages: {
|
||||||
1331311: {
|
1331311: {
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
runAddPartTest( assert, 'NoData', response, this.server, function ( transclusion ) {
|
runAddPartTest( assert, 'NoData', response, this.server, function ( transclusion ) {
|
||||||
var parts = transclusion.getParts(),
|
const parts = transclusion.getParts(),
|
||||||
spec = parts[ 0 ].getSpec();
|
spec = parts[ 0 ].getSpec();
|
||||||
|
|
||||||
assert.strictEqual( parts.length, 1 );
|
assert.strictEqual( parts.length, 1 );
|
||||||
|
@ -100,7 +100,7 @@
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'fetch part data for template with no TemplateData and no params', function ( assert ) {
|
QUnit.test( 'fetch part data for template with no TemplateData and no params', function ( assert ) {
|
||||||
var response = {
|
const response = {
|
||||||
batchcomplete: '',
|
batchcomplete: '',
|
||||||
pages: {
|
pages: {
|
||||||
1331311: {
|
1331311: {
|
||||||
|
@ -112,7 +112,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
runAddPartTest( assert, 'NoParams', response, this.server, function ( transclusion ) {
|
runAddPartTest( assert, 'NoParams', response, this.server, function ( transclusion ) {
|
||||||
var parts = transclusion.getParts(),
|
const parts = transclusion.getParts(),
|
||||||
spec = parts[ 0 ].getSpec();
|
spec = parts[ 0 ].getSpec();
|
||||||
|
|
||||||
assert.strictEqual( parts.length, 1 );
|
assert.strictEqual( parts.length, 1 );
|
||||||
|
|
|
@ -29,7 +29,7 @@ QUnit.test( 'isolateAndUnwrap (MWheading)', function ( assert ) {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'insertContent (MWheading)', function ( assert ) {
|
QUnit.test( 'insertContent (MWheading)', function ( assert ) {
|
||||||
var doc = new ve.dm.Document( [
|
const doc = new ve.dm.Document( [
|
||||||
{ type: 'list', attributes: { style: 'bullet' } },
|
{ type: 'list', attributes: { style: 'bullet' } },
|
||||||
{ type: 'listItem' },
|
{ type: 'listItem' },
|
||||||
{ type: 'paragraph' },
|
{ type: 'paragraph' },
|
||||||
|
@ -42,9 +42,9 @@ QUnit.test( 'insertContent (MWheading)', function ( assert ) {
|
||||||
{ type: '/internalList' }
|
{ type: '/internalList' }
|
||||||
] ),
|
] ),
|
||||||
surface = new ve.dm.Surface( doc ),
|
surface = new ve.dm.Surface( doc ),
|
||||||
fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) ),
|
|
||||||
headingData = [ { type: 'mwHeading', attributes: { level: 3 } }, 'x', { type: '/mwHeading' } ];
|
headingData = [ { type: 'mwHeading', attributes: { level: 3 } }, 'x', { type: '/mwHeading' } ];
|
||||||
|
|
||||||
|
let fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) );
|
||||||
fragment.insertContent( headingData );
|
fragment.insertContent( headingData );
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
doc.getData( new ve.Range( 3, 14 ) ),
|
doc.getData( new ve.Range( 3, 14 ) ),
|
||||||
|
|
|
@ -665,7 +665,7 @@ ve.dm.mwExample.domToDataCases = {
|
||||||
{ type: '/internalList' }
|
{ type: '/internalList' }
|
||||||
],
|
],
|
||||||
modify: function ( model ) {
|
modify: function ( model ) {
|
||||||
var data = [ 'x', [ ve.dm.example.bold ] ],
|
const data = [ 'x', [ ve.dm.example.bold ] ],
|
||||||
linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() );
|
linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() );
|
||||||
model.data.data.splice( 3, 0, linearData.data[ 0 ] );
|
model.data.data.splice( 3, 0, linearData.data[ 0 ] );
|
||||||
},
|
},
|
||||||
|
@ -726,7 +726,7 @@ ve.dm.mwExample.domToDataCases = {
|
||||||
{ type: '/internalList' }
|
{ type: '/internalList' }
|
||||||
],
|
],
|
||||||
modify: function ( model ) {
|
modify: function ( model ) {
|
||||||
var data = [ 'x', [ ve.dm.example.bold ] ],
|
const data = [ 'x', [ ve.dm.example.bold ] ],
|
||||||
linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() );
|
linearData = ve.dm.example.preprocessAnnotations( [ data ], model.getStore() );
|
||||||
model.data.data.splice( 3, 0, linearData.data[ 0 ] );
|
model.data.data.splice( 3, 0, linearData.data[ 0 ] );
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
QUnit.module( 've.init.mw.DesktopArticleTarget', ve.test.utils.mwEnvironment );
|
QUnit.module( 've.init.mw.DesktopArticleTarget', ve.test.utils.mwEnvironment );
|
||||||
|
|
||||||
QUnit.test( 'init', function ( assert ) {
|
QUnit.test( 'init', function ( assert ) {
|
||||||
var
|
const response = {
|
||||||
response = {
|
|
||||||
visualeditor: {
|
visualeditor: {
|
||||||
result: 'success',
|
result: 'success',
|
||||||
notices: [
|
notices: [
|
||||||
|
@ -114,8 +113,7 @@ QUnit.test( 'init', function ( assert ) {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'compatibility', function ( assert ) {
|
QUnit.test( 'compatibility', function ( assert ) {
|
||||||
var profile, matches, compatibility,
|
const cases = [
|
||||||
cases = [
|
|
||||||
{
|
{
|
||||||
msg: 'Unidentified browser',
|
msg: 'Unidentified browser',
|
||||||
userAgent: 'FooBar Browser Company Version 3.141',
|
userAgent: 'FooBar Browser Company Version 3.141',
|
||||||
|
@ -248,15 +246,15 @@ QUnit.test( 'compatibility', function ( assert ) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
compatibility = {
|
const compatibility = {
|
||||||
supportedList: ve.init.mw.DesktopArticleTarget.static.compatibility.supportedList,
|
supportedList: ve.init.mw.DesktopArticleTarget.static.compatibility.supportedList,
|
||||||
// TODO: Fix this mess when we split ve.init from ve.platform
|
// TODO: Fix this mess when we split ve.init from ve.platform
|
||||||
unsupportedList: mw.libs.ve.unsupportedList
|
unsupportedList: mw.libs.ve.unsupportedList
|
||||||
};
|
};
|
||||||
|
|
||||||
cases.forEach( function ( caseItem ) {
|
cases.forEach( function ( caseItem ) {
|
||||||
profile = $.client.profile( { userAgent: caseItem.userAgent, platform: '' } );
|
const profile = $.client.profile( { userAgent: caseItem.userAgent, platform: '' } ),
|
||||||
matches = [];
|
matches = [];
|
||||||
[ 'unsupportedList', 'supportedList' ].every( function ( list ) {
|
[ 'unsupportedList', 'supportedList' ].every( function ( list ) {
|
||||||
if ( $.client.test( compatibility[ list ], profile, true ) ) {
|
if ( $.client.test( compatibility[ list ], profile, true ) ) {
|
||||||
matches.push( list );
|
matches.push( list );
|
||||||
|
|
|
@ -10,8 +10,7 @@ QUnit.module( 've.ui.FormatAction (MW)', ve.test.utils.mwEnvironment );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'convert (MW-specific types)', function ( assert ) {
|
QUnit.test( 'convert (MW-specific types)', function ( assert ) {
|
||||||
var i,
|
const cases = [
|
||||||
cases = [
|
|
||||||
{
|
{
|
||||||
rangeOrSelection: new ve.Range( 14, 16 ),
|
rangeOrSelection: new ve.Range( 14, 16 ),
|
||||||
type: 'mwHeading',
|
type: 'mwHeading',
|
||||||
|
@ -69,7 +68,7 @@ QUnit.test( 'convert (MW-specific types)', function ( assert ) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for ( i = 0; i < cases.length; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
ve.test.utils.runActionTest(
|
ve.test.utils.runActionTest(
|
||||||
'format', assert, cases[ i ].html || ve.dm.example.isolationHtml, false, 'convert',
|
'format', assert, cases[ i ].html || ve.dm.example.isolationHtml, false, 'convert',
|
||||||
[ cases[ i ].type, cases[ i ].attributes ], cases[ i ].rangeOrSelection, cases[ i ].msg,
|
[ cases[ i ].type, cases[ i ].attributes ], cases[ i ].rangeOrSelection, cases[ i ].msg,
|
||||||
|
|
|
@ -10,7 +10,7 @@ QUnit.module( 've.ui.MWLinkAction' );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'MW autolink', function ( assert ) {
|
QUnit.test( 'MW autolink', function ( assert ) {
|
||||||
var cases = [
|
const cases = [
|
||||||
{
|
{
|
||||||
msg: 'Strip trailing punctuation (but not matched parens)',
|
msg: 'Strip trailing punctuation (but not matched parens)',
|
||||||
html: '<p><b>https://en.wikipedia.org/wiki/Red_(disambiguation) xyz</b></p>',
|
html: '<p><b>https://en.wikipedia.org/wiki/Red_(disambiguation) xyz</b></p>',
|
||||||
|
@ -18,9 +18,8 @@ QUnit.test( 'MW autolink', function ( assert ) {
|
||||||
method: 'autolinkUrl',
|
method: 'autolinkUrl',
|
||||||
expectedRangeOrSelection: new ve.Range( 51 ),
|
expectedRangeOrSelection: new ve.Range( 51 ),
|
||||||
expectedData: function ( data, action ) {
|
expectedData: function ( data, action ) {
|
||||||
var i,
|
const a = action.getLinkAnnotation( 'https://en.wikipedia.org/wiki/Red_(disambiguation)' );
|
||||||
a = action.getLinkAnnotation( 'https://en.wikipedia.org/wiki/Red_(disambiguation)' );
|
for ( let i = 1; i < 51; i++ ) {
|
||||||
for ( i = 1; i < 51; i++ ) {
|
|
||||||
data[ i ][ 1 ].push( a.element );
|
data[ i ][ 1 ].push( a.element );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ QUnit.module( 've.ui.MWWikitextStringTransferHandler', QUnit.newMwEnvironment( {
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string, mimeType, expectedResponse, expectedData, annotations, assertDom, msg ) {
|
ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string, mimeType, expectedResponse, expectedData, annotations, assertDom, msg ) {
|
||||||
var handler, i, j, name,
|
const done = assert.async(),
|
||||||
done = assert.async(),
|
|
||||||
item = ve.ui.DataTransferItem.static.newFromString( string, mimeType ),
|
item = ve.ui.DataTransferItem.static.newFromString( string, mimeType ),
|
||||||
doc = ve.dm.Document.static.newBlankDocument(),
|
doc = ve.dm.Document.static.newBlankDocument(),
|
||||||
mockSurface = {
|
mockSurface = {
|
||||||
|
@ -40,9 +39,9 @@ ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Preprocess the expectedData array
|
// Preprocess the expectedData array
|
||||||
for ( i = 0; i < expectedData.length; i++ ) {
|
for ( let i = 0; i < expectedData.length; i++ ) {
|
||||||
if ( Array.isArray( expectedData[ i ] ) ) {
|
if ( Array.isArray( expectedData[ i ] ) ) {
|
||||||
for ( j = 0; j < expectedData[ i ][ 1 ].length; j++ ) {
|
for ( let j = 0; j < expectedData[ i ][ 1 ].length; j++ ) {
|
||||||
if ( typeof expectedData[ i ][ 1 ][ j ] === 'number' ) {
|
if ( typeof expectedData[ i ][ 1 ][ j ] === 'number' ) {
|
||||||
expectedData[ i ][ 1 ][ j ] = annotations[ expectedData[ i ][ 1 ][ j ] ];
|
expectedData[ i ][ 1 ][ j ] = annotations[ expectedData[ i ][ 1 ][ j ] ];
|
||||||
}
|
}
|
||||||
|
@ -51,14 +50,14 @@ ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check we match the wikitext string handler
|
// Check we match the wikitext string handler
|
||||||
name = ve.ui.dataTransferHandlerFactory.getHandlerNameForItem( item );
|
const name = ve.ui.dataTransferHandlerFactory.getHandlerNameForItem( item );
|
||||||
assert.strictEqual( name, 'wikitextString', msg + ': triggers match function' );
|
assert.strictEqual( name, 'wikitextString', msg + ': triggers match function' );
|
||||||
|
|
||||||
// Invoke the handler
|
// Invoke the handler
|
||||||
handler = ve.ui.dataTransferHandlerFactory.create( 'wikitextString', mockSurface, item );
|
const handler = ve.ui.dataTransferHandlerFactory.create( 'wikitextString', mockSurface, item );
|
||||||
|
|
||||||
handler.getInsertableData().done( function ( docOrData ) {
|
handler.getInsertableData().done( function ( docOrData ) {
|
||||||
var actualData, store;
|
let actualData, store;
|
||||||
if ( docOrData instanceof ve.dm.Document ) {
|
if ( docOrData instanceof ve.dm.Document ) {
|
||||||
actualData = docOrData.getData();
|
actualData = docOrData.getData();
|
||||||
store = docOrData.getStore();
|
store = docOrData.getStore();
|
||||||
|
@ -88,8 +87,7 @@ ve.test.utils.runWikitextStringHandlerTest = function ( assert, server, string,
|
||||||
};
|
};
|
||||||
|
|
||||||
QUnit.test( 'convert', function ( assert ) {
|
QUnit.test( 'convert', function ( assert ) {
|
||||||
var i,
|
const cases = [
|
||||||
cases = [
|
|
||||||
{
|
{
|
||||||
msg: 'Simple link',
|
msg: 'Simple link',
|
||||||
// Put link in the middle of text to verify that the
|
// Put link in the middle of text to verify that the
|
||||||
|
@ -269,7 +267,7 @@ QUnit.test( 'convert', function ( assert ) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for ( i = 0; i < cases.length; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
ve.test.utils.runWikitextStringHandlerTest(
|
ve.test.utils.runWikitextStringHandlerTest(
|
||||||
assert, this.server, cases[ i ].pasteString, cases[ i ].pasteType, cases[ i ].parsoidResponse,
|
assert, this.server, cases[ i ].pasteString, cases[ i ].pasteType, cases[ i ].parsoidResponse,
|
||||||
cases[ i ].expectedData, cases[ i ].annotations, cases[ i ].assertDom, cases[ i ].msg
|
cases[ i ].expectedData, cases[ i ].annotations, cases[ i ].assertDom, cases[ i ].msg
|
||||||
|
|
|
@ -9,15 +9,14 @@ QUnit.module( 've.ui.UrlStringTransferHandler (MW)' );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'paste', function ( assert ) {
|
QUnit.test( 'paste', function ( assert ) {
|
||||||
var i,
|
const cases = [
|
||||||
cases = [
|
|
||||||
{
|
{
|
||||||
msg: 'External link converts to internal link',
|
msg: 'External link converts to internal link',
|
||||||
pasteString: location.origin + mw.Title.newFromText( 'Main Page' ).getUrl(),
|
pasteString: location.origin + mw.Title.newFromText( 'Main Page' ).getUrl(),
|
||||||
pasteType: 'text/plain',
|
pasteType: 'text/plain',
|
||||||
expectedData: function () {
|
expectedData: function () {
|
||||||
// Explicitly create an internal link so we can assert this behaviour is working
|
// Explicitly create an internal link so we can assert this behaviour is working
|
||||||
var a = ve.dm.MWInternalLinkAnnotation.static.newFromTitle( mw.Title.newFromText( 'Main Page' ) ).element;
|
const a = ve.dm.MWInternalLinkAnnotation.static.newFromTitle( mw.Title.newFromText( 'Main Page' ) ).element;
|
||||||
return [
|
return [
|
||||||
[ 'M', [ a ] ],
|
[ 'M', [ a ] ],
|
||||||
[ 'a', [ a ] ],
|
[ 'a', [ a ] ],
|
||||||
|
@ -33,7 +32,7 @@ QUnit.test( 'paste', function ( assert ) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for ( i = 0; i < cases.length; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
ve.test.utils.runUrlStringHandlerTest( assert, cases[ i ].pasteString, cases[ i ].pasteHtml, cases[ i ].pasteType, cases[ i ].expectedData, cases[ i ].msg );
|
ve.test.utils.runUrlStringHandlerTest( assert, cases[ i ].pasteString, cases[ i ].pasteHtml, cases[ i ].pasteType, cases[ i ].expectedData, cases[ i ].msg );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -17,7 +17,7 @@ QUnit.module( 've.ui.FragmentInspector (MW)', QUnit.newMwEnvironment( {
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
QUnit.test( 'Wikitext link inspector', function ( assert ) {
|
QUnit.test( 'Wikitext link inspector', function ( assert ) {
|
||||||
var done = assert.async(),
|
const done = assert.async(),
|
||||||
surface = ve.init.target.createSurface(
|
surface = ve.init.target.createSurface(
|
||||||
ve.dm.converter.getModelFromDom(
|
ve.dm.converter.getModelFromDom(
|
||||||
ve.createDocumentFromHtml(
|
ve.createDocumentFromHtml(
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
QUnit.module( 've.ui.DiffElement (MW)', ve.test.utils.mwEnvironment );
|
QUnit.module( 've.ui.DiffElement (MW)', ve.test.utils.mwEnvironment );
|
||||||
|
|
||||||
QUnit.test( 'Diffing', function ( assert ) {
|
QUnit.test( 'Diffing', function ( assert ) {
|
||||||
var i, len,
|
const fixBase = function ( body ) {
|
||||||
fixBase = function ( body ) {
|
|
||||||
return '<html><head><base href="' + ve.dm.example.baseUri + '"></head><body>' + body + '</body>';
|
return '<html><head><base href="' + ve.dm.example.baseUri + '"></head><body>' + body + '</body>';
|
||||||
},
|
},
|
||||||
cases = [
|
cases = [
|
||||||
|
@ -47,7 +46,7 @@ QUnit.test( 'Diffing', function ( assert ) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
for ( i = 0, len = cases.length; i < len; i++ ) {
|
for ( let i = 0; i < cases.length; i++ ) {
|
||||||
ve.test.utils.runDiffElementTest( assert, cases[ i ] );
|
ve.test.utils.runDiffElementTest( assert, cases[ i ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
( function () {
|
( function () {
|
||||||
var getDomElementSummaryCore;
|
|
||||||
|
|
||||||
function MWDummyTarget() {
|
function MWDummyTarget() {
|
||||||
MWDummyTarget.super.call( this );
|
MWDummyTarget.super.call( this );
|
||||||
}
|
}
|
||||||
|
@ -40,7 +38,7 @@
|
||||||
return Array.prototype.join.call( arguments, ',' );
|
return Array.prototype.join.call( arguments, ',' );
|
||||||
};
|
};
|
||||||
MWDummyPlatform.prototype.getHtmlMessage = function () {
|
MWDummyPlatform.prototype.getHtmlMessage = function () {
|
||||||
var $wrapper = $( '<div>' );
|
const $wrapper = $( '<div>' );
|
||||||
Array.prototype.forEach.call( arguments, function ( arg, i, args ) {
|
Array.prototype.forEach.call( arguments, function ( arg, i, args ) {
|
||||||
$wrapper.append( arg );
|
$wrapper.append( arg );
|
||||||
if ( i < args.length - 1 ) {
|
if ( i < args.length - 1 ) {
|
||||||
|
@ -48,15 +46,13 @@
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
// Merge text nodes
|
// Merge text nodes
|
||||||
// eslint-disable-next-line no-restricted-properties
|
|
||||||
$wrapper[ 0 ].normalize();
|
$wrapper[ 0 ].normalize();
|
||||||
return $wrapper.contents().toArray();
|
return $wrapper.contents().toArray();
|
||||||
};
|
};
|
||||||
ve.test.utils.MWDummyPlatform = MWDummyPlatform;
|
ve.test.utils.MWDummyPlatform = MWDummyPlatform;
|
||||||
|
|
||||||
ve.test.utils.mwEnvironment = ( function () {
|
ve.test.utils.mwEnvironment = ( function () {
|
||||||
var mwPlatform, corePlatform, mwTarget, coreTarget,
|
const setEditorPreference = mw.libs.ve.setEditorPreference,
|
||||||
setEditorPreference = mw.libs.ve.setEditorPreference,
|
|
||||||
dummySetEditorPreference = function () { return ve.createDeferred().resolve().promise(); },
|
dummySetEditorPreference = function () { return ve.createDeferred().resolve().promise(); },
|
||||||
overrides = [
|
overrides = [
|
||||||
ve.dm.MWHeadingNode,
|
ve.dm.MWHeadingNode,
|
||||||
|
@ -69,22 +65,21 @@
|
||||||
ve.dm.BlockImageNode
|
ve.dm.BlockImageNode
|
||||||
];
|
];
|
||||||
|
|
||||||
corePlatform = ve.init.platform;
|
const corePlatform = ve.init.platform,
|
||||||
coreTarget = ve.init.target;
|
coreTarget = ve.init.target,
|
||||||
mwPlatform = new ve.test.utils.MWDummyPlatform();
|
mwPlatform = new ve.test.utils.MWDummyPlatform();
|
||||||
// Unregister mwPlatform
|
// Unregister mwPlatform
|
||||||
ve.init.platform = corePlatform;
|
ve.init.platform = corePlatform;
|
||||||
|
|
||||||
mwTarget = new ve.test.utils.MWDummyTarget();
|
const mwTarget = new ve.test.utils.MWDummyTarget();
|
||||||
// Unregister mwTarget
|
// Unregister mwTarget
|
||||||
ve.init.target = coreTarget;
|
ve.init.target = coreTarget;
|
||||||
|
|
||||||
function setupOverrides() {
|
function setupOverrides() {
|
||||||
var i;
|
for ( let i = 0; i < overrides.length; i++ ) {
|
||||||
for ( i = 0; i < overrides.length; i++ ) {
|
|
||||||
ve.dm.modelRegistry.register( overrides[ i ] );
|
ve.dm.modelRegistry.register( overrides[ i ] );
|
||||||
}
|
}
|
||||||
for ( i = 0; i < overridden.length; i++ ) {
|
for ( let i = 0; i < overridden.length; i++ ) {
|
||||||
ve.dm.modelRegistry.unregister( overridden[ i ] );
|
ve.dm.modelRegistry.unregister( overridden[ i ] );
|
||||||
}
|
}
|
||||||
ve.ui.windowFactory.unregister( ve.ui.LinkAnnotationInspector );
|
ve.ui.windowFactory.unregister( ve.ui.LinkAnnotationInspector );
|
||||||
|
@ -99,11 +94,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardownOverrides() {
|
function teardownOverrides() {
|
||||||
var i;
|
for ( let i = 0; i < overrides.length; i++ ) {
|
||||||
for ( i = 0; i < overrides.length; i++ ) {
|
|
||||||
ve.dm.modelRegistry.unregister( overrides[ i ] );
|
ve.dm.modelRegistry.unregister( overrides[ i ] );
|
||||||
}
|
}
|
||||||
for ( i = 0; i < overridden.length; i++ ) {
|
for ( let i = 0; i < overridden.length; i++ ) {
|
||||||
ve.dm.modelRegistry.register( overridden[ i ] );
|
ve.dm.modelRegistry.register( overridden[ i ] );
|
||||||
}
|
}
|
||||||
ve.ui.windowFactory.unregister( ve.ui.MWLinkAnnotationInspector );
|
ve.ui.windowFactory.unregister( ve.ui.MWLinkAnnotationInspector );
|
||||||
|
@ -123,7 +117,7 @@
|
||||||
};
|
};
|
||||||
}() );
|
}() );
|
||||||
|
|
||||||
getDomElementSummaryCore = ve.getDomElementSummary;
|
const getDomElementSummaryCore = ve.getDomElementSummary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override getDomElementSummary to extract HTML from data-mw/body.html
|
* Override getDomElementSummary to extract HTML from data-mw/body.html
|
||||||
|
@ -134,10 +128,9 @@
|
||||||
ve.getDomElementSummary = function ( element, includeHtml ) {
|
ve.getDomElementSummary = function ( element, includeHtml ) {
|
||||||
// "Parent" method
|
// "Parent" method
|
||||||
return getDomElementSummaryCore( element, includeHtml, function ( name, value ) {
|
return getDomElementSummaryCore( element, includeHtml, function ( name, value ) {
|
||||||
var obj, html;
|
|
||||||
if ( name === 'data-mw' ) {
|
if ( name === 'data-mw' ) {
|
||||||
obj = JSON.parse( value );
|
const obj = JSON.parse( value ),
|
||||||
html = ve.getProp( obj, 'body', 'html' );
|
html = ve.getProp( obj, 'body', 'html' );
|
||||||
if ( html ) {
|
if ( html ) {
|
||||||
obj.body.html = ve.getDomElementSummary( $( '<div>' ).html( html )[ 0 ] );
|
obj.body.html = ve.getDomElementSummary( $( '<div>' ).html( html )[ 0 ] );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue