2017-07-28 17:32:46 +00:00
|
|
|
import { isEnabled } from '../../../src/instrumentation/eventLogging';
|
|
|
|
import * as stubs from '../stubs';
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-15 12:15:46 +00:00
|
|
|
QUnit.module( 'ext.popups/instrumentation/eventLogging', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2019-09-17 11:47:25 +00:00
|
|
|
this.config = new Map();
|
2017-08-10 17:55:26 +00:00
|
|
|
this.config.set( 'wgPopupsEventLogging', true );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
|
|
|
this.window = {
|
|
|
|
navigator: {
|
2018-03-14 22:04:59 +00:00
|
|
|
sendBeacon() {}
|
2017-02-28 17:32:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
this.user = stubs.createStubUser();
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
// Helper function that DRYs up the tests below.
|
2020-10-29 14:33:53 +00:00
|
|
|
this.isEnabled = () => isEnabled( this.user, this.config, this.window );
|
2017-06-14 11:00:01 +00:00
|
|
|
}
|
|
|
|
} );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-07-03 12:05:00 +00:00
|
|
|
QUnit.test( 'it should return false when sendBeacon isn\'t supported', function ( assert ) {
|
2019-09-25 15:20:34 +00:00
|
|
|
this.window = {};
|
|
|
|
assert.notOk( this.isEnabled(),
|
2017-08-10 17:55:26 +00:00
|
|
|
'No sendBeacon. No logging.' );
|
2017-06-14 11:00:01 +00:00
|
|
|
// ---
|
|
|
|
|
2019-09-25 15:20:34 +00:00
|
|
|
this.window.navigator = {
|
2017-06-14 11:00:01 +00:00
|
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
|
|
};
|
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.notOk(
|
2019-09-25 15:20:34 +00:00
|
|
|
this.isEnabled(),
|
2018-05-08 19:48:17 +00:00
|
|
|
'EventLogging is disabled.'
|
|
|
|
);
|
2017-06-14 11:00:01 +00:00
|
|
|
} );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-08-10 17:55:26 +00:00
|
|
|
QUnit.test( 'it should respect PopupsEventLogging', function ( assert ) {
|
2019-09-25 15:20:34 +00:00
|
|
|
assert.ok( this.isEnabled(), 'EventLogging is enabled.' );
|
2017-08-10 17:55:26 +00:00
|
|
|
this.config.set( 'wgPopupsEventLogging', false );
|
2019-09-25 15:20:34 +00:00
|
|
|
assert.notOk( this.isEnabled(), 'EventLogging is disabled.' );
|
2017-08-10 17:55:26 +00:00
|
|
|
} );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-08-10 17:55:26 +00:00
|
|
|
QUnit.test( 'it should respect the debug flag always', function ( assert ) {
|
|
|
|
this.config.set( 'wgPopupsEventLogging', false );
|
2017-06-30 16:19:39 +00:00
|
|
|
this.config.set( 'debug', false );
|
2019-09-25 15:20:34 +00:00
|
|
|
assert.notOk( this.isEnabled(), 'not logged' );
|
2017-06-30 16:19:39 +00:00
|
|
|
|
|
|
|
this.config.set( 'debug', true );
|
2019-09-25 15:20:34 +00:00
|
|
|
assert.ok( this.isEnabled(), 'is logged!' );
|
2017-06-30 16:19:39 +00:00
|
|
|
} );
|