mediawiki-extensions-Cite/tests/qunit/ve-cite/ve.dm.MWReferenceNode.test.js
Ed Sanders 5a2154de38 ESLint: Enforce prefer-arrow-callback
Change-Id: I8d96b69e8c15bc8ad84cfb0c511396e5b3e7ac20
2024-06-03 12:31:33 +01:00

42 lines
1.5 KiB
JavaScript

'use strict';
QUnit.module( 've.dm.MWReferenceNode (Cite)', ve.test.utils.newMwEnvironment() );
QUnit.test( 'getGroup', ( assert ) => {
const dataElement = { attributes: { refGroup: 'g' } };
assert.deepEqual( ve.dm.MWReferenceNode.static.getGroup( dataElement ), 'g' );
} );
QUnit.test( 'cloneElement', ( assert ) => {
const element = {
attributes: { contentsUsed: true, mw: {}, originalMw: {} }
};
const store = { value: () => false };
const clone = ve.dm.MWReferenceNode.static.cloneElement( element, store );
assert.deepEqual( clone.attributes, {} );
assert.true( isFinite( clone.originalDomElementsHash ) );
} );
QUnit.test( 'getHashObject', ( assert ) => {
const dataElement = { type: 'T', attributes: { listGroup: 'L' } };
assert.deepEqual( ve.dm.MWReferenceNode.static.getHashObject( dataElement ), dataElement );
// FIXME: Shouldn't this behave different?
assert.deepEqual( ve.dm.MWReferenceNode.static.getInstanceHashObject( dataElement ),
dataElement );
} );
QUnit.test( 'describeChange', ( assert ) => {
for ( const [ key, change, expected ] of [
[ 'refGroup', { to: 'b' }, 'cite-ve-changedesc-ref-group-to,<ins>b</ins>' ],
[ 'refGroup', { from: 'a' }, 'cite-ve-changedesc-ref-group-from,<del>a</del>' ],
[ 'refGroup', { from: 'a', to: 'b' }, 'cite-ve-changedesc-ref-group-both,<del>a</del>,<ins>b</ins>' ],
[ '', {}, undefined ]
] ) {
let msg = ve.dm.MWReferenceNode.static.describeChange( key, change );
if ( Array.isArray( msg ) ) {
msg = $( '<span>' ).append( msg ).html();
}
assert.strictEqual( msg, expected );
}
} );