2016-05-10 12:42:05 +00:00
|
|
|
( function ( mw ) {
|
|
|
|
var Slider = mw.libs.revisionSlider.Slider,
|
2016-05-10 16:45:11 +00:00
|
|
|
RevisionList = mw.libs.revisionSlider.RevisionList,
|
|
|
|
Revision = mw.libs.revisionSlider.Revision,
|
|
|
|
makeNRevisions = function ( n ) {
|
|
|
|
var revs = [],
|
|
|
|
i;
|
|
|
|
for ( i = 0; i < n; i++ ) {
|
|
|
|
revs.push( new Revision( { user: 'Fooo' } ) );
|
|
|
|
}
|
|
|
|
return new RevisionList( revs );
|
|
|
|
};
|
2016-05-10 12:42:05 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.RevisionSlider.Slider' );
|
|
|
|
|
|
|
|
QUnit.test( 'has revisions', function ( assert ) {
|
2016-05-10 16:45:11 +00:00
|
|
|
var revs = new RevisionList( [ new Revision( {} ), new Revision( {} ) ] ),
|
2016-05-10 12:42:05 +00:00
|
|
|
slider = new Slider( revs );
|
|
|
|
|
|
|
|
assert.equal( slider.getRevisions(), revs );
|
|
|
|
} );
|
|
|
|
|
2016-05-10 16:45:11 +00:00
|
|
|
QUnit.test( 'Given no revisions, first visible revision index is 0', function ( assert ) {
|
|
|
|
var slider = new Slider( makeNRevisions( 0 ) );
|
|
|
|
|
|
|
|
assert.equal( slider.getFirstVisibleRevisionIndex(), 0 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'Given 200 revisions sliding once increases firstVisibleRevisionIndex by the number of revisions per window', function ( assert ) {
|
|
|
|
var slider = new Slider( makeNRevisions( 200 ) );
|
|
|
|
slider.setRevisionsPerWindow( 50 );
|
|
|
|
slider.slide( 1 );
|
|
|
|
|
|
|
|
assert.equal( slider.getFirstVisibleRevisionIndex(), 50 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'firstVisibleRevisionIndex cannot be higher than revisions.length - revisionsPerWindow', function ( assert ) {
|
|
|
|
var slider = new Slider( makeNRevisions( 75 ) );
|
|
|
|
slider.setRevisionsPerWindow( 50 );
|
|
|
|
slider.slide( 1 );
|
|
|
|
|
|
|
|
assert.equal( slider.getFirstVisibleRevisionIndex(), 24 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'firstVisibleRevisionIndex cannot be lower than 0', function ( assert ) {
|
|
|
|
var slider = new Slider( makeNRevisions( 50 ) );
|
|
|
|
slider.firstVisibleRevisionIndex = 10;
|
|
|
|
slider.setRevisionsPerWindow( 20 );
|
|
|
|
slider.slide( -1 );
|
|
|
|
|
|
|
|
assert.equal( slider.getFirstVisibleRevisionIndex(), 0 );
|
|
|
|
} );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
|
|
|
} )( mediaWiki );
|