2017-06-29 08:14:27 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-05-10 16:45:11 +00:00
|
|
|
var SliderView = mw.libs.revisionSlider.SliderView,
|
|
|
|
Slider = mw.libs.revisionSlider.Slider,
|
2016-05-12 16:47:53 +00:00
|
|
|
RevisionList = mw.libs.revisionSlider.RevisionList,
|
2016-07-04 20:45:34 +00:00
|
|
|
Revision = mw.libs.revisionSlider.Revision,
|
2016-05-12 16:47:53 +00:00
|
|
|
startHistoryState, startHref;
|
2016-05-10 12:42:05 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.RevisionSlider.SliderView' );
|
|
|
|
|
2016-05-12 16:47:53 +00:00
|
|
|
QUnit.testStart( function () {
|
|
|
|
startHistoryState = history.state;
|
|
|
|
startHref = window.location.href;
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.testDone( function () {
|
|
|
|
history.replaceState( startHistoryState, 'QUnit', startHref );
|
|
|
|
} );
|
|
|
|
|
2016-05-31 10:00:07 +00:00
|
|
|
QUnit.test( 'render adds the slider view with defined revisions selected', function ( assert ) {
|
|
|
|
var $container = $( '<div>' ),
|
2016-05-10 16:45:11 +00:00
|
|
|
view = new SliderView( new Slider( new RevisionList( [
|
2016-07-04 20:45:34 +00:00
|
|
|
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' } )
|
2016-05-31 10:00:07 +00:00
|
|
|
] ) ) ),
|
|
|
|
$revisionOld,
|
|
|
|
$revisionNew;
|
|
|
|
|
|
|
|
mw.config.values.extRevisionSliderOldRev = 1;
|
|
|
|
mw.config.values.extRevisionSliderNewRev = 37;
|
2016-05-10 16:45:11 +00:00
|
|
|
|
|
|
|
view.render( $container );
|
2016-05-31 10:00:07 +00:00
|
|
|
|
2016-07-01 10:13:53 +00:00
|
|
|
assert.ok( $container.find( '.mw-revslider-revision-slider' ).length > 0 );
|
|
|
|
$revisionOld = $container.find( '.mw-revslider-revision-old' );
|
|
|
|
$revisionNew = $container.find( '.mw-revslider-revision-new' );
|
2016-05-31 10:00:07 +00:00
|
|
|
assert.ok( $revisionOld.length > 0 );
|
|
|
|
assert.equal( $revisionOld.attr( 'data-revid' ), 1 );
|
|
|
|
assert.ok( $revisionNew.length > 0 );
|
|
|
|
assert.equal( $revisionNew.attr( 'data-revid' ), 37 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'render throws an exception when no selected revisions provided', function ( assert ) {
|
|
|
|
var $container = $( '<div>' ),
|
|
|
|
view = new SliderView( new Slider( new RevisionList( [
|
2016-07-04 20:45:34 +00:00
|
|
|
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' } )
|
2016-05-31 10:00:07 +00:00
|
|
|
] ) ) );
|
|
|
|
|
|
|
|
mw.config.values.extRevisionSliderOldRev = null;
|
|
|
|
mw.config.values.extRevisionSliderNewRev = null;
|
|
|
|
|
2016-11-19 13:37:20 +00:00
|
|
|
assert.throws(
|
2016-05-31 10:00:07 +00:00
|
|
|
function () {
|
|
|
|
view.render( $container );
|
|
|
|
}
|
|
|
|
);
|
2016-05-10 16:45:11 +00:00
|
|
|
} );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2017-06-29 08:14:27 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|