mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-12-22 04:43:01 +00:00
5bf1466e7f
* Removed deprecated testCount, which is no longer supported in this way. It's only useful when wanting to explicitly expect 0 assertions (normally considered an error). * Replaced use of testCount = 0, with assert.expect( 0 ). Change-Id: I8fe82032d3af2a1ad2ed7febdb90a95d56dd3fc4
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
( function ( mw, $ ) {
|
|
QUnit.module( 'mmv.logging.ActionLogger', QUnit.newMwEnvironment() );
|
|
|
|
QUnit.test( 'log()', function ( assert ) {
|
|
var fakeEventLog = { logEvent: this.sandbox.stub() },
|
|
logger = new mw.mmv.logging.ActionLogger(),
|
|
action1key = 'test-1',
|
|
action1value = 'Test',
|
|
action2key = 'test-2',
|
|
action2value = 'Foo $1 $2 bar',
|
|
unknownAction = 'test-3',
|
|
clock = this.sandbox.useFakeTimers();
|
|
|
|
this.sandbox.stub( logger, 'loadDependencies' ).returns( $.Deferred().resolve() );
|
|
this.sandbox.stub( mw, 'log' );
|
|
|
|
logger.samplingFactorMap = { 'default': 1 };
|
|
logger.setEventLog( fakeEventLog );
|
|
logger.logActions = {};
|
|
logger.logActions[ action1key ] = action1value;
|
|
logger.logActions[ action2key ] = action2value;
|
|
|
|
logger.log( unknownAction );
|
|
clock.tick( 10 );
|
|
|
|
assert.strictEqual( mw.log.lastCall.args[ 0 ], unknownAction, 'Log message defaults to unknown key' );
|
|
assert.ok( fakeEventLog.logEvent.called, 'event log has been recorded' );
|
|
|
|
mw.log.reset();
|
|
fakeEventLog.logEvent.reset();
|
|
logger.log( action1key );
|
|
clock.tick( 10 );
|
|
|
|
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' );
|
|
|
|
mw.log.reset();
|
|
fakeEventLog.logEvent.reset();
|
|
logger.samplingFactorMap = { 'default': 0 };
|
|
logger.log( action1key, true );
|
|
clock.tick( 10 );
|
|
|
|
assert.ok( !mw.log.called, 'No logging when disabled' );
|
|
assert.ok( fakeEventLog.logEvent.called, 'event log has been recorded' );
|
|
|
|
clock.restore();
|
|
} );
|
|
}( mediaWiki, jQuery ) );
|