Commit graph

562 commits

Author SHA1 Message Date
DannyS712 68d52f7fa9 Use assertTrue instead of assertSame to compare with true
Bug: T244552
Change-Id: I42c50e37515e49a15658041147edc1d644812c46
2020-02-07 07:17:04 +00:00
Piotr Miazga 0ab39f88e7 Enable by default
Popups is enabled on the Wikipedias but disabled by default, which makes
it more difficult to enable on third-party wikis.

Things should be enabled by default, and them WMF configs should disable
features when they are not used/available.

Supporting changes:

- Rename PopupsContextTest#testAnonUserHasDisabledPagePreviews and
  remove the associated data provider, which provided only one datum

- Set $wgPopupsReferencePreviews to false in
  PopupsContextTest#testShouldSendModuleToUser in order to isolate the
  code under test

Change-Id: Ib8cc7041d792bed0a19d18e14506627099a69bef
2020-01-29 15:40:23 +00:00
Umherirrender 9fa7f2071c build: Updating mediawiki/mediawiki-codesniffer to 29.0.0
Change-Id: Ifb739130872b192b0fee54351555b65c3099981e
2020-01-26 20:22:03 +01:00
WMDE-Fisch 4f263bebfc Don't use double dash in refrence preview tests
The default way to build these ids is without a double dash afaik.

Change-Id: I068d97de517f9da09c203d543cf6eb51cf306465
2020-01-23 18:41:50 +01:00
jenkins-bot 5d925e3479 Merge "Add tests case for user preferences while in Beta mode" 2019-12-18 07:57:40 +00:00
Thiemo Kreuz 776f4af6c5 Add tests case for user preferences while in Beta mode
This is a direct follow up for I4d31805. Note the previous patch was
only testing the code path when Beta is disabled. But the bug was about
what happens when Beta is enabled. This is now properly covered by
these tests.

Bug: T240947
Change-Id: I54c5e9751e14a94808e85d935e1972eea0395002
2019-12-17 16:27:26 +01:00
Thiemo Kreuz fc6a72094d Turn some tests into faster running "pure" unit tests
On my local machine, this reduced the runtime for all PHPUnit tests
combined from 900ms to 800ms.

Change-Id: Iec4f0396115fd270ba1a1f6668e1672cea5f7aff
2019-12-17 16:20:27 +01:00
Thiemo Kreuz 5752c2538e Fix initial preferences for newly created user accounts
It appears like we accidentially copy-pasted the behavior for
PagePreviews and made ReferencePreviews behave the same, not taking
into account that the later feature is in Beta mode.

Bug: T240947
Change-Id: I4d31805ee9b2045c49c7ab4179c5a4adbcba0394
2019-12-17 13:37:11 +00:00
jdlrobson 01fc2db19f Use 6.1.0 of @wikimedia/mw-node-qunit
Bug: T203137
Change-Id: I9fd701cc9575ad250c919d88bf1fe74898b690eb
2019-10-22 10:42:49 -07:00
Thiemo Kreuz 76e02fae98 Remove obsolete mediaWiki and jQuery aliases
Notice how this actually reduces the size of the final, compiled index.js.
It's not much, but still.

One issue I noticed is that the coverage reports for the JS code stopped
working. I have no idea why.

Bug: T208951
Change-Id: I2fe92579574b3b1ba4d2dd064899eee944045a96
2019-10-22 09:30:46 +02:00
Thiemo Kreuz 71ac670d9e Add visibility keywords to all constants in PHP code
Change-Id: I384cffed670c7e845465e3e18808e267327011ed
2019-10-22 07:10:31 +00:00
Thiemo Kreuz c7595e54f6 Replace deprecated mw.RegExp.escape() with mw.util.escapeRegExp()
The signature mw.RegExp.escape() is deprecated since MediaWiki 1.34.

By the way, this is the 4th or even 5th time in my short career this
tiny, single line (!) helper function is moved around and I need to
update all my code. This felt already ridiculous when it happened the
2nd time.

