Commit graph

551 commits

Author SHA1 Message Date
joakin f3839189dc Test: Migrate isEnabled.test.js to node-qunit
Change-Id: I85a08725c9138f47a51cdc34c20bc3a60b61af34
2017-02-20 20:01:01 +01:00
joakin c233ffb4a5 Test: Migrate preview/model.test.js to node-qunit
Change-Id: Ie5a895a1760dbfc58e11369fdb8b979021b8ae74
2017-02-20 20:01:01 +01:00
joakin b7a4029adb Test: Migrate reducers/eventLogging.test.js to node-qunit
Change-Id: I4bc6d77a496a8c4bf1ecafbf3a6a71986c77e423
2017-02-20 20:01:01 +01:00
joakin d06bbe5871 Test: Migrate reducers/preview.test.js to node-qunit
Change-Id: I700bc43dace64503058337a6b458673070bc5db0
2017-02-20 20:01:01 +01:00
joakin 33c05394f4 Set up qunit running in node to migrate tests to commonjs
In order to run qunit tests on sources that use common.js modules, set
up infra to run qunit tests in the node cli when running:

    npm run test:node

Changes:
* Add npm script test:node that runs the tests
* Run node tests on CI (npm test)
* Add a qunit node test runner: mw-node-qunit
* Migrate a test from the root hierarchy and another one from the nested
  one to prove it works (globs fail otherwise)
  * reducers/settings.test.js to node qunit to prove it works
  * counts.test.js to node qunit to prove it works

Change-Id: I55d76b7db168f3745e0ac69852c152322ab385c3
2017-02-20 20:01:01 +01:00
jenkins-bot ade818e89e Merge "Resize thumbnails images returned by REST endpoint" 2017-02-17 00:30:28 +00:00
jdlrobson 6d859a73a3 Resize thumbnails images returned by REST endpoint
This change resizes thumbnails to the appropriate width
based on the value of mw.popups.gateway.THUMBNAIL_SIZE

Tests cover
* When requested thumbnail is < than original size
* When requested thumbnail is > than original size
* When requested thumbnail is an svg and originalimage
smaller than requested thumb size

Bug: T156800
Change-Id: Ib375b97e2bc959e91de5177efc3df1f2ded54a5b
2017-02-16 16:19:14 -08:00
Piotr Miazga 2988a6e620 Hygiene: Move Popups.hooks into includes folder
Lets keep all extenion PHP files in one folder

Change-Id: I225019b895df038c1d43a082ac4244053d0b96dd
2017-02-14 21:04:49 +01:00
jenkins-bot fa0426e008 Merge "Hygiene: Rename isEnabledByUser to shouldSendModuleToUser" into mpga 2017-02-10 18:57:27 +00:00
jenkins-bot 9e3ad908c7 Merge "Only add Popups code to output page where needed" into mpga 2017-02-10 18:55:09 +00:00
jdlrobson 64e7bfd620 Hygiene: Rename isEnabledByUser to shouldSendModuleToUser
Sometimes we make choices on the users behalf if we don't have
sufficient information, so this name is more applicable.

If beta features is disabled and the user is anon they have not
explicitly opted in.

Change-Id: I5d816f569fc54f8bf74d6e5a06246b7fa7036e06
2017-02-10 10:07:28 -08:00
jdlrobson 4e2ce1ce39 Only add Popups code to output page where needed
If the Popups code is enabled in beta feature mode only then
only add it to the page if the beta feature is enabled.

isEnabledByUser now returns false if the user is anonymous
and Popups is restricted to beta mode.

Bug: T156290
Change-Id: If152d2a67a079050173c6d642e0960b59730bc6d
2017-02-09 10:43:53 -08:00
jenkins-bot cd9451e538 Merge "Hygiene: Split and organize the gateways" into mpga 2017-02-08 21:20:18 +00:00
jenkins-bot d7b5f56665 Merge "Hygiene: Use factory functions instead of classes" into mpga 2017-02-08 19:38:53 +00:00
joakin 955189230a Hygiene: Split and organize the gateways
* Create new namespace mw.popups.gateway to contain them
* Create folder resources/ext.popups/gateway/
* Split gateway{,.test}.js into gateway/{mediawiki,rest}{.test,}.js
* Extract stateless functions out of factory scope now that there are no
  name collisions between the factories.

Bug: T123445
Change-Id: Ib256871c3e4cfe3f13361cb66d4e9a67e9823c7b
2017-02-08 18:58:46 +01:00
joakin 557fd113c8 Hygiene: Use factory functions instead of classes
Instead of using constructor functions, use factory functions to
generate the gateway objects, because of:

* Consistency on the approach in the repository, no constructor
  functions are used, the factory function pattern prevales.
* Real private data with closures
* No use of `this`, which is dynamic and unbound in JS and a source of
  errors. In contrast, by using a factory function, the
  function/methods-of-the-object are tightly bound to the internal data.

Additional changes:
* Specify more the type of createRESTBaseGateway's parameter to improve
clarity on the intent of the parameter
  * From: @param {jQuery} api
  * To:   @param {Function} ajax function from jQuery for example

Supporting documentation:
* https://medium.com/javascript-scene/javascript-factory-functions-vs-constructor-functions-vs-classes-2f22ceddf33e

Change-Id: Iacbb098b646843a01f459b15343057e2e4851d35
2017-02-08 18:28:21 +01:00
jenkins-bot bc7ae795c3 Merge "Add support for RESTBase endpoint consumption" into mpga 2017-02-07 18:48:18 +00:00
Baha 9764f7fe64 Add support for RESTBase endpoint consumption
* Introduce the new config variable `PopupsAPIUseRESTBase`.
* Create a gateway interface that exposes the getPageSummary
  method. Both MediaWiki API gateway and RESTBase gateway
  implement this interface.

Bug: T123445
Change-Id: I71a8a848f3143fa4a0dfd4ca182ee086903110bc
2017-02-07 12:36:11 -05:00
Sam Smith 75aaf7a23e Don't log editCountBucket when user is logged out
Bug: T156893
Change-Id: I3cdfbe0c9872407b900f0676396b0bc3102a43fd
2017-02-06 11:58:18 +00:00
jdlrobson eea509637a Remove unused code in repo
The existence of these files was causing me much confusion as I thought
they were still being used in the mpga branch.

If this is note the case they should be removed to make the repo easier
to understand.

Changes:
* Move the ext.popups.animation.less into ext.popups since that's where
its shipped.
* Remove files which are not being used.
* Since csslint now runs on ext.popups.animation.less fix the linting
issues (previously linting was not occuring)

Change-Id: Iae0a78d0b8a13353de70794b67387f2c3bab44c6
2017-02-02 16:18:41 -08:00
Sam Smith ab75283392 model: extract -> page
In I6bbff6a5 a preview was assigned the "extract" type if it had an
extract whereas it should've been assigned the "page" type.

Bug: T152004
Change-Id: I5e0cdc8f528647f1e20873753be29c6b85b3a384
2017-02-02 17:06:46 +00:00
jdlrobson 09ccfa9a13 Remove last modified line
Note this is a breaking change in the sense that it breaks the function
signature for createModel which no longer needs to be passed the last
modified time. Given this change is in the mpga branch at current time
and hasnt been exposed for public use I have deemed this okay.

The change removes tests relating to the last modified bar, removes
lines in the templates and updates existing tests and code to reflect
the new function signature for create model.

Settings icon is floated to right which will be flipped for RTL
users.

Bug: T137775
Change-Id: I7737e37d956c62f1f1c0694d7a25a58d91651f4d
2017-02-02 11:28:11 +00:00
Sam Smith 2d42471ccd reducers: Add preview type to interaction state
The preview model is included in the FETCH_END action so, when reducing
that action, pluck the preview type from the model and add it to the
interaction state.

Change-Id: I0e51a85b4dada8f9a17ec4882e0c13b2c4382d24
2017-01-30 10:05:17 +00:00
Sam Smith 44c6d3d9b9 Add type to preview model
Per T152004, if the preview has an empty extract, then it's a "generic"
preview; it's an "extract" preview otherwise.

Bug: T152004
Change-Id: I6bbff6a507fe3e4f03b3a44f64d875e7dbb512df
2017-01-30 08:29:29 +00:00
Sam Smith 7ce7423639 Make gateway use preview model
Following on from I20f29657, simplify the gateway by making it return
instances ofext.popups.PreviewModel.

Supporting changes:
* data -> model in mw.popups.renderer#render and the
  create{,Empty}Preview helper functions.

Bug: T152004
Change-Id: I531f609056ae813ae5e6b1d53010d77be0799ec1
2017-01-30 08:29:24 +00:00
Sam Smith 622f2af318 gateway: Don't create new object for thumbnail
As noted in the review of I71a8a84, creating a new object to represent
the thumbnail is confusing. It's also somewhat wasteful.

Since both the MediaWiki API and RESTBase both agree on using "source"
as the key for the thumbnail's URL, it's reasonable to use it in the
gateway and renderer.

Bug: T152004
Change-Id: Ie1346d13b6e88004b817f5968448188ed83cfda4
2017-01-27 14:22:54 +00:00
Sam Smith e3ae38f966 Introduce preview model
After the gateway has made a request, it processes the page. This
processing both mangles and processes the MediaWiki API response. The
latter step contains two pieces of related business logic:

1. Deciding if a page has been modified recently.
2. Processing the extract/deciding if it's viable (see processExtract).

In order to support switching between the MediaWiki API and RESTBase and
to simplify the event logging reducer when it comes to instrumenting the
"type" of preview, extract this business logic into a model.

Bug: T152004
Change-Id: I20f29657fcf94101a71ed13c0920508db71292ce
2017-01-27 14:15:37 +00:00
Sam Smith 6cc6252704 Add hovercardsSuppressedByGadget to logging
I4c15296e introduced the wgPopupsConflictsWithNavPopupGadget client-side
config variable, an always-available flag that represents whether the
user has enabled the NavPopups gadget. This property has been missing
from the Popups instrumentation since I8a3f5835.

Changes:
* Add the value of wgPopupsConflictsWithNavPopupGadget to BOOT action
  and reduce it into the base instrumentation data.

Bug: T151058
Change-Id: I09924d0cb10e96b0a846940506ebfeaa7086cd17
2017-01-25 14:21:34 +00:00
Piotr Miazga 84abecab2b Pass conflictsWithNavPopupsGadget to js client
Changes:
 - Pass conflictsWithNavPopupsGadget to JS via GlobalVariablesScript hook

Bug: T151058
Change-Id: I4c15296e2fa3d411561be0ef1f914c7cc9beccd2
2017-01-23 23:03:14 +01:00
Sam Smith 51c6f2c8e5 Hygiene: Make settings reducer control footer link
Since the footer link part of the settings system - clicking the link
opens the settings modal - it seems appropriate that it should be
controlled by state managed by the settings reducer.

Bug: T146889
Change-Id: I3a8549dbf1952cd0556f663496c55de91acaf2c0
2017-01-17 06:40:36 -08:00
Sam Smith c51b33c8b7 Send blob to everyone
As before, we need to send the Page Previews blob that logged out users
can enable/disable previews.

Changes:
* Unconditionally add the ext.popups RL module to the output.
* Send the value of Popups\PopupsContext#isEnabledByUser to the client
  as $wgPopupsIsEnabledByUser.
* Make mw.popups#isEnabled return $wgPopupsIsEnabledByUser if the user
  is logged in.

Bug: T146889
Change-Id: Id2ccfaa81a327e222fff400f4a5f22f96c99ea31
2017-01-17 06:40:24 -08:00
Sam Smith c6a502954d Vary cog click behavior
The behavior of the cog varies when:

* The user is logged in/out.
* Page Previews is enabled as a beta feature.

Since the behavior of the cog doesn't vary per-preview, it can be
determined at boot time and passed to the renderer. However, in order to
keep the renderer stateless, we pass the behavior to it when a preview
is added to the DOM.

Changes:
* Add the mw.popups.createPreviewBehavior factory function, which
  returns an object that encapsulates how a preview responds to the user
  dwelling on it, abandoning it, and clicking on the cog.
* Invoke mw.popups.createPreviewBehavior at boot time and pass it to the
  mw.popups.changeListeners.render change listener, which then passes it
  to mw.popups.Preview#show.
* Make mw.popups.Preview#show responsible for binding event handlers
  and configuring the cog based on the behavior.

Bug: T146889
Change-Id: I39d7d0afd7b1fe896019a1b3a82ee907bfb20edd
2017-01-15 16:20:22 -08:00
jenkins-bot cc35a016b3 Merge "Forward PopupsBetaFeature to the client" into mpga 2017-01-15 23:54:21 +00:00
jenkins-bot 1b7283a301 Merge "Hygiene: Rename SchemaPopupsSamplingRate" into mpga 2017-01-15 23:38:53 +00:00
jenkins-bot e1b71f5d3f Merge "actions: Merge LINK_ABANDON_* + PREVIEW_ABANDON_*" into mpga 2017-01-15 23:28:23 +00:00
jenkins-bot 5020424fbb Merge "Hygiene: Remove link element from LINK_ABANDON_*" into mpga 2017-01-15 23:24:18 +00:00
Sam Smith dfccc55bb5 Forward PopupsBetaFeature to the client
Bug: T146889
Change-Id: I66739b01e405bd7be29e912388005e0bb1f25b3f
2017-01-15 11:04:44 -08:00
Sam Smith 98b2dcf631 Hygiene: Rename SchemaPopupsSamplingRate
The SchemaPopupsSamplingRate config variable is inconsistently named and
even forwarded to the client as wgPopupsSchemaPopupsSamplingRate.

Changes:
* SchemaPopupsSamplingRate -> PopupsSchemaSamplingRate
* Forward PopupsSchemaSamplingRate to the client as
  $wgPopupsSchemaSamplingRate.

Bug: T146889
Bug: T146434
Change-Id: I80d6a0abccf462e2eb0fd96af6849b5e82b49c26
2017-01-15 11:01:00 -08:00
Sam Smith 787660f956 actions: Merge LINK_ABANDON_* + PREVIEW_ABANDON_*
Per Id1339dc2, the LINK_ABANDON_* and PREVIEW_ABANDON_* actions can (and
should) be merged, as they are always reduced in the same way.

Change-Id: I71b30d4d2774deb4efea9e565f2ccd7383bf08c1
2017-01-15 09:55:36 -08:00
Piotr Miazga c13ab30bfa Move conflicting NavPopups gadget name into config var
Changes:
 - removed hardcoded comflicting Navigation Popups gadget name
 - introduced a config variable to specify conflicting gadget name

Bug: T151058
Change-Id: Ief5c6f90ec6dd6c074931f7d9ff20297d4718fe5
2017-01-12 18:07:20 +01:00
Sam Smith 49ce7643f0 Hygiene: Remove link element from LINK_ABANDON_*
Initially, the link element was added to LINK_ABANDON_* to determine
when an interaction should be reset. However, this wasn't enough to
protect against timing-related bugs, e.g. T154923. Now that tokens are
used to determine when interactions should be reset, the link element
can safely be removed from the LINK_ABANON_* actions.

Supporting changes:
* Update the return type of mw.popups.actions.linkAbandon in its
  DocBlock.

Change-Id: Iaaed7a4846af75f9c4051d7bc761022ea5b3f6cf
2017-01-11 14:33:46 -08:00
jenkins-bot 4d0f0a489a Merge "Disable Page Previews preferences when NavPopups are enabled" into mpga 2017-01-11 15:39:36 +00:00
jenkins-bot a57a0a321d Merge "Fix linkTitleChangeListener" into mpga 2017-01-11 04:27:30 +00:00
Sam Smith e17e209003 Fix linkTitleChangeListener
I2ecf575b introduced a regression where the linkTitleChangeListener
wouldn't destroy the active link's title if it had been dwelled on
within 300 ms of the previous active link being abandoned.

The LINK_ABANDON_END action is dispatched after 300 ms and ignored if
the active link has changed.

Change-Id: If0c16afd6ca1c44f0e7eed497f62f0190005a619
2017-01-10 18:03:47 -08:00
joakin 21230742c0 Change preview to check *_ABANDON_END with tokens
... instead of using the active elements, and check also the user
dwelling flag to only act if the user is not dwelling.

Preview and link abandon end and start share now test cases, meaning it
can be collapsed into one action creator in a followup commit.

Change-Id: Id1339dc23e8f1b1b7514c769cd09f8bdadc759b4
2017-01-10 17:52:53 -08:00
joakin e49103061e Don't reset interaction info when dwelling back to a link
When dwelling back to a link, previously a new LINK_DWELL action would
be sent and the reducer would reset the interaction as if it was a new
one.

This shouldn't happen, since dwelling back to the active link (from
the preview, for example) is not a new interaction, and should not
create a new interaction or hide and show the preview.

With this change, the preview reducer has the notion of new or repeat
interactions, and only resets state on new ones, and only sets
isUserDwelling when dwelling on a the link of the current interaction.

Also when the interaction is repeat, we guard on the action creator and
don't trigger the wait or the fetch request.

Change-Id: I71cde81cbfe50b6f955e562e7e5b57d0f920fdb9
2017-01-10 17:44:37 -08:00
joakin 36518b1215 Don't hide preview when user dwells on link
... after dwelling on preview.

Currently, the asynchronous PREVIEW_ABANDON_END action wouldn't be
ignored if the user were to have dwelled on the link that the preview is
about. The action is only ignored if the user is dwelling on the
preview, i.e. if preview.isUserDwelling is truthy.

Set preview.isUserDwelling to truthy if the user is dwelling either on
the link or on the preview.

Bug: T154923
Change-Id: I8e6989790da5884992ee9dda9e4895e2e58e6694
2017-01-10 17:43:55 -08:00
Sam Smith af05386ea4 actions: Add token to PREVIEW_ABANDON_**
Change-Id: Ic84aa0c3144761b93beff9b7b82932647e504a5b
2017-01-10 16:47:19 -08:00
Sam Smith 489f1e69f2 Run previewAbandon action creator tests
Unfortunately, QUnit doesn't complain that QUnit#module was being called
with a function and not an object.

Change-Id: I6d3b4941566fa4e4ecad2dbe6f7b5fdd62cdaf72
2017-01-10 16:47:11 -08:00
Piotr Miazga 211f1d1658 Disable Page Previews preferences when NavPopups are enabled
Changes:
 - introduced PopupsGadgetsIntegration class handles all checks
 - show help message on Preferences page when NavPopups is enabled
 - unit test everything

Bug: T151058
Change-Id: Ia474b1b30378efe84dedf3ad47c1f833e88d69b5
2017-01-11 01:06:48 +01:00
jenkins-bot 064437d7f7 Merge "actions: Conditionally dispatch LINK_DWELL" into mpga 2017-01-10 19:52:42 +00:00
jenkins-bot f3618e78bd Merge "actions: Add token to LINK_ABANDON_*" into mpga 2017-01-10 19:38:11 +00:00
jenkins-bot 66d325cad7 Merge "reducers: Store interaction tokens" into mpga 2017-01-10 19:37:28 +00:00
jenkins-bot 5ad4edf53d Merge "Hygiene: interactionToken -> token" into mpga 2017-01-10 19:34:52 +00:00
jenkins-bot fc2b055934 Merge "Hygiene: use UserGetDefaultOptions instead of ExtensionRegistration" into mpga 2017-01-10 18:53:45 +00:00
Sam Smith df0f175d72 actions: Conditionally dispatch LINK_DWELL
Change-Id: I9046296f061677674f9ad991ec6dacd1dd9db65c
2017-01-10 10:12:03 -08:00
Sam Smith 4d736b9a78 actions: Add token to LINK_ABANDON_*
Change-Id: I7f6187f6c0249c112a08163a343d35ee75cf85e8
2017-01-10 09:50:58 -08:00
Sam Smith 46cd38849e reducers: Store interaction tokens
Consider the user repeatedly dwelling on and abandoning a link. Testing
whether or not the element has changed before modifying state is not
sufficient. Fortunately, we already generate a unique token and include
it in the LINK_DWELL action for use in the eventLogging reducer - the
so-called "interaction token".

Change-Id: Iae9544055f7eccb4f7f071797eb360bc3456861a
2017-01-10 09:50:58 -08:00
Sam Smith f26768afe8 Hygiene: interactionToken -> token
... for brevity.

Change-Id: I03626728fae36176cec0eb844efb92303377bfbf
2017-01-10 09:50:57 -08:00
jenkins-bot b081b0aa0a Merge "Consistently delay showing previews" into mpga 2017-01-10 17:42:47 +00:00
Piotr Miazga 05eccb31c1 Hygiene: use UserGetDefaultOptions instead of ExtensionRegistration
Changes:
 - removed onExtensionRegistration and related TODOs
 - introduced onUserGetDefaultOptions hook

Change-Id: I6648802c19d90df36a211d6494033aca30c078ca
2017-01-10 18:34:43 +01:00
jenkins-bot b7348f4036 Merge "Fix checkin tests to use fake timers" into mpga 2017-01-10 17:34:35 +00:00
joakin 84043e86f9 Fix checkin tests to use fake timers
* To speed the time the tests spend running
* To make them reliably execute and not depend on magic numbers

Additional changes:
* Use mw.now instead of Date on checkin.js
* Split big setVisibleTimeout test into several smaller ones
  * Extract helpers for the tests

Change-Id: I9d3233fccf6de0997f968d096e375df996e87786
2017-01-10 09:31:32 -08:00
Sam Smith cbdcf7d353 Consistently delay showing previews
While I1bf953b2 fixed the typo in FETCH_START_DELAY, it didn't do
anything to address the inconsistency in the time it takes to render a
preview (preview delay).

If the gateway result resolves before the target preview delay (500 ms)
is met, then delay dispatching the FETCH_END action until it is. If,
however, the gateway result resolves after the target preview delay,
then dispatch the FETCH_END action immediately.

Supporting changes:
* Expose the fetch action to ease testing it and to help tidy up the
  mw.popups.actions.linkDwell tests.

Change-Id: Idf02343a0417cfbb33093a81d97ecebc5c1c7379
2017-01-09 15:00:02 -08:00
joakin 014d442974 Preview actions+reducer qunit integration tests
Initial approach booting reducers and using actions to manipulate the
state.

Change-Id: I0dba4b2186dd2e092df80fe1806dd320bb829914
2017-01-09 11:53:07 -08:00
jenkins-bot 7f25a8ce1a Merge "Hygiene: Avoid touching internal state in tests" into mpga 2017-01-04 15:56:28 +00:00
Sam Smith 60adbd0831 Hygiene: Avoid touching internal state in tests
Test what mw.popups.haveCheckinActionsBeenSetup guards against so that
it doesn't have to be touched during the associated test.

Bug: T147314
Change-Id: I315e0782a0e3b1d04878f1ee6f538e54531f7df5
2017-01-04 11:13:34 +00:00
jenkins-bot 605118aa41 Merge "Add reading depth" into mpga 2017-01-04 11:03:01 +00:00
Baha 4afa1958a0 Add reading depth
Use schema revision 16163887.

Add the 'checkin' action, which is accompanied by the 'checkin'
property. The action is logged at the following seconds
(Fibonacci numbers) after the page loads: 1, 2, 3, 5, 8, 13, 21,
34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765.
The `checkin` property contains the values listed above.

Bug: T147314
Change-Id: Ib9ec7bd0e60aa34a04e32222b025347f6ee31794
2016-12-21 15:08:20 -05:00
Piotr Miazga c3cfcbe0e0 Inject preference option directly after skin select
Per #Design's mocks, the "Reading preferences" section should appear
immediately beneath the Skin section, if it's present.

Changes:
 - onGetPreferences will try to inject PagePreviews option after
skin section or on the end of section when skin select is not available
 - unit tests for new behaviour

Bug: T146889
Change-Id: Id14c0774aee917b7e949ab3ba5968a038b3ca933
2016-12-21 16:53:33 +00:00
Piotr Miazga c587a9785b Hygiene: Improve code quality by reaching 100% coverage
Changes:
 - added missing unit tests
 - introduced PopupsContextTestWrapper, removed all unit-tests logic
   from Hooks/Context classes
 - removed getModule() from Popups.hooks.php, it's hooks responsibility
   to keep single context instance
 - removed class_exists calls, use ExtensionRegistry instead
 - pass ExtensionRegistry as a dependency so it's easy to mock
 - reach 100% code coverage
 - introduce PoupsContext::isBetaOn() as it was used in many places

Change-Id: Id014efe72edf24628539c76968e53eb3e06709f4
2016-12-21 16:03:33 +01:00
Piotr Miazga 147772bbd8 ext.popups module should be loaded for anon users
Bug: T146889
Change-Id: I11dc6208334daa556d376f04aeb099a2642fcec0
2016-12-21 10:38:36 +00:00
Piotr Miazga 959bf40d9b Implement necessary wiring for preferences
Changes:
 - introduce unit tests
 - don't send module for anonymous users
 - renamed Module to Context
 - remove Config dependency from Popups.hooks.php

Bug: T146889
Change-Id: I3cbcdc1303411b28b613afa6dd1a00b410891471
2016-12-20 16:54:33 +01:00
jenkins-bot 397d3e8bc2 Merge "Hygiene: Make mw.popups#isEnabled return boolean" into mpga 2016-12-16 19:48:10 +00:00
jenkins-bot 7e64a87d7f Merge "Hygiene: Remove experiment-related code" into mpga 2016-12-16 19:48:09 +00:00
jenkins-bot 4fe1cd9f69 Merge "Redefine when Page Previews are enabled" into mpga 2016-12-16 19:48:08 +00:00
Sam Smith b2bd1ebdf7 Hygiene: Make mw.popups#isEnabled return boolean
Action changes:
* Update the BOOT action to include isEnabled and update the associated
  tests.

Reducer changes:
* Make the preview and eventLogging reducers handle the BOOT action's
  new shape.

Bug: T152687
Change-Id: I3fa2098269a32912eda99ceb8f13887688a14c15
2016-12-16 10:59:47 +00:00
Sam Smith 6bd082920f Hygiene: Remove experiment-related code
Changes:
* Remove $wgPopupsExperiment and $wgPopupsExperimentConfig config
  variables.
* Remove $wgPopupsExperimentIsBetaFeatureEnabled client-side config
  variable.
* Remove MakeGlobalVariablesScript hook handler as it's redundant.

Bug: T152687
Change-Id: Id25cd7c16da14b7ce9bad502565de9ff6d29434e
2016-12-16 10:59:47 +00:00
Sam Smith a6423fbc75 Redefine when Page Previews are enabled
The Page Previews A/B test was disabled in T144490. After the changes
for that task had been deployed we discovered that the old definition
for when previews are enabled was invalid.

Previews are enabled:
* If the beta feature is enabled and the user has enabled the beta
  feature.
* The user hasn't disabled previews via the settings modal.
* And soon, if the beta feature is disabled and the user hasn't disabled
  previews via their user preferences (see T146889).

Changes:
* mw.popups#createExperiment -> mw.popups#isEnabled
* Make mw.popups#isEnabled act like a factory to maintain backwards
  compatibility.
* Update the associated tests.

Bug: T152687
Change-Id: I713a90dfb29866b27738e7d19e8a22518a12d417
2016-12-16 10:35:55 +00:00
joakin 212dcf1d55 Update the settings enabled radio with the enabled state
When opening the settings dialog, the form didn't represent the current
enabled status of the application. This change makes sure that every
time the form is shown, the form state represents the current
application state.

If the application is enabled, then the 'simple' (Enabled) option is
selected on the form. If it is disabled then if there's Navigation
popups, it selects 'advanced' (Advanced popups), if there are not, it
selects 'off' (Disabled).

Changes:
* Change listeners
  * Set the form state every time the form is going to be shown
    * Update tests
* Supporting changes
  * Add settingsDialog#setEnabled which updates the DOM form based on the
    enabled flag and the navpops state
  * Extract isNavPopupsEnabled function in settingsDialog.js to be used in the
    form creation and also when setting the form enabled state
  * Add test verifying changeListeners#settings shows and sets enabled state
    properly when showing the dialog more than one time

Change-Id: Ic660f48d9a78e47c09a192ab86681196d2e01d61
2016-12-16 10:29:34 +00:00
joakin 8631a183de Sync enabled preview state to storage on change
Changes:
* Generalized previewCount change listener to syncUserSettings
* Added state.preview.enabled to be saved on change

Change-Id: I403a490fee9c8e125175996ba30c63c232b5598b
2016-12-16 10:27:24 +00:00
jenkins-bot cacce7b03c Merge "Introduce Opt-In option on user preferences page" into mpga 2016-12-16 00:11:55 +00:00
Piotr Miazga f597e341af Introduce Opt-In option on user preferences page
This changes introduces new option on Special:Preferences page that
allows users to enable/disable Page Previews feature.
By default feature is disabled. Temporarily option in Preferences
page is smoke and mirrors as switching logic is still WIP.

Bug: T146889
Change-Id: Ifdd17ce265d2d4c7583433ed4991443c563f1fe3
2016-12-16 01:06:59 +01:00
joakin efb7b3d872 Wire up saving enabled/disabled in settings dialog
The save action has been implemented, and it is listened to by the
canonical enabled state in the previews reducer, and by the settings
reducer to perform UI changes.

The enabled state of the application has been kept in the preview
reducer as the canonical source of truth. See supporting changes for
documentation about the decision.

Actions:
* Introduce new action SETTINGS_CHANGE with the enabled status
* Trigger that action when clicking Save in the settings dialog

Reducers:
* Listen to SETTINGS_CHANGE in the preview reducer to update enabled
  status
* On the settings reducer
  * Handle the SETTINGS_CHANGE action
  * Add showHelp flag to determine if the help should be showing

Change listeners:
* Switch to compare past vs present changes in the implementation
* Handle showing and hiding the help

Supporting changes:
* On the rendered settings dialog:
  * Change #hide to actually just hide and remove legacy if statement
  * Add #toggleHelp method to show or hide the help dialog
* Add doc/adr/0003-keep-enabled-state-only-in-preview-reducer.md to
  support the decision of making the saveSettings action creator return
  a Redux.Thunk and keeping the enabled state just in the preview
  reducer.
  * Add NB to actions#saveSettings explaining and linking to the
    document

Follow commits soon:
* Persist the settings change to local storage when it changes, and
  unify with the preview change listener

Change-Id: I80dc5f29fbe6286f2e3e3b50d909894bc5041ccd
2016-12-14 14:35:59 +00:00
jenkins-bot 1277baf54e Merge "Tag previews acceptance tests with @integration" into mpga 2016-12-14 11:54:12 +00:00
jenkins-bot 9ec1fd308e Merge "Hygiene: Remove RL-related step" into mpga 2016-12-14 11:53:13 +00:00
jenkins-bot 1d8a5e1e98 Merge "Hygiene: Remove "I am on the ... page" step" into mpga 2016-12-14 11:52:14 +00:00
jenkins-bot c47c1867bc Merge "Hygiene: Tidy up "core" acceptance tests" into mpga 2016-12-14 11:52:11 +00:00
Sam Smith fcfe079d79 Hygiene: Organize reducers
Reducer changes:
* Break the mw.popups.reducers.rootReducer test into @@INIT tests
  for each reducer as there's shouldn't be any need to test that a
  framework works as documented.

Changes:
* Move the mw.popups.reducers#preview, #eventLogging, and #settings
  reducers into their own files in resources/ext.popups/reducers/.
* Make the associated tests mirror the new layout.
* Move the initialization of the mw.popups.reducers namespace into its
  own file.
* Remove the mw.popups.rootReducer property in favour of a simple
  private factory function per the reducer change above.

Change-Id: I94229d9ef1985f3806eec44c2e8234a5bbddc94f
2016-12-13 18:45:10 +00:00
Sam Smith 87ff0cae83 Tag previews acceptance tests with @integration
i.e. Allow the previews acceptance tests to be run against each Gerrit
change.

Change-Id: I17daaa955026c7fc5ef63b248c48932ecb75a1bc
2016-12-13 14:47:32 +00:00
Sam Smith 6a2f641cf4 Hygiene: Remove RL-related step
High-level acceptance tests shouldn't expose low-level concepts such as
the Resource Loader ("RL"). Merge the "And the RL module has loaded"
step into the "Given I am on the test page" step as they are only ever
used together.

Changes:
* Use the ArticlePage#wait_until_rl_module_ready helper method provided
  by mediawiki_selenium@1.7.3.
* Update and include the Gemfile.lock.

Change-Id: Ic81eae5dc0caa8ec51c91b21aef544f52d8c49e1
2016-12-13 14:46:03 +00:00
Sam Smith a0b01f86ab Hygiene: Remove "I am on the ... page" step
Merge the "Given the test page has been created" and "Given I am on the
... page" as they are only ever used together to mean "Given I am on the
test page".

Supporting changes:
* samples/links.wikitext -> fixtures/test_page.wikitext as it's more
  obvious what the file is.

Change-Id: Ide261a8e8c55133ab2a13a80c48e266252f61f5f
2016-12-13 14:25:37 +00:00
Sam Smith 4db0043ee7 Hygiene: Tidy up "core" acceptance tests
Changes:
* Rename the somewhat awkwardly named "popups_core" Cucumber feature and
  its accompanying step definitions to "previews".
* Remove as many references to Popups and HoverCards as possible.
* Use language consistent with the QUnit unit and integration tests and
  documentation, e.g. the user dwells on a link.
* Remove settings-related step definitions from the previews step
  definitions.

Change-Id: Ibc0d07e8394aeb640f9efaabfe10be5317bf4b8c
2016-12-13 14:14:08 +00:00
jenkins-bot 492c170aae Merge "Introduce the settings dialog UI" into mpga 2016-12-13 12:54:37 +00:00
jenkins-bot f7746bb860 Merge "Introduce the settings change listener" into mpga 2016-12-13 11:26:48 +00:00
jenkins-bot cacd6ee04c Merge "Create the settings reducer" into mpga 2016-12-13 11:03:47 +00:00
joakin 4d5269320f Introduce the settings dialog UI
* Port ext.popups.desktop/ext.popups.settings.js to settingsDialog.js
  * Blank tests for now. Needs Qunit integration tests.
    * Transform into a factory function for future testing.
  * Saving functionality is commented out, will be removed when immplemented in
    the actions
* Add new incomplete action saveSettings
  * Will perform the saveSettings async tasks and then trigger enabling or
    disabling popups.
* Rename action settingsDialogClosed to hideSettings for consistency

Change-Id: I3936d3a4bc476de16d76025139be09f1798796c4
2016-12-13 11:42:21 +01:00
joakin 034f1840ab Introduce the settings change listener
Which for the moment is only in charge of showing and hiding the dialog

Change-Id: Ib57250236ff424abddb0fa627d2a48167a5d8d74
2016-12-13 11:32:53 +01:00
joakin 8415bd1e9b Create the settings reducer
Right now only with visibility state on it.

Change-Id: Idbe99aca652eb04357ba85f22ba413dcd38cd54b
2016-12-13 10:46:13 +01:00
Sam Smith df441982fa {LINK,PREVIEW}_ABANDON_END logs an event
Since the user can dwell on a link, abandon it while moving to dwell on
the preview and vice versa:

* The time at which the link/preview was abandoned is recorded and can
  be updated.
* The event can only be queued when the link/preview has definitely been
  abandoned.

Reducer changes:
* Make the eventLogging reducer:
  * Calculate the time it took to show the preview.
  * Mark the interaction as finished when the user abandons the link or
    the preview.
  * Queue a "dismissed" event if the preview hasn't been shown or a
    "dwelledButAbandoned" event if it has when the abandon has
    finalized.

Bug: T152225
Change-Id: I6a254136f615484fc26e440fe5125289e74688a6
2016-12-12 19:00:33 +00:00
Sam Smith 60b65ad6c4 LINK_CLICK logs an "opened" event
Reducer changes:
* Make the eventLogging reducer queue an "opened" event with the
  requisite supporting data.

Changes:
* Update the Popups EventLogging schema to the latest revision, which
  defines the "opened" action.

Bug: T152225
Change-Id: I9d67daf83815f1c08b6479497c566dfa337de4bc
2016-12-12 18:59:57 +00:00
Sam Smith 5b76fb0276 LINK_DWELL starts an interaction
Action changes:
* Mix in timing information into actions that are likely to need it:
  LINK_DWELL, {LINK,PREVIEW}_ABANDON_START, LINK_CLICK, and
  PREVIEW_CLICK.
* Generate and include an unique token in the LINK_CLICK action.

Reducer changes:
* Make the eventLogging reducer:
  * Handle the LINK_CLICK action's new shape.
  * Start (create) and maintain a model of the user interacting with a
    link.

Bug: T152225
Change-Id: I671b12432ba2f7a93bf81043adb57ac30a4c38c3
2016-12-12 18:59:40 +00:00
Sam Smith 71b97cd089 Hygiene: Organise change listeners
Move all of the change listeners into
resources/ext.popups/changeListeners and remove the ChangeListener
suffix. Also, do the above for the associated tests.

