mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-12-12 07:25:13 +00:00
fc74a35709
If the user has a time offset that will be used. If the user uses the default then the offset is still retrieved from mw.user.options.values.timecorrection If the user is anon then mw.config.values.extRevisionSliderTimeOffset is used which is added as a JS var by the Hook Bug: T135109 Change-Id: Iab56bbeb6a1dd2ea08b73983341485623ff63ef1
129 lines
4 KiB
JavaScript
129 lines
4 KiB
JavaScript
( function ( mw ) {
|
|
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'
|
|
},
|
|
rev = new mw.libs.revisionSlider.Revision( data );
|
|
|
|
mw.config.values.extRevisionSliderTimeOffset = 0;
|
|
mw.user.options.values.timecorrection = 0;
|
|
|
|
assert.equal( rev.getSize(), data.size );
|
|
assert.equal( rev.getComment(), data.comment );
|
|
assert.equal( rev.getParsedComment(), data.parsedcomment );
|
|
assert.equal( rev.getFormattedDate(), '10:27, 26 Apr 2016' );
|
|
assert.equal( rev.getUser(), data.user );
|
|
assert.equal( rev.isMinor(), false );
|
|
} );
|
|
|
|
QUnit.test( 'create minor Revision (minor empty string)', 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',
|
|
minor: ''
|
|
},
|
|
rev = new mw.libs.revisionSlider.Revision( data );
|
|
|
|
mw.config.values.extRevisionSliderTimeOffset = 0;
|
|
mw.user.options.values.timecorrection = 0;
|
|
|
|
assert.equal( rev.getSize(), data.size );
|
|
assert.equal( rev.getComment(), data.comment );
|
|
assert.equal( rev.getParsedComment(), data.parsedcomment );
|
|
assert.equal( rev.getFormattedDate(), '10:27, 26 Apr 2016' );
|
|
assert.equal( rev.getUser(), data.user );
|
|
assert.equal( rev.isMinor(), true );
|
|
} );
|
|
|
|
QUnit.test( 'create minor Revision (minor true, as if from another Revision object)', 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',
|
|
minor: true
|
|
},
|
|
rev = new mw.libs.revisionSlider.Revision( data );
|
|
|
|
mw.config.values.extRevisionSliderTimeOffset = 0;
|
|
mw.user.options.values.timecorrection = 0;
|
|
|
|
assert.equal( rev.getSize(), data.size );
|
|
assert.equal( rev.getComment(), data.comment );
|
|
assert.equal( rev.getParsedComment(), data.parsedcomment );
|
|
assert.equal( rev.getFormattedDate(), '10:27, 26 Apr 2016' );
|
|
assert.equal( rev.getUser(), data.user );
|
|
assert.equal( rev.isMinor(), true );
|
|
} );
|
|
|
|
QUnit.test( 'get Revision with section', function ( assert ) {
|
|
var data = {
|
|
comment: '/* section */ comment'
|
|
},
|
|
rev = new mw.libs.revisionSlider.Revision( data );
|
|
|
|
assert.equal( rev.getSection(), 'section' );
|
|
} );
|
|
|
|
QUnit.test( 'get Revision without section', function ( assert ) {
|
|
var data = {
|
|
comment: 'no section comment'
|
|
},
|
|
rev = new mw.libs.revisionSlider.Revision( data );
|
|
|
|
assert.equal( rev.getSection(), '' );
|
|
} );
|
|
|
|
QUnit.test( 'get and set relative size', function ( assert ) {
|
|
var size = 5,
|
|
rev = new mw.libs.revisionSlider.Revision( {} );
|
|
rev.setRelativeSize( size );
|
|
assert.equal( rev.getRelativeSize(), size );
|
|
} );
|
|
|
|
QUnit.test( 'getFormattedDate No user offset, 0 default offset', function ( assert ) {
|
|
var rev = new mw.libs.revisionSlider.Revision( {
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
} );
|
|
|
|
mw.user.options.values.timecorrection = undefined;
|
|
mw.config.values.extRevisionSliderTimeOffset = 0;
|
|
|
|
assert.equal( rev.getFormattedDate(), '10:27, 26 Apr 2016' );
|
|
} );
|
|
|
|
QUnit.test( 'getFormattedDate No user offset, 1 default offset', function ( assert ) {
|
|
var rev = new mw.libs.revisionSlider.Revision( {
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
} );
|
|
|
|
mw.user.options.values.timecorrection = undefined;
|
|
mw.config.values.extRevisionSliderTimeOffset = 60;
|
|
|
|
assert.equal( rev.getFormattedDate(), '11:27, 26 Apr 2016' );
|
|
} );
|
|
|
|
QUnit.test( 'getFormattedDate 2 user offset, 1 default offset', function ( assert ) {
|
|
var rev = new mw.libs.revisionSlider.Revision( {
|
|
timestamp: '2016-04-26T10:27:14Z' // 10:27, 26 Apr 2016
|
|
} );
|
|
|
|
mw.user.options.values.timecorrection = 'FOO|120|BAR';
|
|
mw.config.values.extRevisionSliderTimeOffset = 60;
|
|
|
|
assert.equal( rev.getFormattedDate(), '12:27, 26 Apr 2016' );
|
|
} );
|
|
|
|
} )( mediaWiki );
|
|
|