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() {
|
2017-06-14 11:00:01 +00:00
|
|
|
this.config = stubs.createStubMap();
|
2017-02-28 17:32:35 +00:00
|
|
|
|
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-08-10 17:55:26 +00:00
|
|
|
this.anonUser = stubs.createStubUser( true );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-06-14 11:00:01 +00:00
|
|
|
// Helper function that DRYs up the tests below.
|
2018-05-03 21:22:11 +00:00
|
|
|
this.isEnabled = function ( isAnon ) {
|
2017-06-14 11:00:01 +00:00
|
|
|
return isEnabled(
|
2017-08-10 17:55:26 +00:00
|
|
|
isAnon ? this.anonUser : this.user,
|
2017-06-14 11:00:01 +00:00
|
|
|
this.config,
|
|
|
|
this.window
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} );
|
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 ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const window = {};
|
2018-05-03 21:22:11 +00:00
|
|
|
assert.notOk( isEnabled( this.user, this.config, window ),
|
2017-08-10 17:55:26 +00:00
|
|
|
'No sendBeacon. No logging.' );
|
2018-05-03 21:22:11 +00:00
|
|
|
assert.notOk( isEnabled( this.anonUser, this.config, window ),
|
2017-08-10 17:55:26 +00:00
|
|
|
'No sendBeacon. No logging for anons.' );
|
2017-06-14 11:00:01 +00:00
|
|
|
// ---
|
|
|
|
|
|
|
|
window.navigator = {
|
|
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
|
|
};
|
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.notOk(
|
|
|
|
isEnabled( this.user, this.config, window ),
|
|
|
|
'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 ) {
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.ok( this.isEnabled( true ), 'EventLogging is enabled.' );
|
2017-08-10 17:55:26 +00:00
|
|
|
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' );
|
|
|
|
} );
|
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 );
|
2017-08-10 17:55:26 +00:00
|
|
|
assert.notOk( this.isEnabled(), 'authenticated not logged' );
|
|
|
|
assert.notOk( this.isEnabled( true ), 'anons not logged' );
|
2017-06-30 16:19:39 +00:00
|
|
|
|
|
|
|
this.config.set( 'debug', true );
|
2017-08-10 17:55:26 +00:00
|
|
|
assert.ok( this.isEnabled(), 'authenticated users are logged!' );
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.ok( this.isEnabled( true ), 'EventLogging is enabled.' );
|
2017-08-10 17:55:26 +00:00
|
|
|
|
|
|
|
this.config.set( 'wgPopupsEventLogging', true );
|
2017-06-30 16:19:39 +00:00
|
|
|
} );
|