Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/317670
Change subject: Hygiene: Move logic for duplicate events into getMassagedData ...................................................................... Hygiene: Move logic for duplicate events into getMassagedData Add tests. Change-Id: I15c10f256432ab5bfa7bf7adb34764f84b17c439 --- M resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js M resources/ext.popups.schemaPopups/ext.popups.schemaPopups.js M tests/qunit/ext.popups.schemaPopups.utils.test.js 3 files changed, 33 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups refs/changes/70/317670/1 diff --git a/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js b/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js index 405b308..7c9c9da 100644 --- a/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js +++ b/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js @@ -88,10 +88,20 @@ /** * Return data after making some adjustments so that it's ready to be logged * - * @param {Object}data + * @param {Object} data + * @param {Object} previousLogData * @return {Object} */ - function getMassagedData( data ) { + function getMassagedData( data, previousLogData ) { + + // Only one action is recorded per link interaction token... + if ( data.linkInteractionToken && + data.linkInteractionToken === previousLogData.linkInteractionToken ) { + // however, the 'disabled' action takes two clicks by nature, so allow it + if ( data.action !== 'disabled' ) { + return false; + } + } data.previewCountBucket = mw.popups.getPreviewCountBucket(); delete data.dwellStartTime; // Figure out `namespaceIdHover` from `pageTitleHover`. diff --git a/resources/ext.popups.schemaPopups/ext.popups.schemaPopups.js b/resources/ext.popups.schemaPopups/ext.popups.schemaPopups.js index afe31b3..cde36ea 100644 --- a/resources/ext.popups.schemaPopups/ext.popups.schemaPopups.js +++ b/resources/ext.popups.schemaPopups/ext.popups.schemaPopups.js @@ -11,18 +11,9 @@ mw.trackSubscribe( 'ext.popups.schemaPopups', function ( topic, data ) { var shouldLog = true; - data = mw.popups.schemaPopups.getMassagedData( data ); + data = mw.popups.schemaPopups.getMassagedData( data, previousLogData ); - // Only one action is recorded per link interaction token... - if ( data.linkInteractionToken && - data.linkInteractionToken === previousLogData.linkInteractionToken ) { - // however, the 'disabled' action takes two clicks by nature, so allow it - if ( data.action !== 'disabled' ) { - shouldLog = false; - } - } - - if ( shouldLog ) { + if ( data ) { schemaPopups.log( data ); } previousLogData = data; diff --git a/tests/qunit/ext.popups.schemaPopups.utils.test.js b/tests/qunit/ext.popups.schemaPopups.utils.test.js index 9f4e145..9a6b7d7 100644 --- a/tests/qunit/ext.popups.schemaPopups.utils.test.js +++ b/tests/qunit/ext.popups.schemaPopups.utils.test.js @@ -126,4 +126,23 @@ newData = schemaPopups.getMassagedData( initialData ); assert.ok( newData.namespaceIdHover === 1, 'namespace is added based on title' ); } ); + + QUnit.test( 'getMassagedData - returns false if the data should not be logged due to being a duplicate', 2, function ( assert ) { + var + thisEvent = { + action: 'myevent', + linkInteractionToken: 't' + }, + previousEvent = { + action: 'myevent', + linkInteractionToken: 't' + }, + settingsEvent = { + action: 'disabled', + linkInteractionToken: 't' + }; + + assert.ok( schemaPopups.getMassagedData( thisEvent, previousEvent ) === false, 'duplicate events are ignored...' ); + assert.ok( schemaPopups.getMassagedData( settingsEvent, thisEvent ) !== false, '... unless disabled event' ); + } ); } )( jQuery, mediaWiki ); -- To view, visit https://gerrit.wikimedia.org/r/317670 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I15c10f256432ab5bfa7bf7adb34764f84b17c439 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Popups Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits