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,
|
2016-07-04 20:45:34 +00:00
|
|
|
Revision = mw.libs.revisionSlider.Revision,
|
2016-05-10 16:45:11 +00:00
|
|
|
makeNRevisions = function ( n ) {
|
|
|
|
var revs = [],
|
|
|
|
i;
|
|
|
|
for ( i = 0; i < n; i++ ) {
|
2016-07-04 20:45:34 +00:00
|
|
|
revs.push( new Revision( { revid: i + 1, user: 'Fooo' } ) );
|
2016-05-10 16:45:11 +00:00
|
|
|
}
|
|
|
|
return new RevisionList( revs );
|
|
|
|
};
|
2016-05-10 12:42:05 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.RevisionSlider.Slider' );
|
|
|
|
|
|
|
|
QUnit.test( 'has revisions', function ( assert ) {
|
2016-07-04 20:45:34 +00:00
|
|
|
var revs = new RevisionList( [
|
2016-09-01 11:17:47 +00:00
|
|
|
new Revision( { revid: 1 } ),
|
|
|
|
new Revision( { revid: 2 } )
|
|
|
|
] ),
|
2016-05-10 12:42:05 +00:00
|
|
|
slider = new Slider( revs );
|
|
|
|
|
2017-08-17 14:08:49 +00:00
|
|
|
assert.equal( slider.getRevisionList(), revs );
|
2016-05-10 12:42:05 +00:00
|
|
|
} );
|
|
|
|
|
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 ) );
|
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
assert.equal( slider.getOldestVisibleRevisionIndex(), 0 );
|
2016-05-10 16:45:11 +00:00
|
|
|
} );
|
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
QUnit.test( 'Given 200 revisions sliding once increases oldestVisibleRevisionIndex by the number of revisions per window', function ( assert ) {
|
2016-05-10 16:45:11 +00:00
|
|
|
var slider = new Slider( makeNRevisions( 200 ) );
|
|
|
|
slider.setRevisionsPerWindow( 50 );
|
|
|
|
slider.slide( 1 );
|
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
assert.equal( slider.getOldestVisibleRevisionIndex(), 50 );
|
2016-05-10 16:45:11 +00:00
|
|
|
} );
|
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
QUnit.test( 'oldestVisibleRevisionIndex cannot be higher than revisions.length - revisionsPerWindow', function ( assert ) {
|
2016-05-10 16:45:11 +00:00
|
|
|
var slider = new Slider( makeNRevisions( 75 ) );
|
|
|
|
slider.setRevisionsPerWindow( 50 );
|
|
|
|
slider.slide( 1 );
|
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
assert.equal( slider.getOldestVisibleRevisionIndex(), 25 );
|
2016-05-10 16:45:11 +00:00
|
|
|
} );
|
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
QUnit.test( 'oldestVisibleRevisionIndex cannot be lower than 0', function ( assert ) {
|
2016-05-10 16:45:11 +00:00
|
|
|
var slider = new Slider( makeNRevisions( 50 ) );
|
2017-03-27 19:04:31 +00:00
|
|
|
slider.oldestVisibleRevisionIndex = 10;
|
2016-05-10 16:45:11 +00:00
|
|
|
slider.setRevisionsPerWindow( 20 );
|
|
|
|
slider.slide( -1 );
|
|
|
|
|
2017-03-27 19:04:31 +00:00
|
|
|
assert.equal( slider.getOldestVisibleRevisionIndex(), 0 );
|
2016-05-10 16:45:11 +00:00
|
|
|
} );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2016-09-01 11:17:47 +00:00
|
|
|
}( mediaWiki ) );
|