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
|
|
|
|
2014-11-15 15:32:04 +00:00
|
|
|
QUnit.test( 'log()', 6, function ( assert ) {
|
2014-05-19 09:24:54 +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',
|
|
|
|
unknownAction = 'test-3';
|
|
|
|
|
|
|
|
this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() );
|
|
|
|
this.sandbox.stub( mw, 'log' );
|
|
|
|
|
2014-05-28 22:43:35 +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 );
|
|
|
|
|
|
|
|
assert.strictEqual( mw.log.getCall( 0 ).args[ 0 ], unknownAction , 'Log message defaults to unknown key' );
|
|
|
|
assert.strictEqual( fakeEventLog.logEvent.callCount, 1, 'event log has been recorded' );
|
|
|
|
|
|
|
|
logger.log( action1key );
|
|
|
|
|
|
|
|
assert.strictEqual( mw.log.getCall( 1 ).args[ 0 ], action1value, 'Log message is translated to its text' );
|
|
|
|
assert.strictEqual( fakeEventLog.logEvent.callCount, 2, 'event log has been recorded' );
|
|
|
|
|
2014-11-15 15:32:04 +00:00
|
|
|
logger.samplingFactorMap = { 'default' : 0 };
|
2014-05-19 09:24:54 +00:00
|
|
|
logger.log( action1key, true );
|
|
|
|
|
|
|
|
assert.strictEqual( mw.log.getCall( 2 ).args[ 0 ], action1value, 'Log message is translated to its text' );
|
|
|
|
assert.strictEqual( fakeEventLog.logEvent.callCount, 3, 'event log has been recorded' );
|
|
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|