2017-07-28 17:32:46 +00:00
|
|
|
import { isEnabled } from '../../../src/instrumentation/eventLogging';
|
2017-08-10 17:55:26 +00:00
|
|
|
import { BUCKETS } from '../../../src/constants';
|
2017-07-28 17:32:46 +00:00
|
|
|
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.
|
2017-08-10 17:55:26 +00:00
|
|
|
this.isEnabled = function ( isAnon, bucket ) {
|
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,
|
2017-08-10 17:55:26 +00:00
|
|
|
bucket || BUCKETS.on,
|
2017-06-14 11:00:01 +00:00
|
|
|
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 = {};
|
2017-08-10 17:55:26 +00:00
|
|
|
assert.notOk( isEnabled( this.user, this.config, BUCKETS.on, window ),
|
|
|
|
'No sendBeacon. No logging.' );
|
|
|
|
assert.notOk( isEnabled( this.anonUser, this.config, BUCKETS.on, window ),
|
|
|
|
'No sendBeacon. No logging for anons.' );
|
2017-06-14 11:00:01 +00:00
|
|
|
// ---
|
|
|
|
|
|
|
|
window.navigator = {
|
|
|
|
sendBeacon: 'NOT A FUNCTION'
|
|
|
|
};
|
|
|
|
|
2017-08-10 17:55:26 +00:00
|
|
|
assert.notOk( isEnabled( this.user, this.config, BUCKETS.on, window ) );
|
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 ) {
|
|
|
|
assert.ok( this.isEnabled( true ) );
|
|
|
|
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( 'if experiment is 0 all events are logged', function ( assert ) {
|
|
|
|
this.config.set( 'wgPopupsAnonsExperimentalGroupSize', 0 );
|
|
|
|
assert.ok( this.isEnabled( true ) );
|
|
|
|
assert.notOk( this.isEnabled(), 'except for logged in users' );
|
|
|
|
} );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-08-10 17:55:26 +00:00
|
|
|
QUnit.test( 'if experiment is running on group is subject to event logging', function ( assert ) {
|
|
|
|
assert.ok( this.isEnabled( true ) );
|
|
|
|
assert.notOk( this.isEnabled(), 'but not for anons' );
|
|
|
|
} );
|
2017-02-28 17:32:35 +00:00
|
|
|
|
2017-08-10 17:55:26 +00:00
|
|
|
QUnit.test( 'if experiment is running control group is subject to event logging', function ( assert ) {
|
|
|
|
assert.ok( this.isEnabled( true, BUCKETS.control ), 'anons are logged' );
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.notOk(
|
|
|
|
this.isEnabled( false, BUCKETS.control ),
|
|
|
|
'but not authenticated users' );
|
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( 'if experiment is running off group is not subject to event logging', function ( assert ) {
|
|
|
|
assert.notOk( this.isEnabled( true, BUCKETS.off ) );
|
|
|
|
assert.notOk( this.isEnabled( false, BUCKETS.off ) );
|
2017-02-28 17:32:35 +00:00
|
|
|
} );
|
2017-06-30 16:19:39 +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!' );
|
|
|
|
assert.ok( this.isEnabled( true ) );
|
|
|
|
|
|
|
|
this.config.set( 'wgPopupsEventLogging', true );
|
|
|
|
|
2018-01-18 18:48:16 +00:00
|
|
|
assert.ok(
|
|
|
|
this.isEnabled( true, BUCKETS.off ), 'Even when user is bucketed as off' );
|
|
|
|
assert.ok(
|
|
|
|
this.isEnabled( false, BUCKETS.off ),
|
|
|
|
'Even when user is logged in and bucketed as off' );
|
2017-06-30 16:19:39 +00:00
|
|
|
} );
|