Bug: T152225
Change-Id: I90ada465ea291d601f8f1c5c6e775148a2100319
2016-12-12 13:06:07 +00:00
Sam Smith bbeb618e1d Store/update user's preview count
Action changes:
* Add the PREVIEW_SHOW action.

Reducer changes:
* Increment the user's preview count in the eventLogging reducer.

Changes:
* Dispatch the PREVIEW_SHOW action when the preview has been shown.
* Add the previewCount change listener, which is responsible for
  persisting the user's preview count to storage when it changes.
* Call the change listener factories individually in
  #registerChangeListeners as their signatures aren't consistent.

Bug: T152225
Change-Id: Ifb493c5bff66712a25614ebb905251e43375420a
2016-12-12 13:05:50 +00:00
Sam Smith b7effdc000 Include user's preview count in BOOT action
Action changes:
* Include the user's preview count in the user property of the action.

Reducer changes:
* Make the eventLogging reducer add the bucketed user's preview count to
  the state tree.

Changes:
* Extract mw.popups.UserSettings#getPreviewCount and #setPreviewCount
  and associated tests from the ext.popups.core module.

Bug: T152225
Change-Id: I6b7afef31311be8fede685deb536f577845cb9cf
2016-12-12 13:01:44 +00:00
Sam Smith 4b74f72926 Include user's edit count in BOOT action
Action changes:
* Group user-related data in the user property, rather than repeating
  "isUser" and "user" prefixes.
* Include user's edit count in the user property of the action.

Reducer changes:
* Make the preview reducer handle the action's new shape.
* Make the eventLogging reducer add the bucketed user's edit count to
  the state tree.

Bug: T152225
Change-Id: I8fae9e2d0f6889ffdd30bb5192513d194f791967
2016-12-12 13:01:44 +00:00
Sam Smith 1ea31cc003 Hygiene: Extract shared stub user object
Changes:
* Extract the various shapes of stub user object into the shared
  mw.popups.tests.stubs#createStubUser factory method.
* Register the ext.popups.tests.stubs module in
  PopupsHooks#onResourceLoaderTestModules and make the test suite depend
  on it.

Bug: T152225
Change-Id: I893b11461d8484bcaabfd950c2fa0dc672454a9d
2016-12-12 13:01:44 +00:00
Sam Smith 3f2752b039 Initial Popups logging implementation
Action changes:
* Include whether the user is logged in/out and information about the
  current page in the BOOT action.
* Add the EVENT_LOGGED action, which represents the eventLoggined change
  listener logging the queued event.

Reducer changes:
* Move all tokens and timing information from the preview reducer to the
  eventLogging reducer.
* Make the eventLogging reducer reset the state.

Changes:
* Add the mw.popups.createSchema function, which constructs an instance
  of the mw.eventLog.Schema object that can be used to log Popups
  events.
* Add the eventLogging change listener, which logs the queued event.
* Add hand-crafted, artisanal documentation.

Bug: T152225
Change-Id: I8a3f58358b211cc55417dcda7e796fe538e3d910
2016-12-12 13:01:44 +00:00
Jhernandez 2fa5b9ef02 Revert "Settings dialog"
This reverts commit 047bccfac1.

It created merge conflicts with a bunch of patches that were days old and about to be merged. Instead of rebasing 10 patches, let's revert this one, finish merging the other ones and just rebase and fix this one. I'll re-introduce the patch in a bit.

Change-Id: Ib495755b0ab4bfa5fdf5590b1271792862a47d4b
2016-12-12 12:54:33 +00:00
Jeff Hobson 047bccfac1 Settings dialog
Also removes some unused (redundant) actions and the renderer reducer.

Bug: T152223
Change-Id: I878c7f16d71f8cdbd74a47ffeb9dadc4decf2883
2016-12-12 04:54:34 -05:00
jenkins-bot ec90fcba6f Merge "previews: Add generic fallback preview" into mpga 2016-12-02 12:06:53 +00:00
Sam Smith b2f9ffa9b0 previews: Add generic fallback preview
Changes:
* Make the gateway handle missing pages, which are characterised by the
  MediaWiki API response having both the missing property set to truthy
  and the page not having any revisions.
* Add the preview-empty template and associated "mwe-popups-is-empty"
  CSS class, which describe what an empty preview contains and how it
  should look.

Supporting changes:
* Move the original preview template into the ext.popups module.

Bug: T151054
Change-Id: Ife75bf9c6bafdfe0a6cc3e20eea853b4ac8f951b
2016-12-02 12:02:43 +00:00
jenkins-bot 9a7045d3bd Merge "Hygiene: Don't fall through unless necessary" into mpga 2016-12-02 11:24:07 +00:00
Sam Smith 27334437fb Hygiene: Don't fall through unless necessary
The preview reducer would treat the LINK_ABANDON_END and
PREVIEW_ABANDON_END actions as the PREVIEW_DWELL action. Fortunately,
this was a NOOP as they would only fall through if the preview was being
dwelled upon.

HT Joaquin Hernandez.

Change-Id: I01ff47de34ac41f1e6aa46aa5baccc2a27013f1b
2016-12-02 12:01:44 +01:00
jenkins-bot b5da2e1c13 Merge "Tests: Deeply extend prev state for test correctness" into mpga 2016-12-02 10:49:50 +00:00
joakin ac264001f6 Tests: Deeply extend prev state for test correctness
As it is, that test is passing the same previous state and current state
because extend by default only copies one level deep, resulting in the
manual mutation mutating both prev and current state.

This passes because the change listener always sets the link visibility
from the current state regardless of the previous state (it is doing
redundant work, but not too much).

Change-Id: I8cf125cc4f6833fbce0fe14bdcb4ef550c7e8450
2016-11-30 19:22:54 +01:00
joakin 8cd297c797 Hygiene: #processLinks Improve wording on tests
Change-Id: Ib6dd29d2c27dd10525fd9d875bfc860c5b76c841
2016-11-30 17:01:54 +00:00
joakin eae0a96e80 Hygiene: Only use that when necessary. Else use this
Change-Id: Idd91300041c1ae68a24a49626f79e97b3e8b2467
2016-11-30 17:01:35 +00:00
joakin cd7f74f691 Tests: Explain the second assert in the test
Like the next test also does, so that in case it fails we get some info
given the assert result doesn't match the test title.

Change-Id: I42d9e7c329c1a0b46133423e5303068b70b270ac
2016-11-30 17:00:20 +00:00
Sam Smith e4719c4918 Don't hide preview if it's interacted with
Action creator changes:
* Make the linkAbandon action creator asynchronous by splitting it into
  two distinct actions, LINK_ABANDON_START and _END, the latter of which
  is dispatched after a 300 ms delay.
* Introduce the previewDwell and previewAbandon action creators. The
  latter is an asynchronous action that mirrors the linkAbandon action.

Reducer changes:
* Make the LINK_DWELL, LINK_ABANDON_END, and PREVIEW_ABANDON_END action
  hide a preview, if one has been shown.
* Make the LINK_ABANDON_END action NOOP if:
  * The user has interacted with another link, or
  * The user is interacting with the preview.

Supporting changes:
* Update the mw.popups.reducers#preview and #renderer unit tests to use
  an empty previous state so that the tests are more resilient to
  modifications of the state tree.

Change-Id: I2ecf575bbb59bb64772f75da9b5a29c071b46a8d
2016-11-28 17:15:37 +00:00
Sam Smith 1210f2f63e actions: Don't fetch if user isn't in condition
Change-Id: I6884f2da38c5b0addcd0a8b3325363efd46401f5
2016-11-25 21:22:09 +00:00
Sam Smith eabb7011fb Don't always render after the API request resolves
If the user abandons the link after the API request delay (500 ms) but
before the it resolves (~10e3 ms), then the preview shouldn't be
rendered.

Changes:
* actions: Include the link in the FETCH_START, FETCH_FAILED, and
  FETCH_END actions.
* reducers: If the active link has changed, then FETCH_END is a NOOP.

Supporting changes:
* reducers: Signal that a preview should be rendered and shown with
  preview.shouldShow.

Change-Id: I3dd1c0c566ec63de515174c14845d7927583ce93
2016-11-25 12:42:02 +00:00
Sam Smith 582fab6aaf actions: window.setTimeout -> mw.popups.wait
The QUnit test suite now completes in ~10e2 ms rather than ~10e3 ms.

Changes:
* Make mw.popups.actions#linkDwell to use mw.popups.wait.
* Make the tests for mw.popups.actions#linkDwell complete faster, but
  still asynchronously, by stubbing mw.popups.wait.

Change-Id: I5cbef0ea69bc860f75cac27c1adea3d419c1ffad
2016-11-25 10:41:39 +00:00
Sam Smith 0d68a8f635 reducers: Remove unused state and cases
... from the preview reducer.

Change-Id: Ic7b9c38a39e0aec4f67a20b921acde2f9bbf362f
2016-11-25 10:41:04 +00:00
Sam Smith 5e2d8ae8d4 Render previews
Extract core rendering functionality from the mw.popups.renderer and
mw.popups.renderer.article objects.

For now, render and show the preview when the user dwells on and
abandons a link respectively.

