jenkins-bot has submitted this change and it was merged.
Change subject: Don't show WikiGrok twice on the same article after a user has
answered once
......................................................................
Don't show WikiGrok twice on the same article after a user has answered once
* Add QUnit tests
Change-Id: Iad5c6554c1d06cb53bfaefbcacd747c33b50ff86
---
M javascripts/modules/wikigrok/WikiGrokDialog.js
M javascripts/modules/wikigrok/WikiGrokDialogB.js
M javascripts/modules/wikigrok/init.js
M tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
4 files changed, 82 insertions(+), 4 deletions(-)
Approvals:
Jhernandez: Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/modules/wikigrok/WikiGrokDialog.js
b/javascripts/modules/wikigrok/WikiGrokDialog.js
index c12a29b..11b0f87 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialog.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialog.js
@@ -2,6 +2,7 @@
M.assertMode( [ 'beta', 'alpha' ] );
var Panel = M.require( 'Panel' ),
+ settings = M.require( 'settings' ),
WikiGrokSuggestionApi = M.require(
'modules/wikigrok/WikiGrokSuggestionApi' ),
WikiGrokResponseApi = M.require(
'modules/wikigrok/WikiGrokResponseApi' ),
WikiDataApi = M.require( 'modules/wikigrok/WikiDataApi' ),
@@ -261,7 +262,21 @@
} );
},
+ /**
+ * Save the page title in localStorage so that we don't show
WikiGrok on this page
+ * the next time the user sees the page.
+ */
+ rememberWikiGrokContribution: function () {
+ var pages = $.parseJSON(
+ settings.get(
'pagesWithWikiGrokContributions', false ) || '{}'
+ );
+
+ pages[M.getCurrentPage().title] = true;
+ settings.save( 'pagesWithWikiGrokContributions',
JSON.stringify( pages ), false );
+ },
+
thankUser: function ( options, claimAttempted ) {
+ this.rememberWikiGrokContribution();
options.thankUser = true;
if ( claimAttempted ) {
options.contentMsg = 'You just made Wikipedia a
little better, thanks!';
diff --git a/javascripts/modules/wikigrok/WikiGrokDialogB.js
b/javascripts/modules/wikigrok/WikiGrokDialogB.js
index 1638718..9692ab8 100644
--- a/javascripts/modules/wikigrok/WikiGrokDialogB.js
+++ b/javascripts/modules/wikigrok/WikiGrokDialogB.js
@@ -148,6 +148,7 @@
self.logError(
'no-response-cannot-record-user-input' );
} );
self.log( 'widget-click-submit' );
+ self.rememberWikiGrokContribution();
} );
// hide this Dialog when the user reads more about
Wikigrok
diff --git a/javascripts/modules/wikigrok/init.js
b/javascripts/modules/wikigrok/init.js
index f0af48b..80a59c3 100644
--- a/javascripts/modules/wikigrok/init.js
+++ b/javascripts/modules/wikigrok/init.js
@@ -5,6 +5,7 @@
var wikidataID = mw.config.get( 'wgWikibaseItemId' ),
errorSchema = M.require(
'loggingSchemas/mobileWebWikiGrokError' ),
+ settings = M.require( 'settings' ),
permittedOnThisDevice = mw.config.get(
'wgMFEnableWikiGrokOnAllDevices' ) || !M.isWideScreen(),
idOverride,
versionConfigs = {
@@ -22,6 +23,22 @@
versionConfig,
WikiGrokAbTest = M.require( 'WikiGrokAbTest' ),
wikiGrokUser = M.require( 'wikiGrokUser' );
+
+ /*
+ * Checks whether the user has already seen and responded to a WikiGrok
question
+ * before on this article and device.
+ */
+ function hasUserAlreadyContributedToWikiGrok() {
+ var pages = $.parseJSON(
+ settings.get( 'pagesWithWikiGrokContributions',
false ) || '{}'
+ ),
+ result = false;
+
+ if ( M.getCurrentPage().title in pages ) {
+ result = true;
+ }
+ return result;
+ }
/*
* Gets the configuration for the version of WikiGrok to use.
@@ -67,6 +84,8 @@
}
if (
+ // show WikiGrok if the user hasn't already contributed to it
on this page before
+ !hasUserAlreadyContributedToWikiGrok() &&
// WikiGrok is enabled
mw.config.get( 'wgMFEnableWikiGrok' ) &&
// We're not on the Main Page
diff --git a/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
b/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
index f3d605c..25c9d0b 100644
--- a/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
+++ b/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
@@ -3,6 +3,7 @@
var WikiGrokDialog = M.require( 'modules/wikigrok/WikiGrokDialog' ),
WikiDataApi = M.require( 'modules/wikigrok/WikiDataApi' ),
WikiGrokResponseApi = M.require(
'modules/wikigrok/WikiGrokResponseApi' ),
+ settings = M.require( 'settings'),
suggestions = [ {
"id": "P106",
"name": "occupations",
@@ -11,13 +12,20 @@
labels = {
Q285759: "insurance broker"
},
- pageTitle = 'Some guy';
+ pageTitle = M.getCurrentPage().title || 'Some guy';
+
+ function getPagesWithWikiGrokContributions () {
+ return $.parseJSON(
+ settings.get( 'pagesWithWikiGrokContributions', false )
|| '{}'
+ );
+ }
QUnit.module( 'MobileFrontend: WikiGrokDialog', {
teardown: function () {
this.wk.remove();
},
setup: function () {
+ settings.remove( 'pagesWithWikiGrokContributions',
false );
this.$el = $( '<div id="test">' );
this.wk = new WikiGrokDialog( {
el: this.$el,
@@ -124,34 +132,69 @@
this.$el.find( sel ).click();
}
- QUnit.test( '#UI - Question - Click Yes', 2, function ( assert ) {
+ QUnit.test( '#UI - Question - Click Yes', 4, function ( assert ) {
getToQuestion.apply( this );
+
+ assert.equal(
+ getPagesWithWikiGrokContributions()[pageTitle],
+ undefined,
+ "User's contribution to WikiGrok has not been saved
locally yet."
+ );
answerQuestion.call( this, '.yes' );
// I'm in thanks page now!
assert.equal( this.$el.find( '.wg-link' ).length, 1 );
assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+
+ assert.equal(
+ getPagesWithWikiGrokContributions()[pageTitle],
+ true,
+ "User's contribution to WikiGrok has been saved locally
correctly."
+ );
} );
- QUnit.test( '#UI - Question - Click No', 2, function ( assert ) {
+ QUnit.test( '#UI - Question - Click No', 4, function ( assert ) {
getToQuestion.apply( this );
+
+ assert.equal(
+ getPagesWithWikiGrokContributions()[pageTitle],
+ undefined,
+ "User's contribution to WikiGrok has not been saved
locally yet."
+ );
answerQuestion.call( this, '.no' );
// I'm in thanks page now!
assert.equal( this.$el.find( '.wg-link' ).length, 1 );
assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+
+ assert.equal(
+ getPagesWithWikiGrokContributions()[pageTitle],
+ true,
+ "User's contribution to WikiGrok has been saved locally
correctly."
+ );
} );
- QUnit.test( '#UI - Question - Click Not sure', 2, function ( assert ) {
+ QUnit.test( '#UI - Question - Click Not sure', 4, function ( assert ) {
getToQuestion.apply( this );
+
+ assert.equal(
+ getPagesWithWikiGrokContributions()[pageTitle],
+ undefined,
+ "User's contribution to WikiGrok has not been saved
locally yet."
+ );
answerQuestion.call( this, '.not-sure' );
// I'm in thanks page now!
assert.equal( this.$el.find( '.wg-link' ).length, 1 );
assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+ assert.equal(
+ getPagesWithWikiGrokContributions()[pageTitle],
+ true,
+ "User's contribution to WikiGrok has been saved locally
correctly."
+ );
} );
}( jQuery, mw.mobileFrontend ) );
--
To view, visit https://gerrit.wikimedia.org/r/175639
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iad5c6554c1d06cb53bfaefbcacd747c33b50ff86
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits