reducers: Don't destroy interaction on LINK_CLICK

I09d8776 introduced a bug in the eventLogging reducer where reducing
LINK_CLICK would remove any accumulated interaction state but not close
the interaction.

Update the associated tests so that they correctly test the reduction of
this action.

Bug: T162924
Change-Id: Ia03e719c228ee96f279c1fa89252dc6b6371a8e9
This commit is contained in:
Sam Smith 2017-04-18 19:42:47 +01:00
parent bb43c9c2e6
commit 2c171d7f25
4 changed files with 22 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View file

@ -201,9 +201,9 @@ module.exports = function ( state, action ) {
case actionTypes.LINK_CLICK:
return nextState( state, {
interaction: {
interaction: nextState( state.interaction, {
finalized: true
},
} ),
event: {
action: 'opened',
linkInteractionToken: state.interaction.token,

View file

@ -285,37 +285,43 @@ QUnit.test(
);
QUnit.test( 'LINK_CLICK should enqueue an "opened" event', function ( assert ) {
var state,
var token = '0987654321',
state,
expectedState,
now = Date.now();
state = {
interaction: undefined
};
state = eventLogging( state, {
expectedState = state = eventLogging( state, {
type: 'LINK_DWELL',
token: '0987654321',
el: this.link,
token: token,
timestamp: now
} );
state = eventLogging( state, {
type: 'LINK_CLICK',
timestamp: now + 250.25
el: this.link,
timestamp: now + 250
} );
assert.deepEqual(
state.event,
{
action: 'opened',
linkInteractionToken: '0987654321',
linkInteractionToken: token,
totalInteractionTime: 250
},
'The event is enqueued and the totalInteractionTime property is an integer.'
);
assert.strictEqual(
state.interaction.finalized,
true,
expectedState.interaction.finalized = true;
assert.deepEqual(
state.interaction,
expectedState.interaction,
'It should finalize the interaction.'
);
} );
@ -612,13 +618,19 @@ QUnit.test( 'ABANDON_END doesn\'t enqueue an event under certain conditions', fu
timestamp: now + 500
} );
state = eventLogging( state, {
type: 'EVENT_LOGGED'
} );
state = eventLogging( state, {
type: 'ABANDON_START',
token: token,
timestamp: now + 700
} );
state = eventLogging( state, {
type: 'ABANDON_END',
token: token,
timestamp: now + 1000 // ABANDON_END_DELAY is 300 ms.
} );