Supporting changes:
* Add mw.popups.wait, which is sugar around window.setTimeout.
* action.response -> action.result in the FETCH_END case of the preview
  reducer.

Change-Id: I14b437e7c2f55b988837fcb2800dd61a23c29a01
2016-11-24 18:07:03 +00:00
Sam Smith 1c861fd9de actions: Include event in LINK_DWELL action
Also include the time at which the interaction started.

Change-Id: Ie46562a2641e8bd26fc687e16e4e7ef3760824b1
2016-11-22 13:46:44 +00:00
Sam Smith 587f060569 gateway: Remove parentheticals from extract
Extracted from ext.popups.renderer.article#removeParensFromText.

Change-Id: I200d431234c4b235a8621e1b261934b1282dd8e6
2016-11-21 10:41:45 +00:00
Sam Smith 261ab1799b gateway: Check if page has been revised recently
Extracted from ext.popups.renderer.article#init.

Change-Id: I906d74ded1082c9caf6f1b870309c815a5876c17
2016-11-21 10:32:28 +00:00
Sam Smith b1b29f4704 Link Previews -> Page Previews
Change-Id: I08e80220c76a65cadaba20ce78b9eb2b36139095
2016-11-18 09:51:06 +00:00
Sam Smith 089ee014ad Add link title change listener
Supporting changes:
* Remove the preview.previousActiveLink property from the state tree as
  it's unnecessary.

Change-Id: I657decf9425a7a9e2b27a798ed60b162569661d8
2016-11-18 09:51:01 +00:00
Sam Smith f6868d2567 reducers: Add the nextState helper function
OO.copy doesn't copy Element instances, whereas $.extend does. However,
OO.copy does copy properties whose values are undefined or null, whereas
$.extend doesn't.

Since the state tree contains an Element instance - the
preview.activeLink property - we need to use $.extend.

Add the nextState helper function which copies the current state tree
with $.extend and mixes in all updates manually.

Change-Id: Ie8edd9fa0cc3a62a792ed60b49288f85b3ca73e9
2016-11-17 21:41:56 +00:00
Sam Smith 0d300867ab Make API request after 500 ms
If the user has abandoned the link or dwelled on a different link, then
don't make the API request.

Changes:
* Fix a bug in the linkDwell reducer where the activeLink was always
  being set to undefined.
* Add the private fetch action creator.
* Make the linkDwell action dispatch the result of the fetch action
  creator after 500ms.

Supporting changes:
* Make the link* action creators take DOM elements rather than jQuery
  instances so that:
  1. Testing whether the state tree has changed is an identity
     comparison.
  2. jQuery instances are constructed only when required.
* Document the ext.popups.Gateway type.
* Document the Redux.Store type.
* Rename the "previews-page-title" data attribute to
  "page-previews-title" to avoid confusion.

Change-Id: I0b1cf3337a6f8d6450ad2bd127cb292ebb73af4f
2016-11-17 13:20:11 +00:00
jenkins-bot 156d552fcf Merge "Add footer link change listener" into mpga 2016-11-17 08:12:06 +00:00
Jeff Hobson f9cc341105 Add reducer cases for all actions
These may change as actions are implemented. Also fixes a typo in the
QUnit test for reducers.

Change-Id: I2218760f273c77c5d396177c99108a57de7162d6
2016-11-16 11:16:43 -05:00
Sam Smith a9e78f06ae Add footer link change listener
Supporting changes:
* Add mw.popups.registerChangeListener, which registers a change
  listener that will only be called when the state in the store has
  changed.

Change-Id: Ibe6934058327c7f02f7d8092e74a667a5a1c600a
2016-11-16 15:20:34 +00:00
Sam Smith ca84de7c9d Add tokens to BOOT action
Changes:
* Add sessionToken and pageToken properties to the BOOT action and
  update the preview reducer.

Supporting changes:
* Move the mw.popups.createActions to ext.popups/boot.js so that Redux
  is used in one file and the actions can be tested in isolation more
  easily.

Change-Id: Icd61bf1aeb466899e047432bf9798e2574652830
2016-11-14 19:42:52 +00:00
Jeff Hobson 2215560866 Add reducers
Reducers as a whole are a WIP, but this implements a baseline from which
to add more.

Changes:
 * Create ext.popups.reducers to house all reducers
 * Create reducers for preview and renderer state manipulation
 * Create rootReducer by combining preview and renderer reducers
 * Add QUnit tests for reducers
 * Move action types into ext.popups.actionTypes
 * Extract rootReducer from boot.js

Change-Id: I8a2296c6846cd4b0552a485e671af1d974944195
2016-11-11 19:55:04 +00:00
Sam Smith 722bfe12a5 Add gateway
Supporting changes:
* Automatically register JavaScript files in the
  tests/qunit/ext.popups/ directory.

Additional changes:
* Fix a grammatical error in the docblock for
  mw.popups.createExperiment.

Change-Id: Ieb00709e353f0b960375fdaa0ca0dcdf950f2eb9
2016-11-11 18:59:44 +00:00
Sam Smith 9611d3b2db Add LINK_DWELL and LINK_ABANDON actions
Supporting changes:
* Add mw.popups.processLinks.
* Extract the existing unit tests for mw.popups.selectPopupElements and
  mw.popups.getTitle.
* Fix Grunt QUnit timeout.

Change-Id: I325bcb15abc6e0b745d78b7308a346a034ab2988
2016-11-10 11:47:55 +00:00
Sam Smith 16adb1d738 Remove optional survey link
Change-Id: If545873bb97b1da8ea5001dce575b1ef512903fb
2016-11-09 14:41:03 +00:00
Sam Smith 19349c0108 Add BOOT action
Changes:
* Make grunt:qunit run all QUnit tests in those modules whose names
  being with "ext.popups".
* Add ext.popups/index.js, which initialises the mw.popups namespace.
* Add ext.popups/userSettings.js, which contains the code that deals
  with interacting with the User Agent's storage.
* Add ext.popups/experiment.js, which contains the code that that
  decides whether or not the user is in the experiment condition.
* Add tests for both units, converting existing tests where appropriate.
* Remove the associated code from ext.popups.core/ext.popups.core.js.
* Finally, dispatch the BOOT action against the store in
  ext.popups/boot.js.

Change-Id: I697207677304bd49c7cfe1d37bb0a4af7810f387
2016-11-09 10:40:59 +00:00
jhobs 046d12f51b Update linting and enable command line QUnit
You can use `grunt watch` now!

Changes:
 * Re-enable QUnit (but ignore legacy tests)
 * Add a sample QUnit test
 * Add ability to run QUnit via `grunt watch` or `grunt test`
 * Move linting to `grunt lint` task
 * Add Redux to globals in linter

Change-Id: Ie4a65a8a66773d6472b3d73257267d18027ff3c3
2016-11-08 13:56:17 -05:00
Sam Smith f64c6ea509 Disable QUnit and acceptance tests
Change-Id: Icee115520ec559f8e107de2946224ac1fe65154d
2016-11-08 09:31:51 +00:00
Jhobs 102d02b891 Revert "Revert "Fix tooltip interactions""
This reverts commit 11431dd2f6.
It also applies the fix for the original error.

Change-Id: Ib86534ffbcd20f64c8ba06c23f2e8af509437cfe
2016-11-03 13:51:36 -04:00
Jdlrobson 11431dd2f6 Revert "Fix tooltip interactions"
There is one reference to removeTooltips in 
ext.popups.targets.desktopTarget.

I suspect this got broken in a rebase. It seems Jenkins only runs
browser tests post merge. We should fix that.

Please resubmit the patch with this amended.

This reverts commit 0ff40a6532.

Change-Id: Idd8dffb853db760ebc5866190d008f173e3025ba
2016-11-03 17:46:41 +00:00
jhobs 0ff40a6532 Fix tooltip interactions
Tooltips are intended to be stripped upon `mouseenter` and `focus`
events and then restored during their corresponding `mouseleave` and
`blur` events. This was broken due to duplication of event registration
and no proper deregistration.

Changes:
 * Rename `mw.popups.removeTooltips` to `mw.popups.removeTooltip` to
   more accurately describe its effect
 * Narrow the scope of `mw.popups.removeTooltip`
 * Add `mw.popups.restoreTooltip`
 * Add `onLinkBlur` to `desktopTarget.js` to handle tooltip restoration
 * Update qunit test to reflect changes to functions
 * Minor hygiene changes regarding event namespaces

Bug: T142723
Change-Id: I776a72e436ac823fdd6b68435d9a042a91c934e5
2016-11-03 13:39:26 -04:00
jdlrobson 4d7d55ec14 Hygiene: Rename getMassagedData to processHovercardEvent
This name is more fitting to the new purpose of this method.

Change-Id: I48f5e9a3ae737a104270699742a96923c92e12e8
2016-10-31 11:25:09 +00:00
jdlrobson 9477fd5fe6 Multiple hover events should not clear dwellStartTime
If a user has hovercards disabled, when they right click a link
this will trigger another hover event which will reset dwellStartTime.
This means when a dwelledButAbandoned event fires shortly afterwards
the totalInteractionTime will not be correct.

To remedy this, the calculation of totalInteractionTime and
perceivedWait is moved into ext.popups.schemaPopups

Now that we can trigger events without logging to the server and
checking the total interaction time duration in two places,
let's always run the event and only check it once.

A `hover` event triggers the setting of a dwell start time
A `display` event triggers the setting of the perceivedWait value
* Both are reset on a dwelledButAbandoned.

