mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-27 08:20:02 +00:00
Merge "Hide main ref warning on orphan refs"
This commit is contained in:
commit
d847caf5b8
|
@ -233,10 +233,9 @@ ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref
|
|||
* @param {ve.dm.MWReferenceModel} ref
|
||||
*/
|
||||
ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( ref ) {
|
||||
if ( ref.extendsRef ) {
|
||||
const itemNode = this.internalList.getItemNode(
|
||||
this.internalList.keys.indexOf( ref.extendsRef )
|
||||
);
|
||||
const mainRefId = this.internalList.keys.indexOf( ref.extendsRef );
|
||||
if ( mainRefId !== -1 ) {
|
||||
const itemNode = this.internalList.getItemNode( mainRefId );
|
||||
const $parentRefPreview = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
|
||||
this.extendsWarning.setLabel(
|
||||
$( '<p>' )
|
||||
|
@ -245,7 +244,7 @@ ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( re
|
|||
);
|
||||
}
|
||||
|
||||
this.extendsWarning.toggle( !!ref.extendsRef );
|
||||
this.extendsWarning.toggle( mainRefId !== -1 );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,3 +24,27 @@ QUnit.test( 'setReferenceForEditing', ( assert ) => {
|
|||
assert.false( editPanel.reuseWarning.isVisible() );
|
||||
assert.false( editPanel.extendsWarning.isVisible() );
|
||||
} );
|
||||
|
||||
QUnit.test( 'sub refs', ( assert ) => {
|
||||
ve.init.target.surface = { commandRegistry: { registry: {} } };
|
||||
const editPanel = new ve.ui.MWReferenceEditPanel();
|
||||
|
||||
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
|
||||
const ref = new ve.dm.MWReferenceModel( doc );
|
||||
|
||||
editPanel.setInternalList( doc.getInternalList() );
|
||||
// does exist in the example document
|
||||
ref.extendsRef = 'literal/bar';
|
||||
editPanel.setReferenceForEditing( ref );
|
||||
|
||||
assert.false( editPanel.reuseWarning.isVisible() );
|
||||
assert.true( editPanel.extendsWarning.isVisible() );
|
||||
assert.true( !!editPanel.extendsWarning.getLabel().text().indexOf( 'Bar' ) );
|
||||
|
||||
// test sub ref with missing main ref
|
||||
ref.extendsRef = 'literal/notexist';
|
||||
editPanel.setReferenceForEditing( ref );
|
||||
|
||||
assert.false( editPanel.reuseWarning.isVisible() );
|
||||
assert.false( editPanel.extendsWarning.isVisible() );
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue