| 1 |
QUnit.module( 've.ui.MWTransclusionOutlineWidget' ); |
| 2 |
|
| 3 |
QUnit.test( 'Constructor', ( assert ) => { |
| 4 |
const widget = new ve.ui.MWTransclusionOutlineWidget(); |
| 5 |
|
| 6 |
|
| 7 |
assert.true( widget.$element.hasClass( 've-ui-mwTransclusionOutlineWidget' ) ); |
| 8 |
assert.deepEqual( widget.partWidgets, {} ); |
| 9 |
} ); |
| 10 |
|
| 11 |
QUnit.test( 'Supports all ve.dm.MWTransclusionPartModel subclasses', ( assert ) => { |
| 12 |
const transclusion = new ve.dm.MWTransclusionModel(), |
| 13 |
widget = new ve.ui.MWTransclusionOutlineWidget(); |
| 14 |
|
| 15 |
widget.onReplacePart( null, new ve.dm.MWTemplateModel( transclusion, { wt: '' } ) ); |
| 16 |
widget.onReplacePart( null, new ve.dm.MWTemplatePlaceholderModel( transclusion ) ); |
| 17 |
widget.onReplacePart( null, new ve.dm.MWTransclusionContentModel( transclusion ) ); |
| 18 |
|
| 19 |
assert.true( widget.partWidgets.part_0 instanceof ve.ui.MWTransclusionOutlineTemplateWidget ); |
| 20 |
assert.true( widget.partWidgets.part_1 instanceof ve.ui.MWTransclusionOutlinePlaceholderWidget ); |
| 21 |
assert.true( widget.partWidgets.part_2 instanceof ve.ui.MWTransclusionOutlineWikitextWidget ); |
| 22 |
} ); |
| 23 |
|
| 24 |
QUnit.test( 'Basic functionality', ( assert ) => { |
| 25 |
const transclusion = new ve.dm.MWTransclusionModel(), |
| 26 |
part0 = new ve.dm.MWTransclusionContentModel( transclusion ), |
| 27 |
part1 = new ve.dm.MWTransclusionContentModel( transclusion ), |
| 28 |
widget = new ve.ui.MWTransclusionOutlineWidget(); |
| 29 |
|
| 30 |
widget.onReplacePart(); |
| 31 |
assert.deepEqual( widget.partWidgets, {} ); |
| 32 |
|
| 33 |
widget.onReplacePart( null, part0 ); |
| 34 |
widget.onReplacePart( null, part1 ); |
| 35 |
assert.deepEqual( Object.keys( widget.partWidgets ), [ 'part_0', 'part_1' ] ); |
| 36 |
|
| 37 |
widget.onReplacePart( part0 ); |
| 38 |
assert.deepEqual( Object.keys( widget.partWidgets ), [ 'part_1' ] ); |
| 39 |
|
| 40 |
widget.clear(); |
| 41 |
assert.deepEqual( widget.partWidgets, {} ); |
| 42 |
} ); |
| 43 |
|
| 44 |
QUnit.test( 'Adding and moving parts to specific positions', ( assert ) => { |
| 45 |
const transclusion = new ve.dm.MWTransclusionModel(), |
| 46 |
part0 = new ve.dm.MWTransclusionContentModel( transclusion ), |
| 47 |
part1 = new ve.dm.MWTransclusionContentModel( transclusion ), |
| 48 |
part2 = new ve.dm.MWTransclusionContentModel( transclusion ), |
| 49 |
widget = new ve.ui.MWTransclusionOutlineWidget(); |
| 50 |
|
| 51 |
|
| 52 |
widget.onReplacePart( null, part0, 666 ); |
| 53 |
widget.onReplacePart( null, part1, 0 ); |
| 54 |
widget.onReplacePart( null, part2, 1 ); |
| 55 |
|
| 56 |
|
| 57 |
assert.deepEqual( Object.keys( widget.partWidgets ), [ 'part_0', 'part_1', 'part_2' ] ); |
| 58 |
|
| 59 |
const $items = widget.$element.children(); |
| 60 |
assert.true( $items.eq( 0 ).is( widget.partWidgets.part_1.$element ) ); |
| 61 |
assert.true( $items.eq( 1 ).is( widget.partWidgets.part_2.$element ) ); |
| 62 |
assert.true( $items.eq( 2 ).is( widget.partWidgets.part_0.$element ) ); |
| 63 |
} ); |
| 64 |
|
| 65 |
[ |
| 66 |
[ null, null ], |
| 67 |
[ '', null ], |
| 68 |
[ 'part_0', null ], |
| 69 |
[ 'part_0/', '' ], |
| 70 |
[ 'part_0/foo', 'foo' ], |
| 71 |
[ 'part_1/foo', null ], |
| 72 |
[ 'part_0/foo/bar', 'foo/bar' ] |
| 73 |
].forEach( ( [ pageName, expected ] ) => QUnit.test( 'setSelectionByPageName: ' + pageName, ( assert ) => { |
| 74 |
const transclusion = new ve.dm.MWTransclusionModel(), |
| 75 |
template = new ve.dm.MWTemplateModel( transclusion, { wt: '' } ), |
| 76 |
partWidget = new ve.ui.MWTransclusionOutlineTemplateWidget( template ), |
| 77 |
widget = new ve.ui.MWTransclusionOutlineWidget(); |
| 78 |
|
| 79 |
|
| 80 |
widget.partWidgets.part_0 = partWidget; |
| 81 |
|
| 82 |
let actual = null; |
| 83 |
partWidget.setParameter = ( paramName ) => { |
| 84 |
actual = paramName; |
| 85 |
}; |
| 86 |
|
| 87 |
widget.setSelectionByPageName( pageName ); |
| 88 |
assert.strictEqual( actual, expected ); |
| 89 |
} ) |
| 90 |
); |