mediawiki-extensions-Revisi.../tests/qunit/RevisionSlider.Slider.test.js
Leszek Manicki 8e7fe2434d Add eslint, to be used instead of jscs and/or jshint
First I jumped on replacing both jscs and jshint with eslint but
it might be premature decision. Although linting with eslint
is possible (like in there is wikimedia config for eslint)
it is still not clear should it

But in case the change happens we will be ready.

Apart from config stuff this changes few bits spotted by eslint:
improves some indentation, removes weird spaces, completes some
doc blocks, changes IIFE forms in tests. These changes do not
seem controversial.

Change-Id: I9f8bf0f5745da8e662685f4cd879ea4baa609c01
2016-09-05 09:47:11 +02:00

58 lines
1.8 KiB
JavaScript

( function ( mw ) {
var Slider = mw.libs.revisionSlider.Slider,
RevisionList = mw.libs.revisionSlider.RevisionList,
Revision = mw.libs.revisionSlider.Revision,
makeNRevisions = function ( 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.equal( slider.getRevisions(), revs );
} );
QUnit.test( 'Given no revisions, first visible revision index is 0', function ( assert ) {
var slider = new Slider( makeNRevisions( 0 ) );
assert.equal( slider.getFirstVisibleRevisionIndex(), 0 );
} );
QUnit.test( 'Given 200 revisions sliding once increases firstVisibleRevisionIndex by the number of revisions per window', function ( assert ) {
var slider = new Slider( makeNRevisions( 200 ) );
slider.setRevisionsPerWindow( 50 );
slider.slide( 1 );
assert.equal( slider.getFirstVisibleRevisionIndex(), 50 );
} );
QUnit.test( 'firstVisibleRevisionIndex cannot be higher than revisions.length - revisionsPerWindow', function ( assert ) {
var slider = new Slider( makeNRevisions( 75 ) );
slider.setRevisionsPerWindow( 50 );
slider.slide( 1 );
assert.equal( slider.getFirstVisibleRevisionIndex(), 25 );
} );
QUnit.test( 'firstVisibleRevisionIndex cannot be lower than 0', function ( assert ) {
var slider = new Slider( makeNRevisions( 50 ) );
slider.firstVisibleRevisionIndex = 10;
slider.setRevisionsPerWindow( 20 );
slider.slide( -1 );
assert.equal( slider.getFirstVisibleRevisionIndex(), 0 );
} );
}( mediaWiki ) );