mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-23 23:13:29 +00:00
1b49469c96
I have seen this getting fed with fractional numbers like 38.9994375. This apparently happens when specific browser zooms are used, e.g. 110% in Google Chrome. There is a lot of code that expects this to be an integer number and stops working entirely when it isn't. I'm also updating two related comparisons to not be so extremely specific any more. This probably doesn't make a difference any more with the fix above, but can't hurt. This patch doesn't solve T352169, but is one more puzzle piece on the way to solve it. Bug: T352169 Change-Id: Ied0b9748beec941e901ca4ecba428c16967ca510
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', function ( 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', function ( 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', function ( 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', function ( 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', function ( assert ) {
|
|
const slider = new Slider( makeNRevisions( 50 ) );
|
|
slider.oldestVisibleRevisionIndex = 10;
|
|
slider.setRevisionsPerWindow( 20 );
|
|
slider.slide( -1 );
|
|
|
|
assert.strictEqual( slider.getOldestVisibleRevisionIndex(), 0 );
|
|
} );
|
|
}() );
|