2024-07-21 18:09:27 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
QUnit.module( 've.ui.MWReferenceEditPanel (Cite)', ve.test.utils.newMwEnvironment() );
|
|
|
|
|
2024-08-29 21:43:03 +00:00
|
|
|
function getDocRefsMock( doc, hasNode, reUse ) {
|
|
|
|
const node = new ve.dm.MWReferenceNode( {
|
|
|
|
type: 'mwReference',
|
|
|
|
attributes: {
|
|
|
|
listKey: 'literal/bar',
|
|
|
|
refGroup: 'mwReference/'
|
|
|
|
},
|
|
|
|
originalDomElementsHash: Math.random()
|
|
|
|
} );
|
|
|
|
node.setDocument( doc );
|
|
|
|
const groupRefs = {
|
|
|
|
getRefUsages: () => ( reUse ? [ node, node ] : [] ),
|
|
|
|
getInternalModelNode: () => ( hasNode ? node : undefined )
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
getAllGroupNames: () => ( [ 'mwReference/' ] ),
|
|
|
|
getGroupRefs: () => ( groupRefs )
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-07-21 18:09:27 +00:00
|
|
|
QUnit.test( 'setReferenceForEditing', ( assert ) => {
|
|
|
|
ve.init.target.surface = { commandRegistry: { registry: {} } };
|
|
|
|
const editPanel = new ve.ui.MWReferenceEditPanel();
|
|
|
|
|
2024-08-26 09:14:33 +00:00
|
|
|
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
|
|
|
|
const ref = new ve.dm.MWReferenceModel( doc );
|
2024-08-29 21:43:03 +00:00
|
|
|
editPanel.setDocumentReferences( getDocRefsMock( doc ) );
|
2024-07-27 19:15:04 +00:00
|
|
|
|
|
|
|
const changeHandlerStub = sinon.stub();
|
|
|
|
editPanel.connect( changeHandlerStub );
|
|
|
|
|
2024-08-29 21:43:03 +00:00
|
|
|
ref.setGroup( 'group' );
|
2024-07-21 18:09:27 +00:00
|
|
|
editPanel.setReferenceForEditing( ref );
|
|
|
|
|
2024-08-29 21:43:03 +00:00
|
|
|
assert.strictEqual( editPanel.originalGroup, 'group' );
|
|
|
|
assert.strictEqual( editPanel.referenceGroupInput.getValue(), 'group' );
|
2024-07-21 18:09:27 +00:00
|
|
|
assert.false( editPanel.referenceGroupInput.isDisabled() );
|
|
|
|
assert.false( editPanel.reuseWarning.isVisible() );
|
|
|
|
assert.false( editPanel.extendsWarning.isVisible() );
|
2024-08-29 21:43:03 +00:00
|
|
|
assert.strictEqual( editPanel.getReferenceFromEditing().getGroup(), 'group' );
|
2024-07-27 19:15:04 +00:00
|
|
|
|
|
|
|
sinon.assert.notCalled( changeHandlerStub );
|
2024-07-21 18:09:27 +00:00
|
|
|
} );
|
2024-08-02 13:13:51 +00:00
|
|
|
|
2024-08-29 21:43:03 +00:00
|
|
|
QUnit.test( 're-used references', ( 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.setDocumentReferences( getDocRefsMock( doc, true, true ) );
|
|
|
|
editPanel.setReferenceForEditing( ref );
|
|
|
|
|
|
|
|
assert.true( editPanel.reuseWarning.isVisible() );
|
|
|
|
assert.false( editPanel.extendsWarning.isVisible() );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'sub-references', ( assert ) => {
|
2024-08-02 13:13:51 +00:00
|
|
|
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 );
|
|
|
|
|
|
|
|
// does exist in the example document
|
|
|
|
ref.extendsRef = 'literal/bar';
|
2024-08-29 21:43:03 +00:00
|
|
|
editPanel.setDocumentReferences( getDocRefsMock( doc, true ) );
|
2024-08-02 13:13:51 +00:00
|
|
|
editPanel.setReferenceForEditing( ref );
|
|
|
|
|
|
|
|
assert.false( editPanel.reuseWarning.isVisible() );
|
|
|
|
assert.true( editPanel.extendsWarning.isVisible() );
|
2024-08-29 21:43:03 +00:00
|
|
|
assert.false( editPanel.extendsWarning.getLabel().text().indexOf( 'cite-ve-dialog-reference-missing-parent-ref' ) !== -1 );
|
|
|
|
// TODO improve node mock to check content insertion for the parent
|
|
|
|
// assert.true( editPanel.extendsWarning.getLabel().text().indexOf( 'Bar' ) !== -1 );
|
2024-08-02 13:13:51 +00:00
|
|
|
|
|
|
|
// test sub ref with missing main ref
|
|
|
|
ref.extendsRef = 'literal/notexist';
|
2024-08-29 21:43:03 +00:00
|
|
|
editPanel.setDocumentReferences( getDocRefsMock( doc ) );
|
2024-08-02 13:13:51 +00:00
|
|
|
editPanel.setReferenceForEditing( ref );
|
|
|
|
|
|
|
|
assert.false( editPanel.reuseWarning.isVisible() );
|
2024-08-21 14:57:50 +00:00
|
|
|
assert.true( editPanel.extendsWarning.isVisible() );
|
|
|
|
assert.true( editPanel.extendsWarning.getLabel().text().indexOf( 'cite-ve-dialog-reference-missing-parent-ref' ) !== -1 );
|
2024-08-02 13:13:51 +00:00
|
|
|
} );
|