mediawiki-extensions-Revisi.../tests/qunit/RevisionSlider.Slider.test.js
Thiemo Kreuz c57fe0f2b6 Get rid of all var … = function () {} declarations
… and replace them with more trivial `function …() {}`. I
believe this does not make any difference. But I feel this
makes the code a little more straightforward.

The motivation for this patch is because a few other patches
change some of these function declarations, leaving a (in my
opinion) confusing mixture of styles behind.

Change-Id: Ib8928c4176a963afcf1fee1c785dd7bdc86c9706
2020-11-12 19:23:40 +00:00

59 lines
1.8 KiB
JavaScript

( function () {
var Slider = mw.libs.revisionSlider.Slider,
RevisionList = mw.libs.revisionSlider.RevisionList,
Revision = mw.libs.revisionSlider.Revision;
function makeNRevisions( n ) {
var revs = [],
i;
for ( i = 0; i < n; i++ ) {
revs.push( new Revision( { revid: i + 1, user: 'Fooo' } ) );
}
return new RevisionList( revs );
}
QUnit.module( 'ext.RevisionSlider.Slider' );
QUnit.test( 'has revisions', function ( assert ) {
var revs = new RevisionList( [
new Revision( { revid: 1 } ),
new Revision( { revid: 2 } )
] ),
slider = new Slider( revs );
assert.strictEqual( slider.getRevisionList(), revs );
} );
QUnit.test( 'Given no revisions, first visible revision index is 0', function ( assert ) {
var slider = new Slider( makeNRevisions( 0 ) );
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 0 );
} );
QUnit.test( 'Given 200 revisions sliding once increases oldestVisibleRevisionIndex by the number of revisions per window', function ( assert ) {
var slider = new Slider( makeNRevisions( 200 ) );
slider.setRevisionsPerWindow( 50 );
slider.slide( 1 );
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 50 );
} );
QUnit.test( 'oldestVisibleRevisionIndex cannot be higher than revisions.length - revisionsPerWindow', function ( assert ) {
var slider = new Slider( makeNRevisions( 75 ) );
slider.setRevisionsPerWindow( 50 );
slider.slide( 1 );
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 25 );
} );
QUnit.test( 'oldestVisibleRevisionIndex cannot be lower than 0', function ( assert ) {
var slider = new Slider( makeNRevisions( 50 ) );
slider.oldestVisibleRevisionIndex = 10;
slider.setRevisionsPerWindow( 20 );
slider.slide( -1 );
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 0 );
} );
}() );