mediawiki-extensions-Cite/tests/qunit/ve-cite/ve.ui.MWUseExistingReferenceCommand.test.js
Adam Wight b3e8737829 Fix regression to auto-save
Cite's MWDocumentReferences included a Document, which caused
auto-save serialization to fail silently on the cyclical reference.

This patch moves the caching to per-instance scope, which was the
better choice to begin with.  The document refs are recalculated after
each change anyway, and caching is only necessary to work around an
awkward control flow in which each ReferenceNode is responsible for
its footnote number.

Bug: T377484
Change-Id: Iebe4befd603fe07d9da2a5bb6126228ec4d5dfea
2024-10-20 11:00:03 +02:00

34 lines
900 B
JavaScript

'use strict';
QUnit.module( 've.ui.MWUseExistingReferenceCommand (Cite)', ve.test.utils.newMwEnvironment() );
function getFragmentMock( hasRefs ) {
const docRefsMock = {
hasRefs: () => hasRefs
};
return {
getDocument: () => ( {
extCiteDocumentReferences: docRefsMock,
getOriginalDocument: () => undefined
} ),
getSelection: () => ( {
getName: () => 'linear'
} )
};
}
QUnit.test( 'Constructor', ( assert ) => {
const command = new ve.ui.MWUseExistingReferenceCommand();
assert.strictEqual( command.name, 'reference/existing' );
assert.strictEqual( command.action, 'window' );
assert.strictEqual( command.method, 'open' );
} );
QUnit.test( 'isExecutable', ( assert ) => {
const command = new ve.ui.MWUseExistingReferenceCommand();
assert.false( command.isExecutable( getFragmentMock( false ) ) );
assert.true( command.isExecutable( getFragmentMock( true ) ) );
} );