2014-05-19 09:24:54 +00:00
|
|
|
( function ( mw, $ ) {
|
2014-09-04 23:00:55 +00:00
|
|
|
QUnit.module( 'mmv.logging.ActionLogger', QUnit.newMwEnvironment() );
|
2014-05-19 09:24:54 +00:00
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'log()', function ( assert ) {
|
2015-01-23 12:48:27 +00:00
|
|
|
var fakeEventLog = { logEvent: this.sandbox.stub() },
|
2014-09-04 23:00:55 +00:00
|
|
|
logger = new mw.mmv.logging.ActionLogger(),
|
2014-05-19 09:24:54 +00:00
|
|
|
action1key = 'test-1',
|
|
|
|
action1value = 'Test',
|
|
|
|
action2key = 'test-2',
|
|
|
|
action2value = 'Foo $1 $2 bar',
|
2017-05-15 13:03:19 +00:00
|
|
|
unknownAction = 'test-3',
|
|
|
|
clock = this.sandbox.useFakeTimers();
|
2014-05-19 09:24:54 +00:00
|
|
|
|
|
|
|
this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() );
|
|
|
|
this.sandbox.stub( mw, 'log' );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
logger.samplingFactorMap = { 'default': 1 };
|
2014-05-19 09:24:54 +00:00
|
|
|
logger.setEventLog( fakeEventLog );
|
|
|
|
logger.logActions = {};
|
|
|
|
logger.logActions[ action1key ] = action1value;
|
|
|
|
logger.logActions[ action2key ] = action2value;
|
|
|
|
|
|
|
|
logger.log( unknownAction );
|
2017-05-15 13:03:19 +00:00
|
|
|
clock.tick( 10 );
|
2014-05-19 09:24:54 +00:00
|
|
|
|
2016-07-18 13:49:27 +00:00
|
|
|
assert.strictEqual( mw.log.lastCall.args[ 0 ], unknownAction, 'Log message defaults to unknown key' );
|
2015-02-19 23:30:29 +00:00
|
|
|
assert.ok( fakeEventLog.logEvent.called, 'event log has been recorded' );
|
2014-05-19 09:24:54 +00:00
|
|
|
|
2015-02-19 23:30:29 +00:00
|
|
|
mw.log.reset();
|
|
|
|
fakeEventLog.logEvent.reset();
|
2014-05-19 09:24:54 +00:00
|
|
|
logger.log( action1key );
|
2017-05-15 13:03:19 +00:00
|
|
|
clock.tick( 10 );
|
2014-05-19 09:24:54 +00:00
|
|
|
|
2015-02-19 23:30:29 +00:00
|
|
|
assert.strictEqual( mw.log.lastCall.args[ 0 ], action1value, 'Log message is translated to its text' );
|
|
|
|
assert.ok( fakeEventLog.logEvent.called, 'event log has been recorded' );
|
2014-05-19 09:24:54 +00:00
|
|
|
|
2015-02-19 23:30:29 +00:00
|
|
|
mw.log.reset();
|
|
|
|
fakeEventLog.logEvent.reset();
|
2015-01-23 12:48:27 +00:00
|
|
|
logger.samplingFactorMap = { 'default': 0 };
|
2014-05-19 09:24:54 +00:00
|
|
|
logger.log( action1key, true );
|
2017-05-15 13:03:19 +00:00
|
|
|
clock.tick( 10 );
|
2014-05-19 09:24:54 +00:00
|
|
|
|
2015-02-19 23:30:29 +00:00
|
|
|
assert.ok( !mw.log.called, 'No logging when disabled' );
|
|
|
|
assert.ok( fakeEventLog.logEvent.called, 'event log has been recorded' );
|
2017-05-15 13:03:19 +00:00
|
|
|
|
|
|
|
clock.restore();
|
2014-05-19 09:24:54 +00:00
|
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|