2016-06-29 10:43:46 +00:00
|
|
|
( function ( mw ) {
|
|
|
|
var RevisionListView = mw.libs.revisionSlider.RevisionListView,
|
|
|
|
RevisionList = mw.libs.revisionSlider.RevisionList,
|
|
|
|
Revision = mw.libs.revisionSlider.Revision;
|
|
|
|
|
|
|
|
QUnit.module( 'ext.RevisionSlider.RevisionListView' );
|
|
|
|
|
|
|
|
QUnit.test( 'render adds revisions', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView( new RevisionList( [
|
2016-07-04 20:45:34 +00:00
|
|
|
new Revision( { revid: 1, size: 5, comment: '' } ),
|
|
|
|
new Revision( { revid: 3, size: 213, comment: '' } ),
|
|
|
|
new Revision( { revid: 37, size: 100, comment: '' } )
|
2016-06-29 10:43:46 +00:00
|
|
|
] ) ),
|
|
|
|
$resultHtml, $revisionWrapperDivs, $revisionDivs;
|
|
|
|
|
|
|
|
$resultHtml = revisionListView.render( 11 );
|
2016-07-01 10:13:53 +00:00
|
|
|
$revisionWrapperDivs = $resultHtml.find( '.mw-revslider-revision-wrapper' );
|
|
|
|
$revisionDivs = $resultHtml.find( '.mw-revslider-revision' );
|
2016-06-29 10:43:46 +00:00
|
|
|
|
|
|
|
assert.equal( $revisionWrapperDivs.length, 3 );
|
2016-07-01 10:24:30 +00:00
|
|
|
assert.equal( $( $revisionDivs[ 0 ] ).attr( 'data-revid' ), 1 );
|
|
|
|
assert.equal( $( $revisionDivs[ 2 ] ).attr( 'data-revid' ), 37 );
|
|
|
|
assert.equal( $( $revisionDivs[ 1 ] ).css( 'width' ), '11px' );
|
|
|
|
assert.equal( $( $revisionDivs[ 1 ] ).css( 'height' ), '70px' ); // max relative size
|
2016-07-01 10:13:53 +00:00
|
|
|
assert.ok( $( $revisionDivs[ 1 ] ).hasClass( 'mw-revslider-revision-up' ) );
|
|
|
|
assert.ok( $( $revisionDivs[ 2 ] ).hasClass( 'mw-revslider-revision-down' ) );
|
2016-06-29 10:43:46 +00:00
|
|
|
} );
|
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
QUnit.test( 'tooltip is composed correctly', function ( assert ) {
|
2016-06-29 10:43:46 +00:00
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
revision = new Revision( {
|
|
|
|
revid: 1,
|
2016-07-04 11:49:59 +00:00
|
|
|
size: 230,
|
2016-06-29 10:43:46 +00:00
|
|
|
comment: 'Hello',
|
|
|
|
parsedcomment: '<strong>Hello</strong>',
|
|
|
|
timestamp: '2016-04-26T10:27:14Z', // 10:27, 26 Apr 2016
|
|
|
|
user: 'User1',
|
|
|
|
minor: true
|
|
|
|
} ),
|
2016-08-03 12:08:05 +00:00
|
|
|
tooltip,
|
|
|
|
tooltipHtml;
|
2016-06-29 10:43:46 +00:00
|
|
|
|
2016-07-04 11:49:59 +00:00
|
|
|
revision.setRelativeSize( 210 );
|
2016-06-29 10:43:46 +00:00
|
|
|
|
|
|
|
mw.libs.revisionSlider.userOffset = 0;
|
|
|
|
|
2017-03-03 13:55:42 +00:00
|
|
|
tooltip = revisionListView.makeTooltip( revision, {} );
|
2016-08-03 12:08:05 +00:00
|
|
|
tooltipHtml = tooltip.$element.html();
|
2016-06-29 10:43:46 +00:00
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
assert.ok( tooltipHtml.match( /User1/ ), 'Test the user.' );
|
|
|
|
assert.ok( tooltipHtml.match( /Hello/ ), 'Test the comment.' );
|
|
|
|
assert.ok( tooltipHtml.match( /230/ ), 'Test the page size.' );
|
|
|
|
assert.ok( tooltipHtml.match( /\+210/ ), 'Test the change size.' );
|
2016-06-29 10:43:46 +00:00
|
|
|
} );
|
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
QUnit.revisionSlider.testOrSkip( 'tooltip is composed correctly with en lang', function ( assert ) {
|
2016-07-04 11:49:59 +00:00
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
revision = new Revision( {
|
|
|
|
revid: 1,
|
|
|
|
size: 2300,
|
|
|
|
comment: 'Hello',
|
|
|
|
parsedcomment: '<strong>Hello</strong>',
|
|
|
|
timestamp: '2016-04-26T10:27:14Z', // 10:27, 26 Apr 2016
|
|
|
|
user: 'User1',
|
|
|
|
minor: true
|
|
|
|
} ),
|
2016-08-03 12:08:05 +00:00
|
|
|
tooltip,
|
2016-12-20 13:23:33 +00:00
|
|
|
tooltipHtml;
|
2016-07-04 11:49:59 +00:00
|
|
|
|
|
|
|
revision.setRelativeSize( 2100 );
|
|
|
|
|
|
|
|
mw.libs.revisionSlider.userOffset = 0;
|
|
|
|
|
2017-03-03 13:55:42 +00:00
|
|
|
tooltip = revisionListView.makeTooltip( revision, {} );
|
2016-08-03 12:08:05 +00:00
|
|
|
tooltipHtml = tooltip.$element.html();
|
2016-07-04 11:49:59 +00:00
|
|
|
|
2016-08-03 12:08:05 +00:00
|
|
|
assert.ok( tooltipHtml.match( /User1/ ), 'Test the user.' );
|
|
|
|
assert.ok( tooltipHtml.match( /Hello/ ), 'Test the comment.' );
|
|
|
|
assert.ok( tooltipHtml.match( /2,300/ ), 'Test the page size.' );
|
|
|
|
assert.ok( tooltipHtml.match( /\+2,100/ ), 'Test the change size.' );
|
2016-08-09 11:19:46 +00:00
|
|
|
assert.ok( tooltipHtml.match( /26 April 2016 10:27 AM/ ), 'Test the date.' );
|
2016-08-03 12:08:05 +00:00
|
|
|
assert.ok( tooltipHtml.match( /minor/ ), 'Test minor.' );
|
2016-07-04 11:49:59 +00:00
|
|
|
}, mw.config.get( 'wgUserLanguage' ) !== 'en' );
|
|
|
|
|
2016-06-29 10:43:46 +00:00
|
|
|
QUnit.test( 'empty user leads to no user line', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$userLineHtml;
|
|
|
|
|
|
|
|
$userLineHtml = revisionListView.makeUserLine( null );
|
|
|
|
|
|
|
|
assert.equal( $userLineHtml, '' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'user line is composed correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$userLineHtml;
|
|
|
|
|
|
|
|
$userLineHtml = revisionListView.makeUserLine( 'User1' );
|
|
|
|
|
|
|
|
assert.equal( $userLineHtml.find( 'a' ).text(), 'User1' );
|
|
|
|
assert.ok( $userLineHtml.find( 'a' ).attr( 'href' ).match( /User:User1/ ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'IP user line is composed correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$userLineHtml;
|
|
|
|
|
|
|
|
$userLineHtml = revisionListView.makeUserLine( '127.0.0.1' );
|
|
|
|
|
|
|
|
assert.equal( $userLineHtml.find( 'a' ).text(), '127.0.0.1' );
|
|
|
|
assert.ok( $userLineHtml.find( 'a' ).attr( 'href' ).match( /Special:Contributions\/127.0.0.1/ ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'empty comment leads to no comment line', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$commentHtml;
|
|
|
|
|
|
|
|
$commentHtml = revisionListView.makeCommentLine( new Revision( {
|
|
|
|
comment: ' ',
|
|
|
|
parsedcomment: ' '
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
assert.equal( $commentHtml, '' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'comment line is composed correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$commentLineHtml;
|
|
|
|
|
|
|
|
$commentLineHtml = revisionListView.makeCommentLine( new Revision( {
|
|
|
|
comment: 'Hello',
|
|
|
|
parsedcomment: '<strong>Hello</strong>'
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
assert.equal( $commentLineHtml.find( 'strong' ).length, 2 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'positive change is composed correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$changeSizeLineHtml;
|
|
|
|
|
|
|
|
$changeSizeLineHtml = revisionListView.makeChangeSizeLine( 9 );
|
|
|
|
|
2016-07-01 10:13:53 +00:00
|
|
|
assert.equal( $changeSizeLineHtml.find( '.mw-revslider-change-positive' ).length, 1 );
|
|
|
|
assert.equal( $changeSizeLineHtml.find( '.mw-revslider-change-positive' ).text(), '+9' );
|
2016-06-29 10:43:46 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'negative change is composed correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$changeSizeLineHtml;
|
|
|
|
|
|
|
|
$changeSizeLineHtml = revisionListView.makeChangeSizeLine( -9 );
|
|
|
|
|
2016-07-01 10:13:53 +00:00
|
|
|
assert.equal( $changeSizeLineHtml.find( '.mw-revslider-change-negative' ).length, 1 );
|
|
|
|
assert.equal( $changeSizeLineHtml.find( '.mw-revslider-change-negative' ).text(), '-9' );
|
2016-06-29 10:43:46 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'neutral change is composed correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$changeSizeLineHtml;
|
|
|
|
|
|
|
|
$changeSizeLineHtml = revisionListView.makeChangeSizeLine( 0 );
|
|
|
|
|
2016-07-01 10:13:53 +00:00
|
|
|
assert.equal( $changeSizeLineHtml.find( '.mw-revslider-change-none' ).length, 1 );
|
|
|
|
assert.equal( $changeSizeLineHtml.find( '.mw-revslider-change-none' ).text(), '0' );
|
2016-06-29 10:43:46 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'big change number is formatted correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$changeSizeLineHtml;
|
|
|
|
|
|
|
|
$changeSizeLineHtml = revisionListView.makeChangeSizeLine( 1000 );
|
|
|
|
|
2016-07-01 10:13:53 +00:00
|
|
|
assert.equal( $changeSizeLineHtml.find( '.mw-revslider-change-positive' ).text(), '+1,000' );
|
2016-06-29 10:43:46 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'page size is formatted correctly', function ( assert ) {
|
|
|
|
var revisionListView = new RevisionListView(),
|
|
|
|
$pageSizeLineHtml;
|
|
|
|
|
|
|
|
$pageSizeLineHtml = revisionListView.makePageSizeLine( 1337 );
|
|
|
|
|
|
|
|
assert.ok( $pageSizeLineHtml.text().match( /1,337/ ) );
|
|
|
|
} );
|
|
|
|
|
2016-09-01 11:17:47 +00:00
|
|
|
}( mediaWiki ) );
|