2016-05-03 10:03:38 +00:00
|
|
|
( function ( mw ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var Revision = mw.libs.revisionSlider.Revision;
|
|
|
|
|
2016-04-28 10:18:52 +00:00
|
|
|
QUnit.module( 'ext.RevisionSlider.Revision' );
|
|
|
|
|
|
|
|
QUnit.test( 'create Revision', function ( assert ) {
|
|
|
|
var data = {
|
|
|
|
size: 5,
|
|
|
|
comment: 'hello',
|
|
|
|
parsedcomment: '<b>hello</b>',
|
|
|
|
timestamp: '2016-04-26T10:27:14Z', // 10:27, 26 Apr 2016
|
2016-06-27 14:00:13 +00:00
|
|
|
user: 'meh',
|
|
|
|
userGender: 'female'
|
2016-04-28 10:18:52 +00:00
|
|
|
},
|
2016-07-25 13:35:41 +00:00
|
|
|
rev = new Revision( data );
|
2016-04-28 10:18:52 +00:00
|
|
|
|
2016-05-20 18:00:52 +00:00
|
|
|
mw.libs.revisionSlider.userOffset = 0;
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-04-28 10:18:52 +00:00
|
|
|
assert.equal( rev.getSize(), data.size );
|
|
|
|
assert.equal( rev.getComment(), data.comment );
|
|
|
|
assert.equal( rev.getParsedComment(), data.parsedcomment );
|
|
|
|
assert.equal( rev.getUser(), data.user );
|
2016-06-27 14:00:13 +00:00
|
|
|
assert.equal( rev.getUserGender(), 'female' );
|
2016-05-12 12:00:00 +00:00
|
|
|
assert.equal( rev.isMinor(), false );
|
|
|
|
|
2016-07-04 11:49:59 +00:00
|
|
|
if ( mw.config.get( 'wgUserLanguage' ) === 'en' ) {
|
2016-08-09 11:19:46 +00:00
|
|
|
assert.equal( rev.getFormattedDate(), '26 April 2016 10:27 AM' );
|
2016-07-04 11:49:59 +00:00
|
|
|
}
|
|
|
|
} );
|
2016-05-12 12:00:00 +00:00
|
|
|
|
2016-07-04 11:49:59 +00:00
|
|
|
QUnit.test( 'isMinor with minor empty string', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-07-04 11:49:59 +00:00
|
|
|
minor: ''
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-05-12 12:00:00 +00:00
|
|
|
assert.equal( rev.isMinor(), true );
|
|
|
|
} );
|
|
|
|
|
2016-07-04 11:49:59 +00:00
|
|
|
QUnit.test( 'isMinor with minor true', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-07-04 11:49:59 +00:00
|
|
|
minor: true
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-05-12 12:00:00 +00:00
|
|
|
assert.equal( rev.isMinor(), true );
|
2016-04-28 10:18:52 +00:00
|
|
|
} );
|
|
|
|
|
2016-05-12 13:52:54 +00:00
|
|
|
QUnit.test( 'get and set relative size', function ( assert ) {
|
|
|
|
var size = 5,
|
2016-07-25 13:35:41 +00:00
|
|
|
rev = new Revision( {} );
|
2016-05-12 13:52:54 +00:00
|
|
|
rev.setRelativeSize( size );
|
|
|
|
assert.equal( rev.getRelativeSize(), size );
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-07-04 11:49:59 +00:00
|
|
|
QUnit.revisionSlider.testOrSkip( 'getFormattedDate, offset: 0', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-07-04 11:49:59 +00:00
|
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-05-20 18:00:52 +00:00
|
|
|
mw.libs.revisionSlider.userOffset = 0;
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-08-09 11:19:46 +00:00
|
|
|
assert.equal( rev.getFormattedDate(), '26 April 2016 10:27 AM' );
|
2016-07-04 11:49:59 +00:00
|
|
|
}, mw.config.get( 'wgUserLanguage' ) !== 'en' );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-07-04 11:49:59 +00:00
|
|
|
QUnit.revisionSlider.testOrSkip( 'getFormattedDate, offset: 120 (treat as hours, +2h)', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-07-04 11:49:59 +00:00
|
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-05-20 18:00:52 +00:00
|
|
|
// Berlin = 120
|
|
|
|
mw.libs.revisionSlider.userOffset = 120;
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-08-09 11:19:46 +00:00
|
|
|
assert.equal( rev.getFormattedDate(), '26 April 2016 12:27 PM' );
|
2016-07-04 11:49:59 +00:00
|
|
|
}, mw.config.get( 'wgUserLanguage' ) !== 'en' );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-07-04 11:49:59 +00:00
|
|
|
QUnit.revisionSlider.testOrSkip( 'getFormattedDate, negative offset: -420 (treat as hours, -7h)', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-07-04 11:49:59 +00:00
|
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-05-20 18:00:52 +00:00
|
|
|
// San Francisco = -420
|
|
|
|
mw.libs.revisionSlider.userOffset = -420;
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-08-09 11:19:46 +00:00
|
|
|
assert.equal( rev.getFormattedDate(), '26 April 2016 3:27 AM' );
|
2016-07-04 11:49:59 +00:00
|
|
|
}, mw.config.get( 'wgUserLanguage' ) !== 'en' );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2016-05-30 12:36:48 +00:00
|
|
|
QUnit.test( 'hasEmptyComment comment with whitespaces', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-05-30 12:36:48 +00:00
|
|
|
comment: ' '
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.ok( rev.hasEmptyComment() );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'hasEmptyComment comment with chars', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-05-30 12:36:48 +00:00
|
|
|
comment: ' comment '
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.notOk( rev.hasEmptyComment() );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'hasEmptyComment comment with unicode chars', function ( assert ) {
|
2016-07-25 13:35:41 +00:00
|
|
|
var rev = new Revision( {
|
2016-05-30 12:36:48 +00:00
|
|
|
comment: 'ברוכים'
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.notOk( rev.hasEmptyComment() );
|
|
|
|
} );
|
|
|
|
|
2016-09-01 11:17:47 +00:00
|
|
|
}( mediaWiki ) );
|
2016-05-02 10:05:31 +00:00
|
|
|
|