mediawiki-extensions-Cite/tests/qunit/ve-cite/ve.ui.MWUseExistingReferenceCommand.test.js
Adam Wight 6ea3a8c696 Try to always limit our document references to the current fragment
Reverses the previous logic which traversed up from a fragment to get
the full document's refs.  Much other code in VE isn't ready for this
behavior, for example we can see list-defined refs but not inline refs
defined outside of the fragment.

This patch will ensure that we're only looking at refs accessible from
the current fragment, and prevents caching on fragments because the
cache uses `persistentStorage`, which is shared between fragments and
their parent document.

Bug: T374068
Change-Id: Ia38098f8b3e5a9d24c2206e11edab37d60209225
2024-09-10 12:26:32 +02:00

35 lines
923 B
JavaScript

'use strict';
QUnit.module( 've.ui.MWUseExistingReferenceCommand (Cite)', ve.test.utils.newMwEnvironment() );
function getFragmentMock( hasRefs ) {
const docRefsMock = {
hasRefs: () => hasRefs
};
return {
getDocument: () => ( {
getOriginalDocument: () => undefined,
getStorage: () => docRefsMock,
setStorage: () => 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 ) ) );
} );