mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-11 07:16:08 +00:00
aa6972c277
The eventlogging `isEnabled` function determines when to sample, this patch removes the `isAnon` conditional so that we can measure reference reading habits for all users. Also guards against a non-function navigator.sendBeacon, which was previously intended but incorrectly tested. Bug: T214493 Change-Id: I42cb3082fb85c7900426a2055dfa3c2f6ecfd968
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
import { isEnabled } from '../../../src/instrumentation/eventLogging';
|
|
import * as stubs from '../stubs';
|
|
|
|
QUnit.module( 'ext.popups/instrumentation/eventLogging', {
|
|
beforeEach() {
|
|
this.config = new Map();
|
|
this.config.set( 'wgPopupsEventLogging', true );
|
|
|
|
this.window = {
|
|
navigator: {
|
|
sendBeacon() {}
|
|
}
|
|
};
|
|
|
|
this.user = stubs.createStubUser();
|
|
|
|
// Helper function that DRYs up the tests below.
|
|
this.isEnabled = function () {
|
|
return isEnabled(
|
|
this.user,
|
|
this.config,
|
|
this.window
|
|
);
|
|
};
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'it should return false when sendBeacon isn\'t supported', function ( assert ) {
|
|
this.window = {};
|
|
assert.notOk( this.isEnabled(),
|
|
'No sendBeacon. No logging.' );
|
|
// ---
|
|
|
|
this.window.navigator = {
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
};
|
|
|
|
assert.notOk(
|
|
this.isEnabled(),
|
|
'EventLogging is disabled.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should respect PopupsEventLogging', function ( assert ) {
|
|
assert.ok( this.isEnabled(), 'EventLogging is enabled.' );
|
|
this.config.set( 'wgPopupsEventLogging', false );
|
|
assert.notOk( this.isEnabled(), 'EventLogging is disabled.' );
|
|
} );
|
|
|
|
QUnit.test( 'it should respect the debug flag always', function ( assert ) {
|
|
this.config.set( 'wgPopupsEventLogging', false );
|
|
this.config.set( 'debug', false );
|
|
assert.notOk( this.isEnabled(), 'not logged' );
|
|
|
|
this.config.set( 'debug', true );
|
|
assert.ok( this.isEnabled(), 'is logged!' );
|
|
} );
|