2023-06-22 09:41:37 +00:00
|
|
|
( function () {
|
|
|
|
const SliderModule = require( 'ext.RevisionSlider.Slider' ),
|
2024-07-23 19:48:46 +00:00
|
|
|
DiffPage = SliderModule.DiffPage,
|
2023-06-22 09:41:37 +00:00
|
|
|
Slider = SliderModule.Slider,
|
|
|
|
SliderView = SliderModule.SliderView,
|
|
|
|
Revision = SliderModule.Revision,
|
2024-07-23 19:48:46 +00:00
|
|
|
RevisionList = SliderModule.RevisionList,
|
|
|
|
historyStub = { replaceState: sinon.spy() },
|
|
|
|
diffPage = new DiffPage( historyStub );
|
2023-06-22 09:41:37 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.RevisionSlider.SliderView' );
|
|
|
|
|
2024-06-08 04:13:35 +00:00
|
|
|
QUnit.test( 'render adds the slider view with defined revisions selected', ( assert ) => {
|
2023-06-22 09:41:37 +00:00
|
|
|
const $container = $( '<div>' ),
|
|
|
|
view = new SliderView( new Slider( new RevisionList( [
|
|
|
|
new Revision( { revid: 1, size: 5, comment: 'Comment1', user: 'User1' } ),
|
|
|
|
new Revision( { revid: 3, size: 21, comment: 'Comment2', user: 'User2' } ),
|
|
|
|
new Revision( { revid: 37, size: 13, comment: 'Comment3', user: 'User3' } )
|
2024-07-23 19:48:46 +00:00
|
|
|
] ) ), diffPage );
|
2023-06-22 09:41:37 +00:00
|
|
|
|
|
|
|
mw.config.set( {
|
|
|
|
wgDiffOldId: 1,
|
|
|
|
wgDiffNewId: 37
|
|
|
|
} );
|
|
|
|
|
|
|
|
view.render( $container );
|
|
|
|
|
|
|
|
assert.strictEqual( $container.find( '.mw-revslider-revision-slider' ).length, 1 );
|
|
|
|
const $revisionOld = $container.find( '.mw-revslider-revision-old' );
|
|
|
|
const $revisionNew = $container.find( '.mw-revslider-revision-new' );
|
|
|
|
assert.strictEqual( $revisionOld.length, 1 );
|
|
|
|
assert.strictEqual( $revisionOld.attr( 'data-revid' ), '1' );
|
|
|
|
assert.strictEqual( $revisionNew.length, 1 );
|
|
|
|
assert.strictEqual( $revisionNew.attr( 'data-revid' ), '37' );
|
2024-07-23 19:48:46 +00:00
|
|
|
|
|
|
|
sinon.assert.calledOnce( historyStub.replaceState );
|
2023-06-22 09:41:37 +00:00
|
|
|
} );
|
|
|
|
|
2024-06-08 04:13:35 +00:00
|
|
|
QUnit.test( 'render throws an exception when no selected revisions provided', ( assert ) => {
|
2023-06-22 09:41:37 +00:00
|
|
|
const $container = $( '<div>' ),
|
|
|
|
view = new SliderView( new Slider( new RevisionList( [
|
|
|
|
new Revision( { revid: 1, size: 5, comment: 'Comment1', user: 'User1' } ),
|
|
|
|
new Revision( { revid: 3, size: 21, comment: 'Comment2', user: 'User2' } ),
|
|
|
|
new Revision( { revid: 37, size: 13, comment: 'Comment3', user: 'User3' } )
|
2024-07-23 19:48:46 +00:00
|
|
|
] ) ), diffPage );
|
2023-06-22 09:41:37 +00:00
|
|
|
|
|
|
|
mw.config.set( 'wgDiffOldId', null );
|
|
|
|
mw.config.set( 'wgDiffNewId', null );
|
|
|
|
|
|
|
|
assert.throws(
|
2024-06-08 04:13:35 +00:00
|
|
|
() => {
|
2023-06-22 09:41:37 +00:00
|
|
|
view.render( $container );
|
|
|
|
}
|
|
|
|
);
|
2024-07-23 19:48:46 +00:00
|
|
|
|
|
|
|
sinon.assert.calledOnce( historyStub.replaceState );
|
2023-06-22 09:41:37 +00:00
|
|
|
} );
|
|
|
|
}() );
|