2016-11-30 13:40:08 +00:00
|
|
|
( function ( mw ) {
|
|
|
|
|
2016-12-01 13:12:29 +00:00
|
|
|
var counts = mw.popups.counts;
|
|
|
|
|
2016-11-30 13:40:08 +00:00
|
|
|
QUnit.module( 'ext.popups/reducers#eventLogging', {
|
|
|
|
setup: function () {
|
|
|
|
this.initialState = mw.popups.reducers.eventLogging( undefined, {
|
|
|
|
type: '@@INIT'
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
QUnit.test( '@@INIT', function ( assert ) {
|
|
|
|
assert.deepEqual(
|
|
|
|
this.initialState,
|
|
|
|
{
|
|
|
|
previewCount: undefined,
|
|
|
|
baseData: {},
|
|
|
|
event: undefined,
|
|
|
|
interaction: undefined
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-11-30 13:40:08 +00:00
|
|
|
QUnit.test( 'BOOT', function ( assert ) {
|
|
|
|
var action = {
|
2016-12-01 14:56:46 +00:00
|
|
|
type: 'BOOT',
|
2016-12-14 14:24:21 +00:00
|
|
|
isEnabled: true,
|
2016-12-01 14:56:46 +00:00
|
|
|
sessionToken: '0123456789',
|
|
|
|
pageToken: '9876543210',
|
|
|
|
page: {
|
|
|
|
title: 'Foo',
|
|
|
|
namespaceID: 1,
|
|
|
|
id: 2
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
isAnon: false,
|
|
|
|
editCount: 11,
|
|
|
|
previewCount: 22
|
|
|
|
}
|
2016-11-30 13:40:08 +00:00
|
|
|
},
|
2016-12-01 14:56:46 +00:00
|
|
|
expectedEditCountBucket,
|
|
|
|
expectedPreviewCountBucket;
|
|
|
|
|
|
|
|
expectedEditCountBucket = counts.getEditCountBucket( action.user.editCount );
|
|
|
|
expectedPreviewCountBucket = counts.getPreviewCountBucket( action.user.previewCount );
|
2016-11-30 13:40:08 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.eventLogging( this.initialState, action ),
|
|
|
|
{
|
2016-12-01 14:56:46 +00:00
|
|
|
previewCount: action.user.previewCount,
|
2016-11-30 13:40:08 +00:00
|
|
|
baseData: {
|
|
|
|
pageTitleSource: action.page.title,
|
|
|
|
namespaceIdSource: action.page.namespaceID,
|
|
|
|
pageIdSource: action.page.id,
|
2016-12-01 13:12:29 +00:00
|
|
|
isAnon: action.user.isAnon,
|
2016-12-14 14:24:21 +00:00
|
|
|
popupEnabled: action.isEnabled,
|
2016-11-30 13:40:08 +00:00
|
|
|
pageToken: action.pageToken,
|
2016-12-01 13:12:29 +00:00
|
|
|
sessionToken: action.sessionToken,
|
2016-12-01 14:56:46 +00:00
|
|
|
editCountBucket: expectedEditCountBucket,
|
|
|
|
previewCountBucket: expectedPreviewCountBucket
|
2016-11-30 13:40:08 +00:00
|
|
|
},
|
|
|
|
event: {
|
|
|
|
action: 'pageLoaded'
|
2016-12-06 14:02:13 +00:00
|
|
|
},
|
|
|
|
interaction: undefined
|
2016-11-30 13:40:08 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'EVENT_LOGGED', function ( assert ) {
|
|
|
|
var state,
|
|
|
|
action;
|
|
|
|
|
|
|
|
state = {
|
|
|
|
event: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
action = {
|
|
|
|
type: 'EVENT_LOGGED'
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.eventLogging( state, action ),
|
|
|
|
{
|
|
|
|
event: undefined
|
|
|
|
},
|
|
|
|
'It dequeues any event queued for logging.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-05 11:56:51 +00:00
|
|
|
QUnit.test( 'PREVIEW_SHOW', function ( assert ) {
|
|
|
|
var state,
|
|
|
|
count = 22,
|
|
|
|
expectedCount = count + 1;
|
|
|
|
|
|
|
|
state = {
|
|
|
|
previewCount: count,
|
|
|
|
baseData: {
|
|
|
|
previewCountBucket: counts.getPreviewCountBucket( count )
|
|
|
|
},
|
2016-12-08 09:02:27 +00:00
|
|
|
event: undefined,
|
|
|
|
|
|
|
|
// state.interaction.started is used in this part of the reducer.
|
|
|
|
interaction: {}
|
2016-12-05 11:56:51 +00:00
|
|
|
};
|
|
|
|
|
2016-12-08 09:02:27 +00:00
|
|
|
state = mw.popups.reducers.eventLogging( state, {
|
2016-12-05 11:56:51 +00:00
|
|
|
type: 'PREVIEW_SHOW'
|
2016-12-08 09:02:27 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
state.previewCount,
|
|
|
|
expectedCount,
|
|
|
|
'It updates the user\'s preview count.'
|
|
|
|
);
|
2016-12-05 11:56:51 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
2016-12-08 09:02:27 +00:00
|
|
|
state.baseData,
|
2016-12-05 11:56:51 +00:00
|
|
|
{
|
2016-12-08 09:02:27 +00:00
|
|
|
previewCountBucket: counts.getPreviewCountBucket( expectedCount )
|
2016-12-05 11:56:51 +00:00
|
|
|
},
|
2016-12-08 09:02:27 +00:00
|
|
|
'It re-buckets the user\'s preview count.'
|
2016-12-05 11:56:51 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-06 14:02:13 +00:00
|
|
|
QUnit.module( 'ext.popups/reducers#eventLogging @integration' );
|
|
|
|
|
|
|
|
QUnit.test( 'LINK_DWELL starts an interaction', function ( assert ) {
|
|
|
|
var state,
|
|
|
|
action;
|
|
|
|
|
|
|
|
state = {
|
2016-12-08 09:02:27 +00:00
|
|
|
interaction: undefined
|
2016-12-06 14:02:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
action = {
|
|
|
|
type: 'LINK_DWELL',
|
|
|
|
interactionToken: '0987654321',
|
|
|
|
timestamp: mw.now()
|
|
|
|
};
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.reducers.eventLogging( state, action ),
|
|
|
|
{
|
|
|
|
interaction: {
|
|
|
|
token: action.interactionToken,
|
|
|
|
started: action.timestamp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-07 10:56:54 +00:00
|
|
|
QUnit.test( 'LINK_CLICK should enqueue an "opened" event', function ( assert ) {
|
|
|
|
var state,
|
|
|
|
now = mw.now();
|
|
|
|
|
|
|
|
state = {
|
|
|
|
interaction: undefined
|
|
|
|
};
|
|
|
|
|
|
|
|
state = mw.popups.reducers.eventLogging( state, {
|
|
|
|
type: 'LINK_DWELL',
|
|
|
|
interactionToken: '0987654321',
|
|
|
|
timestamp: now
|
|
|
|
} );
|
|
|
|
|
|
|
|
state = mw.popups.reducers.eventLogging( state, {
|
|
|
|
type: 'LINK_CLICK',
|
|
|
|
timestamp: now + 250.25
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
state.event,
|
|
|
|
{
|
|
|
|
action: 'opened',
|
|
|
|
linkInteractionToken: '0987654321',
|
|
|
|
totalInteractionTime: 250
|
|
|
|
},
|
|
|
|
'The event is enqueued and the totalInteractionProperty is an integer.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-12-08 09:02:27 +00:00
|
|
|
QUnit.test( 'PREVIEW_SHOW should update the perceived wait time of the interaction', function ( assert ) {
|
|
|
|
var state,
|
|
|
|
now = mw.now();
|
|
|
|
|
|
|
|
state = {
|
|
|
|
interaction: undefined
|
|
|
|
};
|
|
|
|
|
|
|
|
state = mw.popups.reducers.eventLogging( state, {
|
|
|
|
type: 'LINK_DWELL',
|
|
|
|
interactionToken: '0987654321',
|
|
|
|
timestamp: now
|
|
|
|
} );
|
|
|
|
|
|
|
|
state = mw.popups.reducers.eventLogging( state, {
|
|
|
|
type: 'PREVIEW_SHOW',
|
|
|
|
timestamp: now + 500
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.deepEqual( state.interaction, {
|
|
|
|
token: '0987654321',
|
|
|
|
started: now,
|
|
|
|
timeToPreviewShow: 500
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2016-11-30 13:40:08 +00:00
|
|
|
}( mediaWiki ) );
|