mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-12-04 19:58:29 +00:00
8e2365502b
Despite its documentation the "constructor" of RevisionList tends to expect array of revision data in a format returned by API instead of array of Revision objects. Due to different name of ID fields in Revision object and in API array, if "real" Revision object is passed to RevisionList, its ID is lost. This changes RevisionList so that it only accepts an array of Revision objects. This provides better abstraction. This is basically a revert of I147270f28381038d05f8bcfd2317e8c269b2e458 which aimed at the same problem but suggested solution doesn't seem right. Change-Id: Ic45cdd3e7b707a8c6a19eecf0a84d4c11696cd1f
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
( function ( mw ) {
|
|
var Revision = mw.libs.revisionSlider.Revision,
|
|
RevisionList = mw.libs.revisionSlider.RevisionList,
|
|
makeRevisions = mw.libs.revisionSlider.makeRevisions;
|
|
|
|
QUnit.module( 'ext.RevisionSlider.RevisionList' );
|
|
|
|
QUnit.test( 'Find biggest Revision', function ( assert ) {
|
|
var revs = new RevisionList( [
|
|
new Revision( { revid: 1, size: 5 } ),
|
|
new Revision( { revid: 2, size: 21 } ),
|
|
new Revision( { revid: 3, size: 13 } )
|
|
] );
|
|
|
|
assert.equal( revs.getBiggestChangeSize(), 16 );
|
|
} );
|
|
|
|
QUnit.test( 'calculate relative size on init', function ( assert ) {
|
|
var revs = new RevisionList( [
|
|
new Revision( { revid: 1, size: 5 } ),
|
|
new Revision( { revid: 2, size: 21 } ),
|
|
new Revision( { revid: 3, size: 13 } )
|
|
] );
|
|
|
|
assert.equal( revs.getRevisions()[ 0 ].getRelativeSize(), 5 );
|
|
assert.equal( revs.getRevisions()[ 1 ].getRelativeSize(), 16 );
|
|
assert.equal( revs.getRevisions()[ 2 ].getRelativeSize(), -8 );
|
|
} );
|
|
|
|
QUnit.test( 'makeRevisions converts revision data into list of Revision objects', function ( assert ) {
|
|
var revs = [
|
|
{ revid: 1, size: 5 },
|
|
{ revid: 2, size: 21 },
|
|
{ revid: 3, size: 13 }
|
|
],
|
|
revisions = makeRevisions( revs );
|
|
|
|
assert.equal( revisions[ 0 ].getId(), 1 );
|
|
assert.equal( revisions[ 0 ].getSize(), 5 );
|
|
assert.equal( revisions[ 1 ].getId(), 2 );
|
|
assert.equal( revisions[ 1 ].getSize(), 21 );
|
|
assert.equal( revisions[ 2 ].getId(), 3 );
|
|
assert.equal( revisions[ 2 ].getSize(), 13 );
|
|
} );
|
|
} )( mediaWiki );
|