mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 03:34:03 +00:00
6d29d08de3
These are annotations for ESLint as described at: https://eslint.org/docs/user-guide/configuring#specifying-globals I'm not sure where the `…: false` comes from. I assume it is a mistake and does not have an effect. I tried to move these annotations closer to the line they are about in case there is only one line. And move it to the top when there is more than one line using the global. Change-Id: I4bd112c5fddd8a97d829a9b91707b8eb7cd7a332
67 lines
2 KiB
JavaScript
67 lines
2 KiB
JavaScript
import { isEnabled } from '../../../src/instrumentation/eventLogging';
|
|
import * as stubs from '../stubs';
|
|
|
|
QUnit.module( 'ext.popups/instrumentation/eventLogging', {
|
|
beforeEach() {
|
|
this.config = new Map(); /* global Map */
|
|
this.config.set( 'wgPopupsEventLogging', true );
|
|
|
|
this.window = {
|
|
navigator: {
|
|
sendBeacon() {}
|
|
}
|
|
};
|
|
|
|
this.user = stubs.createStubUser();
|
|
this.anonUser = stubs.createStubUser( true );
|
|
|
|
// Helper function that DRYs up the tests below.
|
|
this.isEnabled = function ( isAnon ) {
|
|
return isEnabled(
|
|
isAnon ? this.anonUser : this.user,
|
|
this.config,
|
|
this.window
|
|
);
|
|
};
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'it should return false when sendBeacon isn\'t supported', function ( assert ) {
|
|
const window = {};
|
|
assert.notOk( isEnabled( this.user, this.config, window ),
|
|
'No sendBeacon. No logging.' );
|
|
assert.notOk( isEnabled( this.anonUser, this.config, window ),
|
|
'No sendBeacon. No logging for anons.' );
|
|
// ---
|
|
|
|
window.navigator = {
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
};
|
|
|
|
assert.notOk(
|
|
isEnabled( this.user, this.config, window ),
|
|
'EventLogging is disabled.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should respect PopupsEventLogging', function ( assert ) {
|
|
assert.ok( this.isEnabled( true ), 'EventLogging is enabled.' );
|
|
assert.notOk( this.isEnabled(), 'but not for logged in users' );
|
|
this.config.set( 'wgPopupsEventLogging', false );
|
|
assert.notOk( this.isEnabled(), 'authenticated users are not logged' );
|
|
assert.notOk( this.isEnabled( true ), 'anons are not logged' );
|
|
} );
|
|
|
|
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(), 'authenticated not logged' );
|
|
assert.notOk( this.isEnabled( true ), 'anons not logged' );
|
|
|
|
this.config.set( 'debug', true );
|
|
assert.ok( this.isEnabled(), 'authenticated users are logged!' );
|
|
assert.ok( this.isEnabled( true ), 'EventLogging is enabled.' );
|
|
|
|
this.config.set( 'wgPopupsEventLogging', true );
|
|
} );
|