mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-20 03:01:01 +00:00
c1abe80b08
Change-Id: I56bcfa040553a96f018f22483f3f988c5639fc97
52 lines
1.3 KiB
JavaScript
52 lines
1.3 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 = () => 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!' );
|
|
} );
|