Merge "Helper function getAllGroupNames"

This commit is contained in:
jenkins-bot 2024-07-30 12:30:14 +00:00 committed by Gerrit Code Review
commit a9b8380bcb
3 changed files with 9 additions and 5 deletions

View file

@ -53,8 +53,7 @@ ve.dm.MWDocumentReferences.static.refsForDoc = function ( fragment ) {
* @private
*/
ve.dm.MWDocumentReferences.prototype.updateAllGroups = function () {
const nodes = this.doc.getInternalList().getNodeGroups();
this.updateGroups( Object.keys( nodes ) );
this.updateGroups( this.getAllGroupNames() );
};
/**
@ -91,6 +90,10 @@ ve.dm.MWDocumentReferences.prototype.updateGroup = function ( groupName ) {
this.cachedByGroup[ groupName ] = indexNumberLookup;
};
ve.dm.MWDocumentReferences.prototype.getAllGroupNames = function () {
return Object.keys( this.doc.getInternalList().getNodeGroups() );
};
/**
* Return a formatted number, in the content script, with no separators.
*

View file

@ -141,8 +141,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
*/
ve.ui.MWReferenceSearchWidget.prototype.buildSearchIndex = function () {
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( this.internalList.getDocument() );
const groups = this.internalList.getNodeGroups();
const groupNames = Object.keys( groups ).sort();
const groupNames = docRefs.getAllGroupNames().sort();
// FIXME: Temporary hack, to be removed soon
// eslint-disable-next-line no-jquery/no-class-state

View file

@ -3,11 +3,13 @@
QUnit.module( 've.ui.MWReferenceSearchWidget (Cite)', ve.test.utils.newMwEnvironment() );
function getInternalListMock( groups, mockWithNode ) {
groups = groups || {};
const node = mockWithNode ? {
getAttribute: () => ( 'literal/foo' ),
getAttributes: () => ( {} )
} : {};
const refDocMock = {
getAllGroupNames: () => ( Object.keys( groups ) ),
getGroupRefsByParents: () => ( { '': [ node ] } ),
getIndexNumber: () => ( 1 ),
getItemNode: () => ( node )
@ -18,7 +20,7 @@ function getInternalListMock( groups, mockWithNode ) {
};
const mockInternalList = {
getDocument: () => ( docMock ),
getNodeGroups: () => ( groups || {} ),
getNodeGroups: () => ( groups ),
getItemNode: () => ( node )
};
docMock.getInternalList = () => ( mockInternalList );