mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-11 22:56:01 +00:00
3af9dfdb71
Making sure that change events form the fields are handled in the panel and forwarded to the dialog with the information needed. Also slighly moving some calls in the setup process that inits the dialog and removing some duplication. Calling focus on the edit panel only makes sense in the ready step. Not during setup. Bug: T369005 Change-Id: I4f9a022a06ec6543b106620eae030235b8f6712b
58 lines
2 KiB
JavaScript
58 lines
2 KiB
JavaScript
'use strict';
|
|
|
|
QUnit.module( 've.ui.MWReferenceEditPanel (Cite)', ve.test.utils.newMwEnvironment() );
|
|
|
|
QUnit.test( 'setReferenceForEditing', ( assert ) => {
|
|
ve.init.target.surface = { commandRegistry: { registry: {} } };
|
|
const editPanel = new ve.ui.MWReferenceEditPanel();
|
|
|
|
const emptyDoc = new ve.dm.Document( [
|
|
{ type: 'paragraph', internal: { generated: 'empty' } },
|
|
{ type: '/paragraph' },
|
|
{ type: 'internalList' },
|
|
{ type: '/internalList' }
|
|
] );
|
|
const ref = new ve.dm.MWReferenceModel( emptyDoc );
|
|
|
|
editPanel.setInternalList( emptyDoc.getInternalList() );
|
|
|
|
const changeHandlerStub = sinon.stub();
|
|
editPanel.connect( changeHandlerStub );
|
|
|
|
ref.setGroup( 'g' );
|
|
editPanel.setReferenceForEditing( ref );
|
|
|
|
assert.strictEqual( editPanel.originalGroup, 'g' );
|
|
assert.strictEqual( editPanel.referenceGroupInput.getValue(), 'g' );
|
|
assert.false( editPanel.referenceGroupInput.isDisabled() );
|
|
assert.false( editPanel.reuseWarning.isVisible() );
|
|
assert.false( editPanel.extendsWarning.isVisible() );
|
|
assert.strictEqual( editPanel.getReferenceFromEditing().getGroup(), 'g' );
|
|
|
|
sinon.assert.notCalled( changeHandlerStub );
|
|
} );
|
|
|
|
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() );
|
|
} );
|