mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-12-23 04:02:50 +00:00
f5de8ee108
* eslint-config-wikimedia: 0.27.0 → 0.28.0 The following rules are failing and were disabled: * modules: * no-mixed-spaces-and-tabs * no-jquery/no-extend * implicit-arrow-linebreak * tests/qunit: * no-jquery/no-extend * grunt-stylelint: 0.19.0 → 0.20.0 * stylelint-config-wikimedia: 0.16.1 → 0.17.1 Change-Id: I3fd3c4a2cbb03d3aa4c8efb658e33d14d24cd518
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
( 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 );
|
|
}
|
|
|
|
QUnit.module( 'ext.RevisionSlider.Slider' );
|
|
|
|
QUnit.test( 'has revisions', ( assert ) => {
|
|
const 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', ( assert ) => {
|
|
const 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', ( assert ) => {
|
|
const slider = new Slider( makeNRevisions( 200 ) );
|
|
slider.setRevisionsPerWindow( 49.999 );
|
|
slider.slide( 1 );
|
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 50 );
|
|
} );
|
|
|
|
QUnit.test( 'oldestVisibleRevisionIndex cannot be higher than revisions.length - revisionsPerWindow', ( assert ) => {
|
|
const slider = new Slider( makeNRevisions( 75 ) );
|
|
slider.setRevisionsPerWindow( 50 );
|
|
slider.slide( 1 );
|
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 25 );
|
|
} );
|
|
|
|
QUnit.test( 'oldestVisibleRevisionIndex cannot be lower than 0', ( assert ) => {
|
|
const slider = new Slider( makeNRevisions( 50 ) );
|
|
slider.oldestVisibleRevisionIndex = 10;
|
|
slider.setRevisionsPerWindow( 20 );
|
|
slider.slide( -1 );
|
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 0 );
|
|
} );
|
|
}() );
|