2020-11-20 10:31:12 +00:00
|
|
|
var SliderModule = require( 'ext.RevisionSlider.Slider' ),
|
|
|
|
Revision = SliderModule.Revision;
|
2020-11-18 09:11:12 +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
|
|
|
|
user: 'meh',
|
|
|
|
userGender: 'female'
|
|
|
|
},
|
|
|
|
rev = new Revision( data );
|
|
|
|
|
2020-11-20 10:31:12 +00:00
|
|
|
SliderModule.setUserOffset( 0 );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
assert.strictEqual( rev.getSize(), data.size );
|
|
|
|
assert.strictEqual( rev.getComment(), data.comment );
|
|
|
|
assert.strictEqual( rev.getParsedComment(), data.parsedcomment );
|
|
|
|
assert.strictEqual( rev.getUser(), data.user );
|
|
|
|
assert.strictEqual( rev.getUserGender(), 'female' );
|
2022-01-13 12:15:32 +00:00
|
|
|
assert.false( rev.isMinor() );
|
2020-11-18 09:11:12 +00:00
|
|
|
|
|
|
|
if ( mw.config.get( 'wgUserLanguage' ) === 'en' ) {
|
|
|
|
assert.strictEqual( rev.getFormattedDate(), '26 April 2016 10:27 AM' );
|
|
|
|
}
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.test( 'isMinor with minor empty string', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
minor: ''
|
2016-05-12 12:00:00 +00:00
|
|
|
} );
|
|
|
|
|
2022-01-13 12:15:32 +00:00
|
|
|
assert.true( rev.isMinor() );
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.test( 'isMinor with minor true', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
minor: true
|
2016-04-28 10:18:52 +00:00
|
|
|
} );
|
|
|
|
|
2022-01-13 12:15:32 +00:00
|
|
|
assert.true( rev.isMinor() );
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.test( 'get and set relative size', function ( assert ) {
|
|
|
|
var size = 5,
|
|
|
|
rev = new Revision( {} );
|
|
|
|
rev.setRelativeSize( size );
|
|
|
|
assert.strictEqual( rev.getRelativeSize(), size );
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.revisionSlider.testOrSkip( 'getFormattedDate, offset: 0', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-20 10:31:12 +00:00
|
|
|
SliderModule.setUserOffset( 0 );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
assert.strictEqual( rev.getFormattedDate(), '26 April 2016 10:27 AM' );
|
|
|
|
}, mw.config.get( 'wgUserLanguage' ) !== 'en' );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.revisionSlider.testOrSkip( 'getFormattedDate, offset: 120 (treat as hours, +2h)', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
// Berlin = 120
|
2020-11-20 10:31:12 +00:00
|
|
|
SliderModule.setUserOffset( 120 );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
assert.strictEqual( rev.getFormattedDate(), '26 April 2016 12:27 PM' );
|
|
|
|
}, mw.config.get( 'wgUserLanguage' ) !== 'en' );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.revisionSlider.testOrSkip( 'getFormattedDate, negative offset: -420 (treat as hours, -7h)', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
|
|
} );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
// San Francisco = -420
|
2020-11-20 10:31:12 +00:00
|
|
|
SliderModule.setUserOffset( -420 );
|
2016-05-12 16:01:50 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
assert.strictEqual( rev.getFormattedDate(), '26 April 2016 3:27 AM' );
|
|
|
|
}, mw.config.get( 'wgUserLanguage' ) !== 'en' );
|
2016-05-30 12:36:48 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.test( 'hasEmptyComment comment with whitespaces', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
comment: ' '
|
2016-05-30 12:36:48 +00:00
|
|
|
} );
|
|
|
|
|
2022-01-13 12:15:32 +00:00
|
|
|
assert.true( rev.hasEmptyComment() );
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
2016-05-30 12:36:48 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.test( 'hasEmptyComment comment with chars', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
comment: ' comment '
|
2016-05-30 12:36:48 +00:00
|
|
|
} );
|
|
|
|
|
2022-01-13 12:15:32 +00:00
|
|
|
assert.false( rev.hasEmptyComment() );
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|
2016-05-30 12:36:48 +00:00
|
|
|
|
2020-11-18 09:11:12 +00:00
|
|
|
QUnit.test( 'hasEmptyComment comment with unicode chars', function ( assert ) {
|
|
|
|
var rev = new Revision( {
|
|
|
|
comment: 'ברוכים'
|
2016-05-30 12:36:48 +00:00
|
|
|
} );
|
|
|
|
|
2022-01-13 12:15:32 +00:00
|
|
|
assert.false( rev.hasEmptyComment() );
|
2020-11-18 09:11:12 +00:00
|
|
|
} );
|