mediawiki-extensions-Multim.../tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js
Timo Tijhof 0f092b6cb3 tests: Minor clean up of mmv.ui.metadataPanel.js and other tests
* Declare variables inline, as per the current code conventions.

* Use `assert.true()` or `assert.false()` in a few places.

* Clarify some test names and simplify some surrounding code.

Change-Id: Id0bca942e34564b9c011e89c0b2298cbb4f8a582
2022-05-13 22:13:01 +01:00

47 lines
1.6 KiB
JavaScript

QUnit.module( 'mmv.logging.ActionLogger', QUnit.newMwEnvironment() );
QUnit.test( 'log()', function ( assert ) {
var fakeEventLog = { logEvent: this.sandbox.stub() };
var logger = new mw.mmv.logging.ActionLogger();
var action1key = 'test-1';
var action1value = 'Test';
var action2key = 'test-2';
var action2value = 'Foo $1 $2 bar';
var unknownAction = 'test-3';
var 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.strictEqual( fakeEventLog.logEvent.called, true, '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.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' );
mw.log.reset();
fakeEventLog.logEvent.reset();
logger.samplingFactorMap = { default: 0 };
logger.log( action1key, true );
clock.tick( 10 );
assert.strictEqual( mw.log.called, false, 'No logging when disabled' );
assert.strictEqual( fakeEventLog.logEvent.called, true, 'event log has been recorded' );
clock.restore();
} );