2021-09-21 08:35:36 +00:00
|
|
|
QUnit.module( 've.ui.MWTransclusionOutlineWidget' );
|
2021-08-24 09:31:14 +00:00
|
|
|
|
|
|
|
QUnit.test( 'Constructor', ( assert ) => {
|
2021-09-21 08:35:36 +00:00
|
|
|
const widget = new ve.ui.MWTransclusionOutlineWidget();
|
2021-08-24 09:31:14 +00:00
|
|
|
|
2021-08-24 11:36:14 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-class-state
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.true( widget.$element.hasClass( 've-ui-mwTransclusionOutlineWidget' ) );
|
2021-08-24 11:36:14 +00:00
|
|
|
assert.deepEqual( widget.partWidgets, {} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'Supports all ve.dm.MWTransclusionPartModel subclasses', ( assert ) => {
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
2021-09-21 08:35:36 +00:00
|
|
|
widget = new ve.ui.MWTransclusionOutlineWidget();
|
2021-08-24 11:36:14 +00:00
|
|
|
|
2021-10-07 11:06:03 +00:00
|
|
|
widget.onReplacePart( null, new ve.dm.MWTemplateModel( transclusion, { wt: '' } ) );
|
2021-08-24 11:36:14 +00:00
|
|
|
widget.onReplacePart( null, new ve.dm.MWTemplatePlaceholderModel( transclusion ) );
|
|
|
|
widget.onReplacePart( null, new ve.dm.MWTransclusionContentModel( transclusion ) );
|
|
|
|
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.true( widget.partWidgets.part_0 instanceof ve.ui.MWTransclusionOutlineTemplateWidget );
|
|
|
|
assert.true( widget.partWidgets.part_1 instanceof ve.ui.MWTransclusionOutlinePlaceholderWidget );
|
|
|
|
assert.true( widget.partWidgets.part_2 instanceof ve.ui.MWTransclusionOutlineWikitextWidget );
|
2021-08-24 11:36:14 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'Basic functionality', ( assert ) => {
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
|
|
part0 = new ve.dm.MWTransclusionContentModel( transclusion ),
|
|
|
|
part1 = new ve.dm.MWTransclusionContentModel( transclusion ),
|
2021-09-21 08:35:36 +00:00
|
|
|
widget = new ve.ui.MWTransclusionOutlineWidget();
|
2021-08-24 11:36:14 +00:00
|
|
|
|
|
|
|
widget.onReplacePart();
|
|
|
|
assert.deepEqual( widget.partWidgets, {} );
|
|
|
|
|
|
|
|
widget.onReplacePart( null, part0 );
|
|
|
|
widget.onReplacePart( null, part1 );
|
|
|
|
assert.deepEqual( Object.keys( widget.partWidgets ), [ 'part_0', 'part_1' ] );
|
|
|
|
|
|
|
|
widget.onReplacePart( part0 );
|
|
|
|
assert.deepEqual( Object.keys( widget.partWidgets ), [ 'part_1' ] );
|
|
|
|
|
|
|
|
widget.clear();
|
|
|
|
assert.deepEqual( widget.partWidgets, {} );
|
2021-08-24 09:31:14 +00:00
|
|
|
} );
|
2021-08-25 09:29:23 +00:00
|
|
|
|
2021-08-25 11:48:41 +00:00
|
|
|
QUnit.test( 'Adding and moving parts to specific positions', ( assert ) => {
|
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
|
|
|
part0 = new ve.dm.MWTransclusionContentModel( transclusion ),
|
|
|
|
part1 = new ve.dm.MWTransclusionContentModel( transclusion ),
|
|
|
|
part2 = new ve.dm.MWTransclusionContentModel( transclusion ),
|
2021-09-21 08:35:36 +00:00
|
|
|
widget = new ve.ui.MWTransclusionOutlineWidget();
|
2021-08-25 11:48:41 +00:00
|
|
|
|
|
|
|
// This adds the parts at an invalid position, at the start, and in the middle
|
|
|
|
widget.onReplacePart( null, part0, 666 );
|
|
|
|
widget.onReplacePart( null, part1, 0 );
|
|
|
|
widget.onReplacePart( null, part2, 1 );
|
|
|
|
|
|
|
|
// Note this is just a map and doesn't reflect the order in the UI
|
|
|
|
assert.deepEqual( Object.keys( widget.partWidgets ), [ 'part_0', 'part_1', 'part_2' ] );
|
|
|
|
|
2021-12-06 16:00:37 +00:00
|
|
|
const $items = widget.$element.children();
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.true( $items.eq( 0 ).is( widget.partWidgets.part_1.$element ) );
|
|
|
|
assert.true( $items.eq( 1 ).is( widget.partWidgets.part_2.$element ) );
|
|
|
|
assert.true( $items.eq( 2 ).is( widget.partWidgets.part_0.$element ) );
|
2021-08-25 11:48:41 +00:00
|
|
|
} );
|
2021-09-11 12:18:17 +00:00
|
|
|
|
|
|
|
[
|
2022-07-05 12:37:12 +00:00
|
|
|
[ null, null ],
|
2021-09-11 12:18:17 +00:00
|
|
|
[ '', null ],
|
|
|
|
[ 'part_0', null ],
|
|
|
|
[ 'part_0/', '' ],
|
|
|
|
[ 'part_0/foo', 'foo' ],
|
|
|
|
[ 'part_1/foo', null ],
|
|
|
|
[ 'part_0/foo/bar', 'foo/bar' ]
|
2024-06-04 03:39:48 +00:00
|
|
|
].forEach( ( [ pageName, expected ] ) => QUnit.test( 'setSelectionByPageName: ' + pageName, ( assert ) => {
|
2021-09-11 12:18:17 +00:00
|
|
|
const transclusion = new ve.dm.MWTransclusionModel(),
|
2021-10-07 11:06:03 +00:00
|
|
|
template = new ve.dm.MWTemplateModel( transclusion, { wt: '' } ),
|
2021-09-11 12:18:17 +00:00
|
|
|
partWidget = new ve.ui.MWTransclusionOutlineTemplateWidget( template ),
|
2021-09-21 08:35:36 +00:00
|
|
|
widget = new ve.ui.MWTransclusionOutlineWidget();
|
2021-09-11 12:18:17 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
widget.partWidgets.part_0 = partWidget;
|
|
|
|
|
|
|
|
let actual = null;
|
2022-07-09 06:54:35 +00:00
|
|
|
partWidget.setParameter = ( paramName ) => {
|
2021-09-11 12:18:17 +00:00
|
|
|
actual = paramName;
|
|
|
|
};
|
|
|
|
|
2021-09-30 11:08:10 +00:00
|
|
|
widget.setSelectionByPageName( pageName );
|
2021-09-11 12:18:17 +00:00
|
|
|
assert.strictEqual( actual, expected );
|
|
|
|
} )
|
|
|
|
);
|