Change-Id: I4d05a49120aff64ebc316d0af7736c62385d9307
2019-10-21 15:00:36 -07:00
jenkins-bot 4476eb7f75 Merge "Upgrade Popups mw-node-qunit version" 2019-10-21 11:07:57 +00:00
Thiemo Kreuz fe32c48268 Replace all mock builders with createMock() calls
This was motivated by two things:

1. Notice the bad class name in UserPreferencesChangeHandlerTest. This
was possible because the default mock builder does not check if a class
exists, *and* there was no type hint in place. createMock() *does* check
if a class exists.

2. We are free to use createMock() from PHPUnit 5+ now. It's not only
shorter but more strict and reliable.

Change-Id: I301a171d587026eab0a62575ab2fdbfd7733c661
2019-10-18 14:31:10 +00:00
Thiemo Kreuz a63a1cf91c Split user preferences for Page and Reference previews
Bug: T233813
Change-Id: I89205658c561961b90abaa133a004e54beebfab5
2019-10-17 11:21:21 +02:00
James D. Forrester e16143df16 build: Upgrade mediawiki-codesniffer to v28.0.0
Change-Id: Icd67aed448269f603dd4465f7e46eac9a64bd1a1
2019-10-15 16:13:01 -07:00
jdlrobson 7d6a903d69 Upgrade Popups mw-node-qunit version
Bug: T203137
Change-Id: I0cf856d04eacf5bf7764c58db55eeae04811e973
2019-10-15 15:36:54 -07:00
Adam Wight 76a34618c3 Tracking for Reference Previews interactions
Logs events to the ReferencePreviewsPopups EventLogging schema, in
order to understand whether Reference Previews is helpful for
end-users.

This will be removed along with the older tracking, as soon as our analysis
phase is finished.

Incidentally disables a lint rule for the generated JS, it's about
readability so irrelevant to the minified code.

Bug: T214493
Change-Id: I2638611ba67b785338f7e98a1c4b08a5e829812d
2019-10-07 11:22:00 +02:00
Max Semenik b72a95b5c0 Fixes for PHPUnit 6
Bug: T192167
Change-Id: I354077e8e44cfea3e75219d6701a4f9e11d4c70a
2019-10-05 22:43:20 -07:00
Thiemo Kreuz 3eb7c9b976 Replace all loose assertEquals with strict PHPUnit assertions
A method that is expected to return, for example, a boolean true
should not return an other value that PHPs loose == comparison might
also consider true.

Same for all other loose equality checks.

Change-Id: If729c6e97d5337eee10b717da76dad428218ff69
2019-10-04 10:34:21 +02:00
Adam Wight aa6972c277 Collect metrics for logged-in users as well as anons
The eventlogging `isEnabled` function determines when to sample,
this patch removes the `isAnon` conditional so that we can measure
reference reading habits for all users.

Also guards against a non-function navigator.sendBeacon, which was
previously intended but incorrectly tested.

Bug: T214493
Change-Id: I42cb3082fb85c7900426a2055dfa3c2f6ecfd968
2019-09-27 12:07:11 +02:00
Ed Sanders 9b3029e0ee Build: Update linters
Change-Id: Ia2a833a01e1bb05d6be3923dd452b1851afd7655
2019-09-17 12:47:25 +01:00
WMDE-Fisch 69caa6ec3d Add browser tests for quickly hovering links
Bug: T219434
Change-Id: I3597b8025f7a12db0cf5d83cce5a77abace9bae3
2019-08-23 08:21:14 +00:00
Thiemo Kreuz 065a8e9631 Fix action reducer forgetting *all* duplicate dwell actions
I was able to track the issue down to the changes made in this patch:
https://gerrit.wikimedia.org/r/331563

This patch is mostly a simplification of ce8a2d4
(I9a73b3086fc8fb0edd897a347b5497d5362e20ef):

- Don't make wait#wait() abortable. This adds complexity and isn't
  needed since the token is rechecked in the .then() of
  actions#linkDwell(). The request is permitted to continue and fetch if
  that token still matches and is never issued otherwise.

  Once a request has been issued, that request is still abortable.
  However, note that calling XHR.abort() is just a request to abort and
  may not be granted. Whether or not XHR.catch() is invoked is what
  dispatches the FETCH_ABORTED action (or doesn't if the request to
  abort was denied).

- Remove the abort tests for wait#wait() since the functionality is no
  longer provided.

- Pass the preview token in the FETCH_ABORTED action and reduce
  FETCH_ABORTED the same way as ABANDON_COMPLETE in reducers/preview.

The follow-up patch, I3597b8025f7a12db0cf5d83cce5a77abace9bae3, adds
integration tests for the specific bug fix. Note that these Selenium
tests are incompatible with the content proxy, so it is probably best to
simply unset $wgPopupsRestGatewayEndpoint and $wgPopupsGateway and allow
the defaults to be used. Also note that the tests are incompatible with
recent versions of Node.js (so use NVM) and emit many deprecation
warnings (so set deprecationWarnings to false in
tests/selenium/wdio.conf.js) An example run of the tests looks something
like:

  chromedriver --url-base=wd/hub --port=4444 &
  # If any changes are made locally, also run `npm -s start &`.
  MW_SERVER=http://localhost:8181 \
  MEDIAWIKI_USER=foo \
  MEDIAWIKI_PASSWORD=bar \
  DISPLAY= \
  npm -s run selenium-test

Live testing may be performed as well. Remember that RESTBase requests
are incompatible with MobileFrontend's content proxy hack so ensure to
comment it out if $wgPopupsGateway is configured for RESTBase (see
T218159).

1. Open the DevTools network tab.
2. Disable the browser cache. Chromium, at least, won't abort requests
   coming form the cache.
3. Hover back and forth quickly over a preview. In Chromium, canceled
   requests are labeled and appear red. This is a good scenario to test.
   With the patch, a preview should always be shown when ultimately
   resting on a link. Without the patch, it is possible to rest upon the
   link with no preview showing. This may require several attempts.

Bug: T219434
Change-Id: I9da84b0296dd14e9ce69cb35f1ca475272fb249a
2019-08-23 10:08:19 +02:00
Ed Sanders 4d885286a3 eslint: Enforce template-curly-spacing
Change-Id: I5640e86cba25f6100c7814c2ef8a845941f73497
2019-08-15 10:24:43 +02:00
Ed Sanders 2687d12c52 eslint: Remove valid-jsdoc override
Change-Id: I6a9936743a74afb528713f21e016838947fa1914
2019-08-15 08:00:24 +00:00
Ed Sanders a17be78b3d build: Update linters
Change-Id: I9b32f412e7e75918a59bdb239d3a42670177be70
2019-08-15 09:55:57 +02:00
Dan Andreescu 27a95517b7 Remove dependencies on deprecated schema modules
As mentioned in T205744, EventLogging schema ResourceLoader modules have
been deprecated.  This removes those modules from loader calls.

Bug: T221281
Change-Id: I1b7355c69e09756f50ccd1c1955b45cae4a64b9e
2019-06-19 09:51:30 -06:00
Adam Wight ed06a6dbb1 Docs: Remove incorrect documentation about LocalSettings in tests README
Follows-up 1cff4a15a7.

There is no such file to copy, delete from README.

Change-Id: I1fa0ac574743f5dbd577653aa74d416ca4609aa8
2019-05-13 11:52:55 +00:00
WMDE-Fisch a498423f90 Avoid popups on self links with file extension
This fixes page previews appearing when there is self link to a page
that has a file extension in it's name.

Bug: T222869
Change-Id: I5caf610fa76986026948a5b7b55537723752b755
2019-05-10 18:02:50 +02:00
WMDE-Fisch 1879a4d59e Show referencePreviews on click
Introducing the REFERENCE_CLICK action that will fetch and show the
preview for the clicked reference right away without any delay.

The main goal of the new chain of events introduced with the reference
click is showing the reference preview right away. The actions triggered
by the dwelling include delays in multiple parts of the process.

If there's a dwell action-chain in progress when the click action is
executed, the related promise ( that might still include steps with
delays ) and the reference preview is retrieved and shown right away
re-using the token. 

In the case where there's no dwell action running ( e.g. when the click
was triggered via touch ) we create a new token and start from scratch.

In either case we want to avoid, that multiple clicks trigger multiple
actions and abort early when there's already a click action in progress.

Bug: T218765
Change-Id: I073a93be2d17a21178aebe12267765f60a2811b9
2019-04-29 17:46:49 +00:00
Thiemo Kreuz 8305eb8634 Minimize createStubTitle() helper method
Pretty much all usages of this function do *not* use the second
parameter to pass a page name prefixed with a namespace, but pass the
page name only.

This patch here removes the redundancy. The namespace prefix is now a
generated one, saying "Namespace <number>:…". It turns out no test
relies on this so far.

Bug: T220097
Change-Id: Ibd45d49c91e86a2647afe676a5e3bb07dfeab6ed
2019-04-26 07:45:13 -06:00
WMDE-Fisch 6c535739bf Use title.getNameText() to compare selflinks
config.get( 'wgTitle' ) returns the unnormalized title of the current
page while title.getName() gets the normalized title (e.g. with underscores ).

On pages with spaces in the check failed before this patch.

Bug: T220097
Change-Id: I58a532627bb27be030cbc553f1181a89109edd80
2019-04-26 13:58:08 +02:00
WMDE-Fisch 35aa05afee Use title and namespace id to check if link is current page
Bug: T220097
Change-Id: Ieffd6a02b4126f6713610e968d662516499d4998
2019-04-23 15:17:06 +02:00
Adam Wight 0acc8db529 Decode fragment, needed for multilingual named references
Named references may include non-ascii characters, so we decode the fragment before matching against reference IDs.

Bug: T220196
Change-Id: I63bba59fa8f0f6aa95aeadbb1f85745d480988bd
2019-04-23 11:39:30 +02:00
Timo Tijhof 81b94eff0a Remove redundant wgPopupsShouldSendModuleToUser variable
It is set based on the same conditional that loads the code,
thus checking it inside the loaded code is a no-op and adds
extra HTML to the <head> that blocks text/layout rendering and
delays fetching of Popups JS.

Bug: T219342
Change-Id: I9c1f4b3861ce2cecb654eb0a78469a616730a40b
2019-04-09 18:31:35 +00:00
WMDE-Fisch 5a38638388 Fix module load script and remove pause
I just realized on another test set, that this is actually not implemented
in a way where it is working correctly. The return value of the browser.exectue()
is returned as part of an object and not directly. So the condition was always
true and the wait until did not really wait for anything.

As a result I'm quite confident the pause is not necessary.

Change-Id: I274bdee0b3c39c418a2b61881d56f89889c53485
2019-04-08 21:17:53 +02:00
WMDE-Fisch 79ee43fbeb Avoid exception when checking for loaded modules
The test would lead to an exception when 'mediaWiki' is not defined. The
exception would then also abort the whole execution so in this context it's
safer to use typeof with 'undefined'.

When the mediaWiki js base is loaded though, loader.getState() is guaranteed
to be available since it is part of the root module.

This also uses "mw" instead of "mediaWiki" for consistency in test.

Change-Id: I1262d0b5c4a1136f4d2294f125336e72118c6e2c
2019-04-08 19:51:11 +02:00
WMDE-Fisch b3a58a6dd3 Move browser tests loading steps to beforeEach
- test page loading and waiting for the scripts moved to beforeEach
- removed unnecessary abondonLink call
- removed unnecessary browser.pause()

Change-Id: I28eb7b9b48f105315bf41f7a41e5a1e6ec21cb2b
2019-04-05 15:56:16 +00:00
Thiemo Kreuz 511c74bf72 Make sure to never trigger multiple events
I had to disable ESLint to be allowed to upload this patch. It starts
complaining about something in code I did not even touched. The error
message does not make any sense to me (something about globals being
forbidden in code where I can not spot anything that would be remotely
global).

