2023-06-22 09:41:37 +00:00
|
|
|
( function () {
|
|
|
|
const SliderModule = require( 'ext.RevisionSlider.Slider' ),
|
|
|
|
Slider = SliderModule.Slider,
|
|
|
|
Revision = SliderModule.Revision,
|
|
|
|
RevisionList = SliderModule.RevisionList;
|
|
|
|
|
|
|
|
function makeNRevisions( n ) {
|
|
|
|
const revs = [];
|
|
|
|
for ( let i = 0; i < n; i++ ) {
|
|
|
|
revs.push( new Revision( { revid: i + 1, user: 'Fooo' } ) );
|
|
|
|
}
|
|
|
|
return new RevisionList( revs );
|
2020-11-12 18:48:39 +00:00
|
|
|
}
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
QUnit.module( 'ext.RevisionSlider.Slider' );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
QUnit.test( 'has revisions', function ( assert ) {
|
|
|
|
const revs = new RevisionList( [
|
|
|
|
new Revision( { revid: 1 } ),
|
|
|
|
new Revision( { revid: 2 } )
|
|
|
|
] ),
|
|
|
|
slider = new Slider( revs );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
assert.strictEqual( slider.getRevisionList(), revs );
|
|
|
|
} );
|
2016-05-10 12:42:05 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
QUnit.test( 'Given no revisions, first visible revision index is 0', function ( assert ) {
|
|
|
|
const slider = new Slider( makeNRevisions( 0 ) );
|
2016-05-10 16:45:11 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 0 );
|
|
|
|
} );
|
2016-05-10 16:45:11 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
QUnit.test( 'Given 200 revisions sliding once increases oldestVisibleRevisionIndex by the number of revisions per window', function ( assert ) {
|
|
|
|
const slider = new Slider( makeNRevisions( 200 ) );
|
2024-02-09 11:13:44 +00:00
|
|
|
slider.setRevisionsPerWindow( 49.999 );
|
2023-06-22 09:41:37 +00:00
|
|
|
slider.slide( 1 );
|
2016-05-10 16:45:11 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 50 );
|
|
|
|
} );
|
2016-05-10 16:45:11 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
QUnit.test( 'oldestVisibleRevisionIndex cannot be higher than revisions.length - revisionsPerWindow', function ( assert ) {
|
|
|
|
const slider = new Slider( makeNRevisions( 75 ) );
|
|
|
|
slider.setRevisionsPerWindow( 50 );
|
|
|
|
slider.slide( 1 );
|
2016-05-10 16:45:11 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 25 );
|
|
|
|
} );
|
2016-05-10 16:45:11 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
QUnit.test( 'oldestVisibleRevisionIndex cannot be lower than 0', function ( assert ) {
|
|
|
|
const slider = new Slider( makeNRevisions( 50 ) );
|
|
|
|
slider.oldestVisibleRevisionIndex = 10;
|
|
|
|
slider.setRevisionsPerWindow( 20 );
|
|
|
|
slider.slide( -1 );
|
2016-05-10 16:45:11 +00:00
|
|
|
|
2023-06-22 09:41:37 +00:00
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 0 );
|
|
|
|
} );
|
|
|
|
}() );
|