Phuedx has uploaded a new change for review. https://gerrit.wikimedia.org/r/191358
Change subject: Remove WikiGrok version A ...................................................................... Remove WikiGrok version A * Merge the WikiGrokDialog and WikiGrokDialogB dialogs and their test cases * Remove the WikiGrokAbTest class Change-Id: Iec3921cddfe6fc026b5757eb338efc44232bbf7a --- M includes/Resources.php D javascripts/WikiGrokAbTest.js M javascripts/WikiGrokDialog.js D javascripts/WikiGrokDialogB.js M javascripts/WikiGrokDialogC.js M javascripts/init.js M templates/WikiGrokDialog.hogan D templates/WikiGrokDialogB.hogan D tests/qunit/test_WikiGrokAbTest.js M tests/qunit/test_WikiGrokDialog.js D tests/qunit/test_WikiGrokDialogB.js 11 files changed, 267 insertions(+), 707 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiGrok refs/changes/58/191358/1 diff --git a/includes/Resources.php b/includes/Resources.php index 008826d..54f7225 100644 --- a/includes/Resources.php +++ b/includes/Resources.php @@ -5,24 +5,13 @@ } $wgResourceModules = array_merge( $wgResourceModules, array( - 'ext.wikigrok.abTest' => $wgWikiGrokResourceFileModuleBoilerplate + array( - 'dependencies' => array( - 'mobile.user', - 'jquery.cookie', - ), - 'scripts' => array( - 'javascripts/wikigrokuser.js', - 'javascripts/WikiGrokAbTest.js', - ), - ), - 'ext.wikigrok.startup' => $wgWikiGrokResourceFileModuleBoilerplate + array( 'dependencies' => array( 'mobile.startup', 'ext.wikiGrok.loggingSchemas', - 'ext.wikigrok.abTest', ), 'scripts' => array( + 'javascripts/wikigrokuser.js', 'javascripts/wikiGrokCampaigns.js', 'javascripts/init.js', ), @@ -44,12 +33,14 @@ 'ext.wikigrok.startup', 'ext.wikiGrok.loggingSchemas', 'ext.wikigrok.api', + 'mediawiki.ui.checkbox', ), 'templates' => array( 'Error.hogan' => 'templates/WikiGrokError.hogan', 'Dialog.hogan' => 'templates/WikiGrokDialog.hogan', 'WikiGrokMoreInfo/content.hogan' => 'templates/WikiGrokMoreInfo.hogan', 'Thanks.hogan' => 'templates/WikiGrokThanks.hogan', + 'tagButton.hogan' => 'templates/tagButton.hogan', ), 'scripts' => array( 'javascripts/WikiGrokDialog.js', @@ -57,30 +48,14 @@ ), 'styles' => array( 'less/WikiGrokDialog.less', - ), - ), - - 'ext.wikigrok.dialog.b' => $wgWikiGrokResourceFileModuleBoilerplate + array( - 'dependencies' => array( - 'ext.wikigrok.dialog', - 'mediawiki.ui.checkbox', - ), - 'styles' => array( 'less/tagButton.less', - ), - 'templates' => array( - 'Dialog.hogan' => 'templates/WikiGrokDialogB.hogan', - 'tagButton.hogan' => 'templates/tagButton.hogan', - ), - 'scripts' => array( - 'javascripts/WikiGrokDialogB.js', ), ), 'ext.wikigrok.roulette' => $wgWikiGrokResourceFileModuleBoilerplate + array( 'dependencies' => array( 'mobile.overlays', - 'ext.wikigrok.dialog.b', + 'ext.wikigrok.dialog', ), 'scripts' => array( 'javascripts/roulette/ErrorDrawer.js', @@ -108,10 +83,9 @@ 'ext.wikigrok.dialog.c' => $wgWikiGrokResourceFileModuleBoilerplate + array( 'dependencies' => array( 'ext.wikigrok.roulette', - 'ext.wikigrok.dialog.b', ), 'scripts' => array( - 'javascripts/WikiGrokDialogC.js', + 'javascripts/WikiGrokDialog.js', ), 'templates' => array( 'Badge.hogan' => 'templates/WikiGrokRouletteBadge.hogan', diff --git a/javascripts/WikiGrokAbTest.js b/javascripts/WikiGrokAbTest.js deleted file mode 100644 index adbe3c6..0000000 --- a/javascripts/WikiGrokAbTest.js +++ /dev/null @@ -1,47 +0,0 @@ -( function ( M ) { - - var Class = M.require( 'Class' ), - - /** - * Represents the WikiGrok A/B test. - * - * @class WikiGrokAbTest - * @extends Class - */ - WikiGrokAbTest = Class.extend( { - - /** - * Initialises a new instance of the WikiGrokAbTest class. - * @method - * @param {Boolean} isEnabled Whether or not the A/B test is enabled - */ - initialize: function ( isEnabled ) { - this.isEnabled = isEnabled; - }, - - /** - * Gets the version of WikiGrok to show to the user. - * @method - * @param {Object} wikiGrokUser The WikiGrok user - * @return {String} `'A'` or `'B'` - */ - getVersion: function ( wikiGrokUser ) { - var lastCharacter = wikiGrokUser.getToken().slice( -1 ); - - return lastCharacter > 'U' ? 'B' : 'A'; - } - } ); - - /** - * Creates a new instance of the WikiGrokAbTest using `wgWikiGrokEnable` as - * the `isEnabled` parameter. - * @method - * @return {WikiGrokAbTest} - */ - WikiGrokAbTest.newFromMwConfig = function () { - return new WikiGrokAbTest( mw.config.get( 'wgWikiGrokEnable' ) ); - }; - - M.define( 'WikiGrokAbTest', WikiGrokAbTest ); - -}( mw.mobileFrontend, mw ) ); diff --git a/javascripts/WikiGrokDialog.js b/javascripts/WikiGrokDialog.js index 93840a7..bbaa391 100644 --- a/javascripts/WikiGrokDialog.js +++ b/javascripts/WikiGrokDialog.js @@ -10,7 +10,8 @@ errorSchema = new Schema( {}, 'MobileWebWikiGrokError' ), WikiGrokDialog, timer = null, - $window = $( window ); + $window = $( window ), + wikiGrokCampaigns = M.require( 'wikiGrokCampaigns' ); /** * @class WikiGrokDialog @@ -18,11 +19,11 @@ * THIS IS AN EXPERIMENTAL FEATURE THAT MAY BE MOVED TO A SEPARATE EXTENSION. * This creates the dialog at the bottom of the lead section that appears when a user * scrolls past the lead. It asks the user to confirm metadata information for use - * in Wikidata (https://www.wikidata.org). + * in Wikidata (https://www.wikidata.org) */ WikiGrokDialog = Panel.extend( { - version: 'a', className: 'wikigrok', + /** * @cfg {Object} defaults Default options hash. * @cfg {Boolean} defaults.beginQuestions Whether to show questions. @@ -86,13 +87,9 @@ } ); Panel.prototype.initialize.apply( this, arguments ); - // log page impression - // Only turn this on for bucketed tests with a relatively small number of - // users, e.g. 10% of readers. - //self.logPageImpression(); - // log widget impression when the widget is shown this.once( 'show', function () { + self.logPageImpression(); self.initializeWidgetImpressionLogging(); } ); }, @@ -187,51 +184,144 @@ }, /** - * Creates a question with a yes, no and not sure answer. - * Makes API request to Wikidata to retrieve labels and uses campaigns for that. - * FIXME: No i18n + * Renders a set of buttons to the panel. + * Fetches suggestions' labels from the server. + * Shows panel to user when there are suggestions. * @method - * @param {Object} options needed to render. + * @private + */ + _renderSuggestions: function () { + var suggestions, + allSuggestions, + $next, + $none, + self = this; + + allSuggestions = wikiGrokCampaigns.getAllSuggestions(); + // randomly pick 4 suggestions + suggestions = self.chooseRandomItemsFromArray( allSuggestions, 4 ); + + // Now work out the labels if we have some suggestions + if ( suggestions.length ) { + $next = self.$( '.footer .next' ); + $none = self.$( '.footer .none' ); + + // Hard-code the "Next" button width to match the "None" button width. + // That way, when the buttons are switched, the width stays the same. + // This depends on the assumption that the "Next" button text is + // always shorter than the "None" button text. + $next.css( 'width', $none.outerWidth() ); + + self.$( '.tags' ).show(); + $.each( suggestions, function ( i, suggestion ) { + var $tag, tagHtml, templateData, propertyName; + + // Replace some property names + // FIXME: These are not internationalizable and will probably have to + // die once WikiGrok is deployed outside of English Wikipedia + if ( suggestion.campaign.propertyName === 'instance of' ) { + propertyName = 'type'; + } else if ( suggestion.campaign.propertyName === 'original language of work' ) { + propertyName = 'original language'; + } else { + propertyName = suggestion.campaign.propertyName; + } + + templateData = { + id: 'tag-' + suggestion.id, + propName: suggestion.campaign.propertyName, + propId: suggestion.campaign.propertyId, + itemId: suggestion.id, + readable: suggestion.label, + campaignName: suggestion.campaign.name, + campaignText: propertyName, + tagText: suggestion.label + }; + + if ( suggestion.label ) { + tagHtml = mw.template.get( 'ext.wikigrok.dialog', 'tagButton.hogan' ) + .render( templateData ); + + $tag = $( tagHtml ) + .on( 'click', function () { + // Activate the tag + $( this ).toggleClass( 'mw-ui-progressive' ); + // If there are any tags active, switch submit button from + // "None" to "Next". + if ( self.$( '.tags .ui-tag-button.mw-ui-progressive' ).length ) { + $none.hide(); + $next.show(); + } else { + $next.hide(); + $none.show(); + } + } ).appendTo( self.$( '.tags' ) ); + } + } ); + + // only show the panel when we have created at least one button + if ( self.$( '.ui-tag-button' ).length ) { + self.$( '.spinner' ).hide(); + self.show(); + } + } + }, + + /** + * Show suggestions to the user. + * Also record claims when the user hits the save button. + * FIXME: Please refactor + * @method + * @param {Object} options needed to render */ askWikidataQuestion: function ( options ) { - var self = this, - vowels = [ 'a', 'e', 'i', 'o', 'u' ]; + var self = this; - options.claimId = options.campaign.randomClaimId; - options.claimLabel = options.campaign.questions[options.claimId]; + self.$( '.wg-notice' ).hide(); + self.$( '.wg-buttons' ).hide(); + self.$( '.spinner' ).show(); + self.$( '.wg-content' ).text( 'Select tags that correctly describe ' + options.title ); + self.$( '.footer' ).show(); - if ( options.campaign.name === 'author' ) { - // Hack for English prototype - if ( $.inArray( options.claimLabel.charAt( 0 ), vowels ) === -1 ) { - options.contentMsg = 'Is ' + options.name + ' a ' + options.claimLabel + '?'; - } else { - options.contentMsg = 'Is ' + options.name + ' an ' + options.claimLabel + '?'; + self._renderSuggestions( options.campaign ); + + this.$save = this.$( '.save' ); + this.$save.on( 'click', function () { + var answers = [], + hasCorrectAnswer = false; + + self.$( '.tags .ui-tag-button' ).each( function () { + var $this = $( this ), + correct = $this.is( '.mw-ui-progressive' ); + + if ( !hasCorrectAnswer && correct ) { + hasCorrectAnswer = true; + } + + answers.push( { + correct: correct ? true : null, + prop: $this.data( 'propname' ), + propid: $this.data( 'propid' ), + value: $this.data( 'readable' ), + valueid: $this.data( 'itemid' ), + campaign: $this.data( 'campaignname' ) + } ); + } ); + + self.$( '.tags' ).hide(); + self.$( '.spinner' ).show(); + + if ( !hasCorrectAnswer ) { + self.log( 'widget-click-none' ); } - } else if ( options.campaign.name === 'actor' ) { - options.contentMsg = 'Is ' + options.name + ' a ' + options.claimLabel + '?'; - } else if ( options.campaign.name === 'album' ) { - options.contentMsg = 'Is this a ' + options.claimLabel + '?'; - } - // Re-render with new content for 'Question' step - options.beginQuestions = true; - options.buttons = [ - { - classes: 'yes inline mw-ui-button mw-ui-progressive', - label: 'Yes' - }, - { - classes: 'not-sure inline mw-ui-button', - label: 'Not Sure' - }, - { - classes: 'no inline mw-ui-button mw-ui-progressive', - label: 'No' - } - ]; - options.noticeMsg = 'All submissions are <a class="wg-notice-link" ' + - 'href="#/wikigrok/about">released freely</a>'; - self.render( options ); + self.apiWikiGrokResponse.recordClaims( answers ).done( function () { + self.postRecordClaims( options, true ); + } ).fail( function () { + self.handleError( 'no-response-cannot-record-user-input' ); + } ); + self.log( 'widget-click-submit' ); + } ); }, /** @@ -414,33 +504,18 @@ this.log( 'page-impression' ); } }, + /** * @inheritdoc */ postRender: function ( options ) { var self = this; - // If you're wondering where the DOM insertion happens, look in wikigrokeval.js. + self.$( '.tags, .footer, .spinner' ).hide(); - // Initialize all the buttons and links - // ...for intermediate 'Question' step - if ( options.beginQuestions ) { - this.$( '.wg-buttons .yes' ).on( 'click', function () { - self.log( 'widget-click-submit' ); - options.claimIsCorrect = true; - self.recordClaim( options ); - } ); - this.$( '.wg-buttons .not-sure' ).on( 'click', function () { - self.log( 'widget-click-submit' ); - self.postRecordClaims( options, false ); - } ); - this.$( '.wg-buttons .no' ).on( 'click', function () { - self.log( 'widget-click-submit' ); - options.claimIsCorrect = false; - self.recordClaim( options ); - } ); - // ...for initial 'Intro' step - } else { + // show the welcome screen once + if ( !options.beginQuestions ) { + options.beginQuestions = true; this.$( '.wg-buttons .cancel' ).on( 'click', function () { self.hide(); self.log( 'widget-click-nothanks' ); @@ -454,19 +529,14 @@ this.$( '.wg-notice-link' ).on( 'click', function () { self.log( 'widget-click-moreinfo' ); } ); + + // hide wikigrok after an error has occurred + this.$( '.pane.error .close' ).on( 'click', function () { + self.hide(); + } ); + + this.reveal( options ); } - - // hide wikigrok after an error has occurred - this.$( '.pane.error .close' ).on( 'click', function () { - self.hide(); - } ); - - // render() does a "deep copy" $.extend() on the template data, so we need - // to reset the buttons after each step (since some steps have fewer - // buttons than the initial default). - self.options.buttons = []; - - this.reveal( options ); }, /** diff --git a/javascripts/WikiGrokDialogB.js b/javascripts/WikiGrokDialogB.js deleted file mode 100644 index 90be0ed..0000000 --- a/javascripts/WikiGrokDialogB.js +++ /dev/null @@ -1,215 +0,0 @@ -( function ( M, $ ) { - var WikiGrokDialog = M.require( 'WikiGrokDialog' ), - wikiGrokCampaigns = M.require( 'wikiGrokCampaigns' ), - WikiGrokDialogB; - - /** - * @class WikiGrokDialogB - * @extends WikiGrokDialog - * THIS IS AN EXPERIMENTAL FEATURE THAT MAY BE MOVED TO A SEPARATE EXTENSION. - * This creates the dialog at the bottom of the lead section that appears when a user - * scrolls past the lead. It asks the user to confirm metadata information for use - * in Wikidata (https://www.wikidata.org). - */ - WikiGrokDialogB = WikiGrokDialog.extend( { - version: 'b', - template: mw.template.get( 'ext.wikigrok.dialog.b', 'Dialog.hogan' ), - - /** @inheritdoc */ - initialize: function () { - var self = this; - - WikiGrokDialog.prototype.initialize.apply( this, arguments ); - - // log page impression and widget impression when the widget is shown - this.once( 'show', function () { - self.logPageImpression(); - self.initializeWidgetImpressionLogging(); - - } ); - }, - /** - * Renders a set of buttons to the panel. - * Fetches suggestions' labels from the server. - * Shows panel to user when there are suggestions. - * @method - * @private - */ - _renderSuggestions: function () { - var suggestions, - allSuggestions, - $next, - $none, - self = this; - - allSuggestions = wikiGrokCampaigns.getAllSuggestions(); - // randomly pick 4 suggestions - suggestions = self.chooseRandomItemsFromArray( allSuggestions, 4 ); - - // Now work out the labels if we have some suggestions - if ( suggestions.length ) { - $next = self.$( '.footer .next' ); - $none = self.$( '.footer .none' ); - - // Hard-code the "Next" button width to match the "None" button width. - // That way, when the buttons are switched, the width stays the same. - // This depends on the assumption that the "Next" button text is - // always shorter than the "None" button text. - $next.css( 'width', $none.outerWidth() ); - - self.$( '.tags' ).show(); - $.each( suggestions, function ( i, suggestion ) { - var $tag, tagHtml, templateData, propertyName; - - // Replace some property names - // FIXME: These are not internationalizable and will probably have to - // die once WikiGrok is deployed outside of English Wikipedia - if ( suggestion.campaign.propertyName === 'instance of' ) { - propertyName = 'type'; - } else if ( suggestion.campaign.propertyName === 'original language of work' ) { - propertyName = 'original language'; - } else { - propertyName = suggestion.campaign.propertyName; - } - - templateData = { - id: 'tag-' + suggestion.id, - propName: suggestion.campaign.propertyName, - propId: suggestion.campaign.propertyId, - itemId: suggestion.id, - readable: suggestion.label, - campaignName: suggestion.campaign.name, - campaignText: propertyName, - tagText: suggestion.label - }; - - if ( suggestion.label ) { - tagHtml = mw.template.get( 'ext.wikigrok.dialog.b', 'tagButton.hogan' ) - .render( templateData ); - - $tag = $( tagHtml ) - .on( 'click', function () { - // Activate the tag - $( this ).toggleClass( 'mw-ui-progressive' ); - // If there are any tags active, switch submit button from - // "None" to "Next". - if ( self.$( '.tags .ui-tag-button.mw-ui-progressive' ).length ) { - $none.hide(); - $next.show(); - } else { - $next.hide(); - $none.show(); - } - } ).appendTo( self.$( '.tags' ) ); - } - } ); - - // only show the panel when we have created at least one button - if ( self.$( '.ui-tag-button' ).length ) { - self.$( '.spinner' ).hide(); - self.show(); - } - } - }, - /** - * Show suggestions to the user. - * Also record claims when the user hits the save button. - * FIXME: Please refactor - * @method - * @param {Object} options needed to render - */ - askWikidataQuestion: function ( options ) { - var self = this; - - self.$( '.wg-notice' ).hide(); - self.$( '.wg-buttons' ).hide(); - self.$( '.spinner' ).show(); - self.$( '.wg-content' ).text( 'Select tags that correctly describe ' + options.title ); - self.$( '.footer' ).show(); - - self._renderSuggestions( options.campaign ); - - this.$save = this.$( '.save' ); - this.$save.on( 'click', function () { - var answers = [], - hasCorrectAnswer = false; - - self.$( '.tags .ui-tag-button' ).each( function () { - var $this = $( this ), - correct = $this.is( '.mw-ui-progressive' ); - - if ( !hasCorrectAnswer && correct ) { - hasCorrectAnswer = true; - } - - answers.push( { - correct: correct ? true : null, - prop: $this.data( 'propname' ), - propid: $this.data( 'propid' ), - value: $this.data( 'readable' ), - valueid: $this.data( 'itemid' ), - campaign: $this.data( 'campaignname' ) - } ); - } ); - - self.$( '.tags' ).hide(); - self.$( '.spinner' ).show(); - - if ( !hasCorrectAnswer ) { - self.log( 'widget-click-none' ); - } - - self.apiWikiGrokResponse.recordClaims( answers ).done( function () { - self.postRecordClaims( options, true ); - } ).fail( function () { - self.handleError( 'no-response-cannot-record-user-input' ); - } ); - self.log( 'widget-click-submit' ); - } ); - }, - /** - * @inheritdoc - */ - postRender: function ( options ) { - var self = this; - - self.$( '.tags, .footer, .spinner' ).hide(); - - // show the welcome screen once - if ( !options.beginQuestions ) { - options.beginQuestions = true; - this.$( '.wg-buttons .cancel' ).on( 'click', function () { - self.hide(); - self.log( 'widget-click-nothanks' ); - } ); - this.$( '.wg-buttons .proceed' ).on( 'click', function () { - self.log( 'widget-click-accept' ); - // Proceed with asking the user a metadata question. - self.askWikidataQuestion( options ); - } ); - // Log more info clicks - this.$( '.wg-notice-link' ).on( 'click', function () { - self.log( 'widget-click-moreinfo' ); - } ); - - // hide wikigrok after an error has occurred - this.$( '.pane.error .close' ).on( 'click', function () { - self.hide(); - } ); - - this.reveal( options ); - } - }, - - /** - * @inheritdoc - */ - reveal: function ( options ) { - if ( options.campaign ) { - this.show(); - } - } - } ); - - M.define( 'WikiGrokDialogB', WikiGrokDialogB ); -}( mw.mobileFrontend, jQuery ) ); diff --git a/javascripts/WikiGrokDialogC.js b/javascripts/WikiGrokDialogC.js index e7fe9a5..8bddb78 100644 --- a/javascripts/WikiGrokDialogC.js +++ b/javascripts/WikiGrokDialogC.js @@ -1,5 +1,5 @@ ( function ( M, $ ) { - var WikiGrokDialogB = M.require( 'WikiGrokDialogB' ), + var WikiGrokDialog = M.require( 'WikiGrokDialog' ), wikiGrokRoulette = M.require( 'roulette/wikiGrokRoulette' ), Drawer = M.require( 'Drawer' ), browser = M.require( 'browser' ), @@ -9,13 +9,13 @@ /** * WikiGrok that's fixed at the bottom of the page. * @class WikiGrokDialogC - * @extends WikiGrokDialogB + * @extends WikiGrokDialog */ - WikiGrokDialogC = WikiGrokDialogB.extend( { + WikiGrokDialogC = WikiGrokDialog.extend( { appendToElement: Drawer.prototype.appendToElement, - className: WikiGrokDialogB.prototype.className + ' ' + Drawer.prototype.className, + className: WikiGrokDialog.prototype.className + ' ' + Drawer.prototype.className, version: 'c', - defaults: $.extend( WikiGrokDialogB.prototype.defaults, { + defaults: $.extend( WikiGrokDialog.prototype.defaults, { thanksMsg: 'You just made Wikipedia a little better, thanks! But wait, there is more.', isDrawer: true } ), @@ -98,7 +98,7 @@ // Don't run this when rendering the Badge template if ( !options.beginQuestions ) { options.beginQuestions = true; - WikiGrokDialogB.prototype.postRender.apply( this, arguments ); + WikiGrokDialog.prototype.postRender.apply( this, arguments ); self.askWikidataQuestion( options ); diff --git a/javascripts/init.js b/javascripts/init.js index db92e50..0ffb13b 100644 --- a/javascripts/init.js +++ b/javascripts/init.js @@ -16,11 +16,6 @@ view: 'WikiGrokDialog', name: 'a' }, - B: { - module: 'ext.wikigrok.dialog.b', - view: 'WikiGrokDialogB', - name: 'b' - }, C: { module: 'ext.wikigrok.dialog.c', view: 'WikiGrokDialogC', @@ -28,7 +23,6 @@ } }, versionConfig, - WikiGrokAbTest = M.require( 'WikiGrokAbTest' ), wikiGrokUser = M.require( 'wikiGrokUser' ), wikiGrokVersion = query.wikigrokversion, wikiGrokCampaigns = M.require( 'wikiGrokCampaigns' ), @@ -63,16 +57,13 @@ * If the override version doesn't exist, then the default version * (currently A) will be used. * - * If the user is eligible to enter the WikiGrok AB test, then the test - * determines which version to use. * @method * @ignore * @return {Object|null} */ function getWikiGrokConfig() { var versionOverride, - versionConfig = null, - wikiGrokAbTest = WikiGrokAbTest.newFromMwConfig(); + versionConfig = null; if ( window.location.hash.toLowerCase() === '#wikigrokversion=c' ) { wikiGrokVersion = 'c'; @@ -85,9 +76,6 @@ if ( versionConfigs.hasOwnProperty( versionOverride ) ) { versionConfig = versionConfigs[versionOverride]; } - // Otherwise, see if A/B test is running, and if so, choose a version. - } else if ( wikiGrokAbTest.isEnabled ) { - versionConfig = versionConfigs[wikiGrokAbTest.getVersion( wikiGrokUser )]; } return versionConfig; diff --git a/templates/WikiGrokDialog.hogan b/templates/WikiGrokDialog.hogan index 4780720..ab4b044 100644 --- a/templates/WikiGrokDialog.hogan +++ b/templates/WikiGrokDialog.hogan @@ -1,3 +1,4 @@ +<!-- note English language only! --> <div class="pane content"> <p class="wg-content">{{contentMsg}}</p> <p class="wg-buttons"> @@ -5,9 +6,18 @@ <button class="{{classes}}">{{label}}</button> {{/buttons}} </p> + <p class="tags"> + </p> + {{{spinner}}} {{#noticeMsg}} <p class="wg-notice">{{{noticeMsg}}}</p> {{/noticeMsg}} + + <div class="footer"> + <span class="license">Submissions are <a href="#/wikigrok/about">released freely</a>.</span> + <button class="mw-ui-button save none">None of these</button> + <button class="mw-ui-button mw-ui-constructive save next">Next</button> + </div> </div> {{>error}} diff --git a/templates/WikiGrokDialogB.hogan b/templates/WikiGrokDialogB.hogan deleted file mode 100644 index ab4b044..0000000 --- a/templates/WikiGrokDialogB.hogan +++ /dev/null @@ -1,23 +0,0 @@ -<!-- note English language only! --> -<div class="pane content"> - <p class="wg-content">{{contentMsg}}</p> - <p class="wg-buttons"> - {{#buttons}} - <button class="{{classes}}">{{label}}</button> - {{/buttons}} - </p> - <p class="tags"> - </p> - {{{spinner}}} - {{#noticeMsg}} - <p class="wg-notice">{{{noticeMsg}}}</p> - {{/noticeMsg}} - - <div class="footer"> - <span class="license">Submissions are <a href="#/wikigrok/about">released freely</a>.</span> - <button class="mw-ui-button save none">None of these</button> - <button class="mw-ui-button mw-ui-constructive save next">Next</button> - </div> -</div> - -{{>error}} diff --git a/tests/qunit/test_WikiGrokAbTest.js b/tests/qunit/test_WikiGrokAbTest.js deleted file mode 100644 index a4903fa..0000000 --- a/tests/qunit/test_WikiGrokAbTest.js +++ /dev/null @@ -1,34 +0,0 @@ -( function ( M, $ ) { - - var WikiGrokAbTest = M.require( 'WikiGrokAbTest' ), - wikiGrokUser = M.require( 'wikiGrokUser' ), - enabledTest = new WikiGrokAbTest( true ); - - QUnit.module( 'MobileFrontend: modules/wikigrok/WikiGrokAbTest' ); - - QUnit.test( 'isEnabled simply exposes the isEnabled constructor parameter', 2, function ( assert ) { - assert.strictEqual( new WikiGrokAbTest( false ).isEnabled, false ); - assert.strictEqual( new WikiGrokAbTest( true ).isEnabled, true ); - } ); - - QUnit.test( 'getVersion()', 62, function ( assert ) { - - // A map of expected version to last character of the user's token - var dataProvider = { - A: '0123456789ABCDEFGHIJKLMNOPQRSTU'.split( '' ), - B: 'VWXYZabcdefghijklmnopqrstuvwxyz'.split( '' ) - }; - - this.stub( wikiGrokUser, 'getToken' ); - - $.each( dataProvider, function ( expectedVersion, tokens ) { - $.each( tokens, function ( i, token ) { - wikiGrokUser.getToken.returns( token ); - - assert.strictEqual( enabledTest.getVersion( wikiGrokUser ), expectedVersion ); - } ); - } ); - - } ); - -}( mw.mobileFrontend, jQuery ) ); diff --git a/tests/qunit/test_WikiGrokDialog.js b/tests/qunit/test_WikiGrokDialog.js index 0910bbe..e675dd9 100644 --- a/tests/qunit/test_WikiGrokDialog.js +++ b/tests/qunit/test_WikiGrokDialog.js @@ -3,29 +3,40 @@ var WikiGrokDialog = M.require( 'WikiGrokDialog' ), WikiGrokResponseApi = M.require( 'WikiGrokResponseApi' ), wikiGrokCampaigns = M.require( 'wikiGrokCampaigns' ), - settings = M.require( 'settings' ), campaigns = { - album: { - property: 'P31', + actor: { + property: 'P106', questions: { - Q208569: 'studio album', - Q209939: 'live album' - } + Q10798782: 'television actor', + Q10800557: 'film actor' + }, + name: 'actor', + propertyId: 'P106', + propertyName: 'occupation' } }, suggestions = { - album: { - id: 'P31', - list: [ 'Q208569', 'Q209939' ], - name: 'album' + actor: { + id: 'P106', + list: [ 'Q10798782', 'Q10800557' ], + name: 'actor' } }, - pageTitle = M.getCurrentPage().title || 'Some guy'; + pageTitle = 'Some guy'; - function getPagesWithWikiGrokContributions() { - return $.parseJSON( - settings.get( 'pagesWithWikiGrokContributions', false ) || '{}' - ); + /** + * Debug the wikigrok dialogs by showing it in screen + * active when debug=true in location + */ + function debugDialog() { + if ( + mw.mobileFrontend.query && + Boolean( mw.mobileFrontend.query.debug ) === true + ) { + this.wk.remove = function () { + }; + this.wk.prependTo( '#content' ).show(); + } } QUnit.module( 'MobileFrontend: WikiGrokDialog', { @@ -33,16 +44,14 @@ this.wk.remove(); }, setup: function () { - settings.remove( 'pagesWithWikiGrokContributions', false ); - // don't run eventLogging - this.stub( WikiGrokDialog.prototype, 'log' ); - this.stub( WikiGrokDialog.prototype, 'logError' ); - // show method is async and not needed on tests and will interfere with them trigging a call to logPageImpression - this.stub( WikiGrokDialog.prototype, 'show' ); + this.sandbox.stub( WikiGrokDialog.prototype, 'log' ); + this.sandbox.stub( WikiGrokDialog.prototype, 'logError' ); this.sandbox.stub( mw.config, 'get' ).withArgs( 'wgWikiGrokCampaigns' ) .returns( campaigns ); + this.sandbox.stub( WikiGrokResponseApi.prototype, 'recordClaims' ) + .returns( $.Deferred().resolve() ); this.$el = $( '<div id="test">' ); this.wk = new WikiGrokDialog( { @@ -55,6 +64,7 @@ // Set suggestions to go to the second screen. suggestions: suggestions } ); + debugDialog.apply( this ); } } ); @@ -105,18 +115,6 @@ ); } ); - /** - * Debug the wikigrok dialog by showing it in screen - * Use in tests like: - * debugDialog.apply( this ); - */ - /* - function debugDialog() { - this.wk.remove = function() {}; - this.wk.prependTo( '#content' ).show(); - } - */ - QUnit.test( '#UI renders initial screen', 3, function ( assert ) { // Lets check that we've got the info, buttons and 'Tell me more' assert.ok( this.$el.find( '.wg-content' ).text().length > 0 ); @@ -126,85 +124,86 @@ QUnit.test( '#UI clicking no thanks hides the dialog', 1, function ( assert ) { var spy = this.sandbox.stub( WikiGrokDialog.prototype, 'hide' ); - this.$el.find( '.cancel' ).click(); + this.$el.find( '.cancel' ).trigger( 'click' ); assert.ok( spy.called ); } ); - QUnit.test( '#UI clicking OK, takes you to the question dialog', 1, function ( assert ) { - this.$el.find( '.proceed' ).click(); - // the question title is visible - assert.notEqual( this.$el.text().indexOf( 'Is this a' ), -1, 'Question is visible' ); + QUnit.asyncTest( '#UI clicking OK, takes you to the question dialog', function ( assert ) { + QUnit.expect( 3 ); + this.wk.$el.find( '.proceed' ).trigger( 'click' ); + // The name of the page is on the question + assert.ok( this.wk.$el.text().indexOf( pageTitle ) !== -1 ); + // After loading + setTimeout( $.proxy( function () { + // The question is there + var tags = this.wk.$el.find( '.tags .ui-tag-button' ), + labels = tags.find( 'label' ); + assert.strictEqual( tags.length, 2, 'Correct number of tags' ); + assert.strictEqual( labels.first().text(), + campaigns.actor.propertyName, 'Correct label text' ); + QUnit.start(); + }, this ), 0 ); } ); - function answerQuestion( sel ) { - this.sandbox.stub( WikiGrokResponseApi.prototype, 'recordClaims' ) - .returns( $.Deferred().resolve() ); - this.$el.find( sel ).click(); - } + QUnit.asyncTest( '#UI - Question - Answer correct', function ( assert ) { + QUnit.expect( 1 ); + this.wk.$el.find( '.proceed' ).trigger( 'click' ); + this.$el.find( '.ui-tag-button' ).trigger( 'click' ); + this.$el.find( '.save' ).trigger( 'click' ); - QUnit.test( '#UI - Question - Click Yes', 4, function ( assert ) { - this.$el.find( '.proceed' ).click(); - - 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.' - ); + setTimeout( $.proxy( function () { + // I'm in thanks page now! + assert.notEqual( this.$el.find( '.wg-link' ).css( 'display' ), 'none' ); + QUnit.start(); + }, this ), 0 ); } ); - QUnit.test( '#UI - Question - Click No', 4, function ( assert ) { - this.$el.find( '.proceed' ).click(); + QUnit.asyncTest( '#UI - Question - Answer incorrect', function ( assert ) { + QUnit.expect( 1 ); + this.wk.$el.find( '.proceed' ).trigger( 'click' ); + this.$el.find( '.save' ).trigger( 'click' ); - 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.' - ); + setTimeout( $.proxy( function () { + // I'm in thanks page now! + assert.notEqual( this.$el.find( '.wg-link' ).css( 'display' ), 'none' ); + QUnit.start(); + }, this ), 0 ); } ); - QUnit.test( '#UI - Question - Click Not sure', 4, function ( assert ) { - this.$el.find( '.proceed' ).click(); + QUnit.module( 'MobileFrontend: WikiGrokDialog', { + setup: function () { + this.sandbox.stub( WikiGrokDialog.prototype, 'log' ); + this.logErrorSpy = this.sandbox.stub( WikiGrokDialog.prototype, 'logError' ); - assert.equal( - getPagesWithWikiGrokContributions()[ pageTitle ], - undefined, - 'User\'s contribution to WikiGrok has not been saved locally yet.' - ); + this.sandbox.stub( mw.config, 'get' ).withArgs( 'wgWikiGrokCampaigns' ) + .returns( campaigns ); + this.sandbox.stub( WikiGrokResponseApi.prototype, 'recordClaims' ) + .returns( $.Deferred().reject() ); - answerQuestion.call( this, '.not-sure' ); + this.$el = $( '<div id="test">' ); + this.wk = new WikiGrokDialog( { + el: this.$el, + campaign: wikiGrokCampaigns.getRandomCampaign(), + itemId: '1234', + title: pageTitle, + userToken: 'token', + testing: false + } ); + } + } ); - // 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.asyncTest( '#Handle error', function ( assert ) { + QUnit.expect( 1 ); + var spy = this.sandbox.stub( WikiGrokDialog.prototype, 'handleError' ); + this.wk.reveal( {} ); + this.wk.$el.find( '.proceed' ).trigger( 'click' ); + QUnit.start(); + // After loading + setTimeout( $.proxy( function () { + // save should thrown an error because of recordClaims + this.wk.$el.find( '.save' ).trigger( 'click' ); + assert.ok( spy.called, 'Error is handled.' ); + }, this ), 0 ); } ); }( jQuery, mw.mobileFrontend ) ); diff --git a/tests/qunit/test_WikiGrokDialogB.js b/tests/qunit/test_WikiGrokDialogB.js deleted file mode 100644 index 9b0cc4b..0000000 --- a/tests/qunit/test_WikiGrokDialogB.js +++ /dev/null @@ -1,162 +0,0 @@ -( function ( $, M ) { - - var WikiGrokDialogB = M.require( 'WikiGrokDialogB' ), - WikiGrokResponseApi = M.require( 'WikiGrokResponseApi' ), - wikiGrokCampaigns = M.require( 'wikiGrokCampaigns' ), - campaigns = { - actor: { - property: 'P106', - questions: { - Q10798782: 'television actor', - Q10800557: 'film actor' - }, - name: 'actor', - propertyId: 'P106', - propertyName: 'occupation' - } - }, - suggestions = { - actor: { - id: 'P106', - list: [ 'Q10798782', 'Q10800557' ], - name: 'actor' - } - }, - pageTitle = 'Some guy'; - - /** - * Debug the wikigrok dialogs by showing it in screen - * active when debug=true in location - */ - function debugDialog() { - if ( - mw.mobileFrontend.query && - Boolean( mw.mobileFrontend.query.debug ) === true - ) { - this.wk.remove = function () { - }; - this.wk.prependTo( '#content' ).show(); - } - } - - QUnit.module( 'MobileFrontend: WikiGrokDialogB', { - teardown: function () { - this.wk.remove(); - }, - setup: function () { - // don't run eventLogging - this.sandbox.stub( WikiGrokDialogB.prototype, 'log' ); - this.sandbox.stub( WikiGrokDialogB.prototype, 'logError' ); - - this.sandbox.stub( mw.config, 'get' ).withArgs( 'wgWikiGrokCampaigns' ) - .returns( campaigns ); - this.sandbox.stub( WikiGrokResponseApi.prototype, 'recordClaims' ) - .returns( $.Deferred().resolve() ); - - this.$el = $( '<div id="test">' ); - this.wk = new WikiGrokDialogB( { - el: this.$el, - campaign: wikiGrokCampaigns.getRandomCampaign(), - itemId: '1234', - title: pageTitle, - userToken: 'token', - testing: false, - // Set suggestions to go to the second screen. - suggestions: suggestions - } ); - debugDialog.apply( this ); - } - } ); - - QUnit.test( '#UI renders initial screen', 3, function ( assert ) { - // Lets check that we've got the info, buttons and 'Tell me more' - assert.ok( this.$el.find( '.wg-content' ).text().length > 0 ); - assert.strictEqual( this.$el.find( '.wg-buttons button' ).length, 2 ); - assert.ok( this.$el.find( '.wg-notice>a' ).attr( 'href' ).length > 0 ); - } ); - - QUnit.test( '#UI clicking no thanks hides the dialog', 1, function ( assert ) { - var spy = this.sandbox.stub( WikiGrokDialogB.prototype, 'hide' ); - this.$el.find( '.cancel' ).trigger( 'click' ); - assert.ok( spy.called ); - } ); - - QUnit.asyncTest( '#UI clicking OK, takes you to the question dialog', function ( assert ) { - QUnit.expect( 3 ); - this.wk.$el.find( '.proceed' ).trigger( 'click' ); - // The name of the page is on the question - assert.ok( this.wk.$el.text().indexOf( pageTitle ) !== -1 ); - // After loading - setTimeout( $.proxy( function () { - // The question is there - var tags = this.wk.$el.find( '.tags .ui-tag-button' ), - labels = tags.find( 'label' ); - assert.strictEqual( tags.length, 2, 'Correct number of tags' ); - assert.strictEqual( labels.first().text(), - campaigns.actor.propertyName, 'Correct label text' ); - QUnit.start(); - }, this ), 0 ); - } ); - - QUnit.asyncTest( '#UI - Question - Answer correct', function ( assert ) { - QUnit.expect( 1 ); - this.wk.$el.find( '.proceed' ).trigger( 'click' ); - this.$el.find( '.ui-tag-button' ).trigger( 'click' ); - this.$el.find( '.save' ).trigger( 'click' ); - - setTimeout( $.proxy( function () { - // I'm in thanks page now! - assert.notEqual( this.$el.find( '.wg-link' ).css( 'display' ), 'none' ); - QUnit.start(); - }, this ), 0 ); - } ); - - QUnit.asyncTest( '#UI - Question - Answer incorrect', function ( assert ) { - QUnit.expect( 1 ); - this.wk.$el.find( '.proceed' ).trigger( 'click' ); - this.$el.find( '.save' ).trigger( 'click' ); - - setTimeout( $.proxy( function () { - // I'm in thanks page now! - assert.notEqual( this.$el.find( '.wg-link' ).css( 'display' ), 'none' ); - QUnit.start(); - }, this ), 0 ); - } ); - - QUnit.module( 'MobileFrontend: WikiGrokDialogB', { - setup: function () { - this.sandbox.stub( WikiGrokDialogB.prototype, 'log' ); - this.logErrorSpy = this.sandbox.stub( WikiGrokDialogB.prototype, 'logError' ); - - this.sandbox.stub( mw.config, 'get' ).withArgs( 'wgWikiGrokCampaigns' ) - .returns( campaigns ); - this.sandbox.stub( WikiGrokResponseApi.prototype, 'recordClaims' ) - .returns( $.Deferred().reject() ); - - this.$el = $( '<div id="test">' ); - this.wk = new WikiGrokDialogB( { - el: this.$el, - campaign: wikiGrokCampaigns.getRandomCampaign(), - itemId: '1234', - title: pageTitle, - userToken: 'token', - testing: false - } ); - } - } ); - - QUnit.asyncTest( '#Handle error', function ( assert ) { - QUnit.expect( 1 ); - var spy = this.sandbox.stub( WikiGrokDialogB.prototype, 'handleError' ); - this.wk.reveal( {} ); - this.wk.$el.find( '.proceed' ).trigger( 'click' ); - QUnit.start(); - // After loading - setTimeout( $.proxy( function () { - // save should thrown an error because of recordClaims - this.wk.$el.find( '.save' ).trigger( 'click' ); - assert.ok( spy.called, 'Error is handled.' ); - }, this ), 0 ); - } ); - -}( jQuery, mw.mobileFrontend ) ); -- To view, visit https://gerrit.wikimedia.org/r/191358 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iec3921cddfe6fc026b5757eb338efc44232bbf7a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikiGrok Gerrit-Branch: master Gerrit-Owner: Phuedx <g...@samsmith.io> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits