mediawiki-extensions-Revisi.../tests/qunit/RevisionSlider.Slider.test.js
Thiemo Kreuz 9aca3a2593 Merge ….RevisionList ResourceLoader module away
It's never used in another context but together with the
….Slider module.

Motivated by the confusion about the two types of require()
introduced in Idf1cc79.

Bug: T233279
Change-Id: I922d7ab56fd3ce80bc901f1a5d7174df6fe6756d
2021-12-20 12:13:09 +01:00

56 lines
1.8 KiB
JavaScript

var SliderModule = require( 'ext.RevisionSlider.Slider' ),
Slider = SliderModule.Slider,
Revision = SliderModule.Revision,
RevisionList = SliderModule.RevisionList;
function makeNRevisions( n ) {
var revs = [];
for ( var 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 );
} );