Send disabled event from settings windows

Changes:
 - introduced new event 'disabled', sent from settings popup
 - added unit tests for 'disabled' event handling

Bug: T167365
Change-Id: I048b38122b8843199c86fd1ed9ec2ff21767e114
This commit is contained in:
Piotr Miazga 2017-06-30 17:07:43 +02:00
parent 4f9ad4d0a7
commit 7e2c79ae0d
4 changed files with 53 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View file

@ -157,11 +157,11 @@ module.exports = function ( state, action ) {
!state.interaction &&
action.type !== actionTypes.BOOT &&
action.type !== actionTypes.LINK_DWELL &&
action.type !== actionTypes.EVENT_LOGGED
action.type !== actionTypes.EVENT_LOGGED &&
action.type !== actionTypes.SETTINGS_CHANGE
) {
return state;
}
switch ( action.type ) {
case actionTypes.BOOT:
return nextState( state, {
@ -188,7 +188,6 @@ module.exports = function ( state, action ) {
) {
newState.interaction = undefined;
}
return newState;
case actionTypes.FETCH_COMPLETE:
@ -285,6 +284,16 @@ module.exports = function ( state, action ) {
} )
} );
case actionTypes.SETTINGS_CHANGE:
if ( action.wasEnabled && !action.enabled ) {
return nextState( state, {
event: {
action: 'disabled'
}
} );
} else {
return state;
}
default:
return state;
}

View file

@ -634,6 +634,47 @@ QUnit.test( 'SETTINGS_SHOW should enqueue a "tapped settings cog" event', functi
);
} );
QUnit.test( 'SETTINGS_CHANGE should enqueue disabled event', function ( assert ) {
var state = eventLogging( undefined, {
type: 'SETTINGS_CHANGE',
wasEnabled: false,
enabled: false
} );
assert.equal(
state.event,
undefined,
'It shouldn\'t enqueue a "disabled" event when there is no change'
);
state = eventLogging( state, {
type: 'SETTINGS_CHANGE',
wasEnabled: true,
enabled: false
} );
assert.deepEqual(
state.event,
{
action: 'disabled'
},
'It should enqueue a "disabled" event when the previews has been disabled'
);
delete state.event;
state = eventLogging( state, {
type: 'SETTINGS_CHANGE',
wasEnabled: false,
enabled: true
} );
assert.equal(
state.event,
undefined,
'It shouldn\'t enqueue a "disabled" event when page previews has been enabled'
);
} );
QUnit.test( 'ABANDON_END should enqueue an event', function ( assert ) {
var dwelledState,
token = '0987654321',