mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 10:59:56 +00:00
06cf00f4c6
I tried hard to come up with the best possible names. Some of the criteria I used: * Longer and more unique is better. This makes it much easier to e.g. search for the event name. * The term "part" should only be used for top-level parts. While template parameters have a unique id, they are not a subclass of …TransclusionPartModel and therefor not "parts". * BookletLayout manages "pages" via "page names". * The page names of top-level parts are identical with the part id, see ve.ui.MWTemplateDialog.getPageFromPart. * The page names of parameters are identical with the parameter model id, see ve.ui.MWTemplateDialog.onAddParameter. Some code knows parameter ids, but not what pages are. Other code knows page names, but not what parameters are. The transition currently happens in the …OutlineContainerWidget. We might want to move this point up to the …TemplateDialog. But I would argue this is good enough for now and can be changed later, if needed. Bug: T285323 Change-Id: Iab2805b3203988db400b67c8d00e48905fdc53dc
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
QUnit.module( 've.ui.MWTransclusionOutlineParameterSelectWidget' );
|
|
|
|
QUnit.test( 'static item constructor', ( assert ) => {
|
|
const item = ve.ui.MWTransclusionOutlineParameterSelectWidget.static.createItem( { data: 'p1' } );
|
|
|
|
assert.ok( item instanceof OO.ui.OptionWidget, 'items use correct base class' );
|
|
assert.strictEqual( item.getData(), 'p1', 'config is forwarded to base class' );
|
|
assert.notOk( item.isSelected() );
|
|
} );
|
|
|
|
QUnit.test( 'interaction with items', ( assert ) => {
|
|
const item = ve.ui.MWTransclusionOutlineParameterSelectWidget.static.createItem( {} ),
|
|
widget = new ve.ui.MWTransclusionOutlineParameterSelectWidget( { items: [ item ] } );
|
|
|
|
assert.strictEqual( widget.getItems().length, 1, 'item is added' );
|
|
|
|
// Note this triggers a chain of events that bubbles up to the SelectWidget. The individual
|
|
// OptionWidgets just store their state, but the outer SelectWidget manages it!
|
|
item.checkbox.setSelected( true );
|
|
assert.ok( item.isSelected(), 'clicking the checkbox selects the item' );
|
|
|
|
let eventsFired = 0;
|
|
widget.connect( this, { templateParameterClick: () => eventsFired++ } );
|
|
|
|
widget.onMouseDown( {
|
|
which: OO.ui.MouseButtons.LEFT,
|
|
target: item.$element[ 0 ]
|
|
} );
|
|
|
|
widget.highlightItem( item );
|
|
widget.onDocumentKeyDown( {
|
|
keyCode: OO.ui.Keys.ENTER,
|
|
preventDefault: () => undefined
|
|
} );
|
|
|
|
assert.strictEqual( eventsFired, 2 );
|
|
} );
|
|
|
|
QUnit.test( 'interaction with required parameter', ( assert ) => {
|
|
const item = ve.ui.MWTransclusionOutlineParameterSelectWidget.static.createItem( { required: true } ),
|
|
widget = new ve.ui.MWTransclusionOutlineParameterSelectWidget( { items: [ item ] } );
|
|
|
|
assert.strictEqual( widget.getItems()[ 0 ], item, 'item is used as is' );
|
|
assert.ok( item.isSelected(), 'selected by default' );
|
|
|
|
item.setSelected( false );
|
|
assert.ok( item.isSelected(), 'can not unselect' );
|
|
|
|
item.checkbox.setSelected( false );
|
|
assert.ok( item.isSelected(), 'can not unselect via the checkbox as well' );
|
|
} );
|