Since dwellStartTime is controlled inside a single place, getMassageData
no longer needs to clear it.

The test "returns false if dwelledButAbandoned event without a dwellStartTime"
is removed as this should no longer be possible.

Bug: T147846
Change-Id: Ie5917ca86f0d0ab27f4cf507e6dfa2c271433c03
2016-10-28 17:33:10 +01:00
jdlrobson 47c2df09d4 Display and hover events are logged but not recorded
This adds two new events "display" and "hover" which are not
recorded back to the server. The benefits of having these events
is that they are important events in the lifecycle of a hovercard.

This allows us to debug trackSubscribe and ensure we see the behaviour
we expect to see and in a future patchset will allow us to use these
events to drive the calculation of interaction time in one single location
(Sneak preview:
 https://gerrit.wikimedia.org/r/316481 to get a feel for the why.)

Change-Id: I58eefc29444179fd245cfd722093dedea19455e8
2016-10-25 19:55:35 +00:00
jdlrobson c4460ba2ea Hygiene: Move logic for duplicate events into getMassagedData
Add tests.

Change-Id: I15c10f256432ab5bfa7bf7adb34764f84b17c439
2016-10-25 19:33:29 +00:00
jdlrobson 8fb7e6fbe6 Tests: Test existing behaviour for getMassagedData
Change-Id: Ia26600222c02b986a05918a00c0776c7dc8deb77
2016-10-24 15:52:21 -07:00
Baha cd0546beb8 Fix browser tests
The Hovercards checkbox on the beta preferences page doesn't have an ID
anymore. It has a name though, which is used from now on.

The regression was introduced in I8636f32330e23814ba3b4c0f5e22e55aaf77883e.

Bug: T148856
Change-Id: I7baa78b0d8c560ee29c3a550628bfd47cad1c30e
2016-10-24 14:27:09 -04:00
jdlrobson 7dfad14da1 Directory structure should reflect the ResourceLoader definitions
Given we currently have modules defined in extension.json and in hooks
it can be really confusing understanding how the code fits together.

This change hopefully makes this a little clearer by using folder names
that are named after the resource loader modules - this is also consistent
with how we do things in our other extensions.

A images folder is added to the route so that it is clearer that the images
are not used in ResourceLoader module definitions and are only used to illustrate
the beta feature.

Change-Id: Ia650ec03e3a6d3069165441ddfa069d390be4d10
2016-10-19 20:52:40 +00:00
Sam Smith 0b2961c318 Merge mw.popups.experiment into mw.popups.core
ext.popups.experiment depends on .core as it initialized the mw.popups
namespace and .core depends on .experiments for
mw.popups#getEnabledState.

By merging the experiment module into core, we can eliminate any
circular dependencies.

Changes:
* Move ext.popups.experiment.js code into ext.popups.core.js
* Remove mw.popups.experiment module and any references to it

Note: ext.popups.experiment.test.js was left in its own file for cleaner
QUnit module setups and easier removal later. I'm not entirely happy
with doing it this way, but I'm not sure changing the mw.config within
the mw.popups.core QUnit module is worth merging the files.

Bug: T146035
Change-Id: I1f024567010acaa61c1d613c6e59c998198a5976
2016-09-21 16:43:49 -04:00
joakin 8f001ee4bd Respect beta feature flag for logged in users
Both in active and inactive state (not just active like before).

Bug: T146017
Change-Id: Ieb4cd39c2870fb701cabd0f1d01c0ab42b6ebe78
2016-09-20 17:48:39 +02:00
joakin eb852cacd5 Fix enabling/disabling browser tests
features/popups_settings.feature:33 seems to fail because of quick
interactions after disabling+enabling hovercards.

Setting a sleep 1 after disabling and enabling hovercards (to allow the
page to start refreshing) makes the tests more resilient

Bug: T145152
Change-Id: Iaf66aaf0e2c4f8e55419d22889f91a02891e49a1
2016-09-14 16:42:56 +00:00
Volker E 0282b9648f Hovercards: Improve layout of settings dialog to design spec
Improving Hovercards' settings dialog to fulfill design specification.
Also fixing HTML structure by removing invalid `radiogroup` element and
adding missing `</div>` element, fixing related QUnit test.

Changes:
 * Add close icon instead of using text
 * Style header as a table for alignment
 * Remove redundant "OK" button and have it replace "Save" instead
 * Update text of "OK" button to "Done"
 * Fix description for translation of "Done" button
 * Fix qunit and selenium tests
 * Remove unnecessary markup and less
 * Add mediawiki-ui-button and mediawiki-ui-icon dependencies
 * Shrink dialog width some per design spec
 * Fix dialog horizontal position calculation to remove hard-coded value

Bug: T138612
Change-Id: I7395e3438836149becdd576942bdaf6f21b4163f
2016-08-10 14:01:36 -04:00
jdlrobson 7975fde745 Remove the need for global mw.popups.triggers
Change-Id: Iec1dd93a83fe393bd8717884ab4bab692ad7b6f4
2016-06-06 09:30:54 -04:00
jdlrobson dedb61caf9 Drop support for non-SVG browsers
According to caniuse.com SVG support is available
from IE > 8, Firefox > 3, Safari > 3.1 and Android
> 2.3. Android 3-4.3 does not support masking.

Out of all these browsers, considering market share
and ResourceLoader support, none of these browsers
are of concern to us. In IE8 for example we do not
run JavaScript for our end users. Thus we should remove
this fallback support.

Changes
* Remove createImgThumbnail method and its test
* Groups duplicate CSS groups
* Refactor createThumbnail function
** Leave a FIXME on some curious code

Change-Id: I59ac2e320b2e07815bc4136d5942016fdc1d4340
Bug: T135554
2016-05-31 15:23:07 -07:00
jdlrobson 765aa40cc1 Replace use of jStorage with mw.storage
Use the standardised MediaWiki storage system for the simple use
case of disabling/enabling Popups. The jStorage library is 12kb
uncompressed and cannot be justified for this usage (and if it becomes
the standardised library mw.storage will begin using it)

This means that browsers with full localStorage or no localStorage
support will not be able to disable Popups. Given the current ecosystem
of the web - localStorage is widely supported - and the fact that grade
A browsers enjoy localStorage support - this is not a problem.
See https://github.com/wikimedia/mediawiki/blob/REL1_27/resources/src/startup.js#L59

Changes:
* Stop using jStorage
* Cleanup and migrate previous values in jStorage with plan for removing this
in a month.

Bug: T136241
Change-Id: I6dac2911e84d6cb20731be34add01576cf407c46
2016-05-30 12:30:38 -07:00
jdlrobson feb0c76381 Render settings via template
This improves readability and separates the HTML from the
JavaScript

Change-Id: Ib765d78890b9aeb05940df00160790b01751a36b
2016-05-30 10:49:17 -07:00
Baha aba43fd560 Switch to Schema:Popups revid 15597282
Bug: T131315
Change-Id: I2ed18e00afb3e355327b417e68e5930b46d49086
2016-05-24 14:26:46 -07:00
Sam Smith c4667fd133 Convert isUserInCondition from async to sync
As there are an unmanageable amount of synchronous checks of
mw.popups.enabled, convert mw.popups.experiment.isUserInCondition to a
synchronous method.

Follow on I4959749.

Bug: T132604
Change-Id: Ide07e62868c77bfcd78af58dcec7303a35a72157
2016-05-19 14:06:17 -07:00
Sam Smith e9ddc8328d Handle user explicitly enabling/disabling feature
Follow on I4959749.

Bug: T132604
Change-Id: I4e6780f17b0423823295be9410a4343150e1e562
2016-05-19 19:10:53 +01:00
Sam Smith 3f03d681c9 Add ext.popups.experiment module
Changes:
* Add the ext.popups.experiment module
* Add the mw.popups.experiment.isUserInCondition function, which
  returns a promise that resolves with true if the user is in the
  experimental condition, otherwise false
* If the experiment isn't configured, i.e. wgPopupsExperimentConfig is
  null or undefined, then the user isn't entered into the experiment,
  providing a kill switch

Bug: T132604
Change-Id: I49597494273e3862711a32e4951c8598e6c8bf59
2016-05-18 17:28:46 +01:00
jenkins-bot 85b27d8de8 Merge "Do not directly manipulate the cached object" 2016-05-18 09:28:41 +00:00
Baha cda1ffe425 Use mw.eventLog.Schema to log EventLogging events
This change is an intermediate step in our transition
to logging a variety of events easily.

Also:
  * Some events may need sendBeacon support and may not be
    logged if the navigator does not support sendBeacon.
  * Do not load schema code if EventLogging is not available.

Bug: T131315
Change-Id: Iff939577f65f1c6c71701dd6967939445385fb70
2016-05-16 17:29:48 -04:00
jdlrobson 7f3be6dcd4 Do not directly manipulate the cached object
Popups currently makes use of a render cache. Using a cache in this
way without protection causes problems (I will look at cleaning this up)

The hack below it
`mw.popups.$popup.html( mw.popups.$popup.html() );`
will lead to the html of the cached object being wiped out on IE9 meaning
future loads will show an empty popup.

Add a unit test (which previously would fail in IE9) to protect against this
in future.

Bug: T68496
Change-Id: Icef784fb389b0ab1856e2ba7464c9423ebcd62ab
2016-05-12 16:56:19 -07:00
jdlrobson ed3500b1bd Describe init method behaviour via QUnit tests
Change-Id: I78c4a4ac7b653e31ce52104cbdaef3d6390b2e20
2016-05-12 16:22:59 -07:00
jdlrobson ab15bf8b3e Add tests for createPopup
Change-Id: I72381ec665427ee2c5c5631d9bc07a1ad5079646
2016-05-12 15:33:50 -07:00
Sam Smith 26be90dc5a Add client-side validation of PopupsSurveyLink
Changes:
* Extract survey link element creation into
  mw.popups.render.renderers.article#createSurveyLink
* Make #createSurveyLink throw an error if the URL doesn't start with
  https or http
* Add unit tests that cover the new behaviour of #createSurveyLink

Bug: T129177
Change-Id: I8b61cb0e94ab4e30bc894c279bb05918ecc7719e
2016-05-11 14:53:30 +01:00
jenkins-bot 9a9b4abdea Merge "Allow brackets in createImgThumbnail" 2016-05-11 10:16:07 +00:00
jdlrobson f3d23c975f Allow brackets in createImgThumbnail
Changes:
* Quote the URL with double quotes when generating the background-image
  rule

Bug: T129177
Change-Id: I74748c7efe67954272ce0a539455b0b00001a26a
2016-05-11 10:18:49 +01:00
Prateek Saxena 46f69baf38 article: Remove bracketed text from the title before looking to bold it in the extract
Bug: T69224
Change-Id: I5306101a7acd3c33c55989e97c7581a403594645
2016-05-10 21:51:57 +00:00
jenkins-bot 10517dee21 Merge "Add QUnit test for ext.popups.settings" 2016-04-28 20:32:19 +00:00
Baha 72dd872781 Add QUnit test for ext.popups.settings
Test pieces that make sense, everything else is already
covered in cucumber tests. See the following commit for more
info: I55f311b6b8845e6ebf4cc5698758afd1f9042a45.

Bug: T133025
Change-Id: I474c1569494601ae5865dcfba22ea728220ff8df
2016-04-28 16:13:20 -04:00
jenkins-bot d9a4c8b0a3 Merge "QA: add a browser test to cover "enable previews" feature" 2016-04-28 08:40:51 +00:00
Baha 85cc7e2257 QA: add a browser test to cover "enable previews" feature
Test whether:
* "Enable previews" footer link correctly appears/disappears;
* A hovercard correctly shows/doesn't show when enabled/disabled.

Bug: T133054
Change-Id: I55f311b6b8845e6ebf4cc5698758afd1f9042a45
2016-04-27 20:22:34 +00:00
Sam Smith 91d3b510cb Add test to cover mw.popups.setupTriggers
Follow up Id173b21.

Bug: T133020
Change-Id: Id97cc7c7cb546d09c196dab8377e9e61a0b12f85
2016-04-27 19:20:27 +00:00
Sam Smith 5f69a721fc Add missing mw.popups.selectPopupElements test case
Follow up on Id173b21 by adding a test case that covers the test of
whether the anchor's title is in a content namespace.

Bug: T133020
Change-Id: I414a5ff8aa4edf58dd0d1947db077afdd1d22f39
2016-04-26 09:25:25 +01:00
jenkins-bot 9b7797dd6d Merge "Add QUnit tests to cover ext.popups.core.js" 2016-04-22 08:54:00 +00:00
jenkins-bot 57bc00c9ad Merge "QA: Updates to browser tests to avoid flakiness" 2016-04-20 22:39:39 +00:00
Baha 728073d9e4 QA: Updates to browser tests to avoid flakiness
* Wait until the form submits successfully, verifying it
worked by testing for the notification toast.
* Drop sleep statements where possible - instead use when_present
Use one when asserting something doesn't show to avoid false positives
* Allow more time for the hovercard to show (5s) - API requests might take
longer than default time.
* Assert popups JavaScript loads before continuing with test. This
helped trap a bug in testing and will be useful for future.

Bug: T133019
Depends-On: Icb1e6ddc8f95da5e4b4de2916d292694c11ba731
Change-Id: Iacd3beedf44cadffcf0285231b2df7e5b64294f6
2016-04-20 20:02:13 +00:00
Baha 06b49dc6b8 Add QUnit tests for ext.popups.logger
Bug: T133024
Depends-On: Icb1e6ddc8f95da5e4b4de2916d292694c11ba731
Change-Id: I73fee2e3351de357f8f60bf6287a876e245117df
2016-04-20 18:33:53 +00:00
Baha b1ec40a202 Add QUnit tests to cover ext.popups.core.js
Bug: T133020
Depends-On: Icb1e6ddc8f95da5e4b4de2916d292694c11ba731
Change-Id: Id173b215701abb87f998722526d643f36f3c0308
2016-04-20 18:33:50 +00:00
Sam Smith 6a0e108384 QA: Enable Hovercards beta feature in browser tests
Bug: T133019
Change-Id: I63faec86a756f189a40d0f61c75e33060c5395fb
2016-04-20 18:20:27 +00:00
Phuedx def7e41192 Merge "Add browser test for hovering link" 2016-04-19 13:28:04 +00:00
Baha 3e78503e8e Add browser test for hovering link
Basic feature of browsing a page, hovering a link, and showing/hiding
a hovercard.

Depends-On: Ie94fa399512be041f12b2f7cada20d4206ddaf82
Bug: T133019
Change-Id: Idf39e7e2a3b343babd6d0538225b4ef9002e8ac1
2016-04-19 13:12:24 +00:00
Prateek Saxena 5f92196541 Bold only first instance of title in extract
Bug: T132523
Change-Id: I3145186264edd23ca898365ae55184cbe96ada6a
2016-04-13 21:24:42 +05:30
Baha 7c6ccb3d1a Remove dead space
Make sure the popup is displayed right above or below the link.

Bug: T68317
Change-Id: Ib6ba9f1ffc5244842a1535937aa0990eae6943ae
2015-10-14 15:49:39 +05:00
jenkins-bot 486e34fb38 Merge "Move the article renderer in to the renderers property" 2015-10-01 08:50:39 +00:00
Prateek Saxena 1565a1d3c9 Move the article renderer in to the renderers property
To allow multiple renderers (for different types of content)
to be defined.

Change-Id: I50320646e26f36a0a2bc425c82ccc58912840f84
2015-10-01 08:48:00 +00:00
Prateek Saxena 6eef4f325b Add jscs and jshint tasks to the Gruntfile
Adds the jscs and jshint packages for development and their tasks in
Grunt. Also fixes all the code convention errors.

Change-Id: If1c9dfdbe22d4912d78b6a51b1292866970a85cc
2015-09-04 13:57:52 +05:30
Prateek Saxena 03f4fa63b2 core: getTitle: Return undefined for non URI links
mw.Uri throws an exception when dealing with -

    href="javascript:void(0);"
    href="mailto:abc@example.com"
    etc.

Using a try…catch to return undefined in this case.

Bug: T95215
Change-Id: I632e9dc0e70a5fddf9f2573572bfc8e7f6232923
2015-04-21 19:19:43 +05:30
wctaiwan 642bdf013e Use href attribute to calculate titles
This is needed for wikis that use LanguageConverter, since the title
attribute is converted to the user's variant, and the canonical title is
needed for the API unless converttitles is specified.

For filtering, instead of comparing linkHref and expectedHref, filter
out links that have other query parameters or aren't in content
namespaces.

Bug: T93605
Change-Id: I5534753307ed5e1d4b27c52c616fd143b2a397e1
2015-04-06 05:55:25 -04:00
Prateek Saxena 20f2bef272 renderer.article.getProcessedElements: Stop escaping the title and the extract
Both the title and the extract were being html escaped thus producing
string like &#039; and &quot; when used with .text(). So, we now use
document.createTextNode() for the normal text and .text() with the bolded
one.

Bug: T93720
Change-Id: I6bbc52e427dc636b7b0be1ad4f749d9273ff61b3
2015-03-26 19:28:20 +05:30
Prateek Saxena 3eaf2829e8 renderer.article: Remove leading spaces before brackets
Bug: T69225
Change-Id: I83f79fa0ebd19bea6ed7ea266cece0778210adb2
2015-03-05 15:32:45 +05:30
Prateek Saxena df0b988eec renderer.article: Bold the title no matter what the trailing characters
Bug: T69229
Change-Id: I833c0dcae98010bc74b6b58ae8035aaac4e6465b
2015-03-05 15:31:42 +05:30
Prateek Saxena a43ef7ca51 Remove the need of .html in article.getProcessedHtml
Instead of replacing all instances of the title in the extract -

  '$1<b>$2</b>$3'

We now put symbolic strings there which we use to split the string
and then make an array of text and <b> elements that get appended
to $contentbox.

Bug: T76378
Change-Id: I02222bbff84532f63cac67af1bf889c328ec6ff2
2015-03-05 15:30:06 +05:30
Prateek Saxena b24e39e9fc Run mw.html.escape on page extract and title
Add test for XSS attack

Bug: T69180
Change-Id: I213169bd9daed979e63f50cf3926f7196eb6181c
2014-12-01 11:23:14 -08:00
Prateek Saxena 40222517ca render.article.getProcessesHtml: Add tests
Change-Id: I2e000fd884df9113f1810ec1ca2aa1562a88790b
2014-06-11 12:47:52 +05:30