Change-Id: I6d4b178a65126c4b81b87d99142a6cdc845ae5ee
2019-03-26 12:39:28 -06:00
Thiemo Kreuz 522f4aa8a2 Fix incomplete test coverage for referencePreview renderer
Two big chunks of code (the "click" and "scroll" event handlers) have
not been covered with QUnit tests before. I found this was not that
complicated and worth the effort.

Note we already have browser tests in place for these features. These
are still required because the scroll feature can not fully be tested
when the popup is not actually rendered on screen.

Bug: T214971
Change-Id: I58111489fe6c4bed65efec59f9fc4184c828b2b3
2019-03-26 16:54:17 +01:00
jenkins-bot 70ebaa221e Merge "Move test for escaped URLs into seperate check" 2019-03-26 13:25:11 +00:00
WMDE-Fisch de8f7a133c Move test for escaped URLs into seperate check
With this I want to pull apart testing two things at one, checking if the
URL is escaped and if it is put to the right position.

So this adds an explicit test, that makes sure that urls in the popup are
escaped safely and lets the big test become more general in that regard.

Bug: T214971
Change-Id: I09b5225a8370e8b1337b2cf6ca03ccb79b3a64aa
2019-03-25 16:24:26 +01:00
WMDE-Fisch 07318c3a33 Add test for dwelling reference links inside a reference preview
Bug: T214971
Change-Id: Ib2f782a67d85647a385f81d5d5fca89b221a9e22
2019-03-25 12:37:05 +00:00
WMDE-Fisch dc1625de64 Add tests for the reference preview fade effect
Bug: T214971
Change-Id: Ie59347e7f51d449900d3a107fd85b0753a14f449
2019-03-25 12:36:47 +00:00
WMDE-Fisch 2cff0a1a8e Simplify testpage setup for browser test
For the reference preview tests we extended that with a lot of stuff
that we do not really use in the tests atm. Lets only have stuff in there
that's really relevant for the tests.

Change-Id: I03c6e00445e9bfe48572fd1b19a7ef1ecd472f4e
2019-03-25 12:36:26 +00:00
Andrew Kostka 42ee00fe37 Improve popup pointer positioning
Bug: T217737
Change-Id: Id478b8cc8dc7aefdd07dde5d5567aa0a1d8ee970
2019-03-20 10:39:18 +00:00
Jan Drewniak 8aad5981e4 Fix double pokey bug
When a thumbnail in portrait-mode is narrower than the 200px
expected width, the SVG clip-path should be shifted on the x-axis
in order to align with the thumbnail image.

Adds extra test-cases to validate this logic.

Bug: T204627
Change-Id: I9359c9fb335e5fad3f7d5ba33ee89d2a1f26b8b2
2019-03-20 01:29:46 +00:00
Thiemo Kreuz 1d2becc25a Consistently talk about "Reference" instead of "Footnote"
During story time on 2019-03-12 it was decided to consistently talk
about "References" in all messages. Main motivation is that this is
the term the community is most familiar with, and it is also the term
that is used in reference section headings most of the time.

Bug: T215063
Change-Id: Iaab8d2c0da1546a3c9d27bc8e2e1c784050ed135
2019-03-13 09:29:26 +01:00
WMDE-Fisch 0d2d6d4c9b Move getPreviewType form gateway to model
The method itself has not much to do with gateways as such, it's
more about the general preview type selection. Since the preview
types "live" in the model, I thought it might good to move it there.

Doing that the "original" getPreviewType method in the model was renamed
to avoid conflicts. If I get this right, that method is quite specific to
page previews, since it processes the output from the TextExtracts API-
request. - Therefore I also removed the TYPE_REFERENCE there, because this
code path will never be reached with that type afaik.

Inspired by the comments in Id1fa7dad59d8fe80bc60c1e2d7c3fb4087e52d1f and
as preparation for that patch.

Bug: T215420
Change-Id: Ic9e24a73e945c7d56435c656ecfdb42b65601d22
2019-03-12 08:28:46 -06:00