Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We need to start covering existing JavaScript functionality within Views with tests. See #2752931: [meta] Implement Javascript testing for Views and the Views UI
This is about adding test coverage to the basic search functionality in the Views filter listing.
Proposed resolution
Add a filter handler via the UI. Search the list with both the selector and the text field. Add one. Expose it, see if it gets added to the list.
Remaining tasks
- Commit #44 2754985-46.9_x-only.patch to 9.y.x branches
- Commit #44 2754985-46.8_x-only.patch to 8.y.x branch
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#46 | 2754985-46.8_x-only.patch | 5.18 KB | dww |
#46 | 2754985-46.9_x-only.patch | 5.18 KB | dww |
Comments
Comment #2
LendudeThis is a start. This fails because for some reason the post request for adding the filter gets done by the anonymous user. Haven't figured out what is going wrong yet.
Comment #4
LendudeI also see that the form submission that fails doesn't contain any of the form data (form-id etc.). Using other ways to trigger submission (directly triggering submitting the form via jQuery, clicking the hidden submit button that's actually inside the form element) doesn't solve this problem so far.
Comment #5
LendudeThe reason was #2771547: In Browser and FunctionalJavascript tests SIMPLETEST_USER_AGENT cookie needs to be set every 5 seconds, that's in now, so lets see what this does. Needs to go to 8.2.x though because the fix isn't in 8.1.x
Comment #8
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedI looked into it and found 1 actual Javascript bug:
Which is an error triggered in:
core/misc/dialog/dialog.position.js - line 59.
Reproducable with the following steps:
1. Open add filter
2. Check body (body) filter
3. Click Add and configure button
4. Resize your window
I think that this JavaScript error is the cause for the test failure. The problem occurs when clicking the Apply button. This closes the dialog and causes the error. I have seen the error in the test if you change the pressButton('Apply') to:
Which should work just fine but somehow triggers the Javascript error.
... update:
There is a bug open for the dialog error: #2731419: "cannot call methods on dialog prior to initialization" logged when resizing after closing a modal
When applied I can extract the HTML but the test still failes. Will search some more tomorrow..
Comment #9
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commented... update 2:
I found the actual (javascript) bug, not sure yet on how to fix it.
A new dialog is opened after adding the body field but the previous one isn't closed. This causes the dialog:beforeclose event not to be fired and the window not unbinding the 'dialogResize' event. On the second dialog 2 events are attached to the window, the first causing errors..
update:
Dug a little deeper. The dialogs are opened via commands. However, no close command is send.
To fix this either one of the following must be done:
1. In views, send a closeDialog command before the open command to properly close it before opening it.
2. Adapt the dialog open to check if there already is a dialog with the passed selector open and close it first
3. Change the dialog.position javascript to only add the event once per dialog selector.
Option 1 seems the right way to go but I'm not sure yet on UX, wil the dialog quickly open/close and 'flicker'?
Options 2 and 3 seem quite large in scope and will dig deep into the core javascript, they will provide somewhat better DX though and possibly UX as you don't have to worry about opening dialogs that currently exist and no flickering will be visible..
Comment #10
LendudeNice digging around! Discussed this with @michielnugter on IRC.
Option 1 sounds like the the best way to do this, but we indeed need to check for a flicker. It might not be perceptible and it just sounds like the best way to clean up after ourselves.
Bumping this to a bug, lets update the IS when we have a concrete description of the bug we are running into.
We should probably postpone on #2731419: "cannot call methods on dialog prior to initialization" logged when resizing after closing a modal, but hopefully that will get in soon.
Comment #11
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedVERY dirty fix for the popup in this case just to see if it fixes the problems. They don't unfortunately :(
What we learned:
- Yes, there is a small flicker sometimes, more that without the close. The dialog seems to align from the bottom of my screan to the center. Doesn't happen each time but it seems far more frequent than without the close.
- Yes there is a bug: as it's not related to this issue I think we should open a new one and discuss the solution there as I'm not sure requiring a closeDialog is DX / UX friendly.
- Despite the bugs the test still failes with PhantomJS responding the the following 500 error:
There is a warning on the preview in the logs but the preview is disabled in the test:
I couldn't find any other warning in my server logs.
I'm completely stuck here on finding the problem.
Comment #12
michielnugter CreditAttribution: michielnugter as a volunteer and at Synetic commentedI did a small cleanup of the test by the way but I think the final version should be postponed untill #2837676: Provide a better way to validate all javascript activity is completed is in.
Comment #13
LendudeWe should really split the handler search part of this test of into its own test. Might be happening in #2846428: Views add dialog filter searches on label instead of title
Comment #19
LendudeNot postponed anymore
Comment #20
LendudeAs in all things javascript test related, just wait and the problem will go away :)
Tweaked #2 a bit for WebDriver vs the old PhantomJs setup.
Running this with WebDriverTestBase gives no problems locally, so lets see if the bot agrees
Comment #21
LendudeAlso removed the other wait call
Comment #22
longwaveTest looks good and this unblocks #2839440: Exposed filter criteria gives InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects. in Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback() where we need a test for a bug fix.
Comment #23
xjmThe fail on D9 is:
Comment #24
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedHere I have tried to fix failed tests for Drupal 9.1.x.
Comment #25
longwaveThanks for the patch!
There should be no space between () and :, i.e.
Comment #26
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedHere I have addressed comment #25.
Comment #27
longwaveLooks good.
Comment #28
dwwMostly looks good, thanks! A few concerns / nits:
s/Test/Tests/
We don't seem to use this variable anywhere, let's remove it.
According to @Lendude at #2842525-80: Ajax attached to Views exposed filter form does not trigger callbacks we should avoid assertWaitOnAjaxRequest() whenever possible.
Why NULL on failure? Why not just @return bool and use FALSE if we time out before we get the right count?
Why bother with a local $result variable? Why not just:
Same here. Why not FALSE on failure?
Same here... why have $result at all?
Comment #29
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commentedaddressed comment #28
please review the patch.
Comment #30
LendudeIt's not that we should just remove it, it's that we should replace it with more specific waitForX methods when possible.
Comment #32
LendudeFixed the test and a small typo.
Comment #33
kishor_kolekar CreditAttribution: kishor_kolekar as a volunteer and at QED42 for Drupal India Association commented@Lendude Thanks for #30
Comment #34
dwwre #29 / #30 Sorry I wasn't clear. I meant to paste the relevant quote, but forgot:
So yeah, thanks for #32!
All the changes since my review now look great, and all feedback addressed. I tried this manually on the 9.1.x branch, and it applies and passes there, too (no sense wasting 1.25 hours of bot cycles to tell us that).
RTBC!
Comment #35
dwwActually, if we're targeting 8.y.x, we need another version of this without the
:void
typehint insetUp()
, or we break stuff on PHP 7.0. Anyone else want to re-roll so I can still re-RTBC?#32 is still RTBC for 9.y.x branches, but we should probably have the backports ready before this is committed.
Thanks/sorry,
-Derek
Comment #36
dwwOh, FFS, this is ridiculous. I'm just gonna fix it and self-RTBC. I think I can be trusted to do a 5 byte fix myself. ;)
Comment #37
dwwGreat, so the bot results agree with me. ;) #32 fails on PHP 7.0, but #36 passes.
Updated with a proper summary, including links to which patch is RTBC for which branch.
Enjoy,
-Derek
Comment #39
lauriiiDo we have a pre-existing pattern to define durations in milliseconds? Just wondering because it seems potentially confusing to have different unit in comparison to Mink.
Any thoughts on using the button text instead of
.button--primary
for selecting which button to press? This would make it easier for us to run this test on other themes (it's more likely they'll customize the button class compared to customizing the text).Comment #40
dwwRe: #39:
1. Patch #32 is correct for 9.1.x and 9.0.x. As I tried to make clear (both in my comments and in the summary), #36 is only the D8 backport.
2. Yes, tons. See
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
and search for 'milliseconds'. Everywait*()
method core already provides does it this way.3. We only test this with Stark, so I'm not sure that it matters. I'm also slightly worried that there might be a lot of 'Add' buttons. ;) The existing seems more resilient.
Thanks,
-Derek
Comment #43
quietone CreditAttribution: quietone as a volunteer commentedSetting to NW because the patch for 9.1.x, in #36, has a failing test.
Comment #44
dwwUploading #32 as 2754985-44.9_x-only.patch
Uploading #36 as 2754985-44.8_x-only.patch
Re-updating the summary to continue to point to the right patches.
Hopefully everyone will be clear on what to test / commit where.
Thanks!
-Derek
Comment #45
lauriiiThank you for clarifying #39.1.
Re: #39.3: Isn't the button text "Add and configure filter criteria" which would be quite specific? We also use that for the Apply button few rows below, so why we couldn't use the same approach there? Stark is one of the themes we are allowed to change and for that reason we could change that class in the future.
Comment #46
dwwSure, that works. Tested locally on 9.1.x and 8.9.x.
Comment #47
Lendude#45 addressed, looks good, back to RTBC
Comment #49
lauriiiCommitted 1f522e2 and pushed to 9.2.x. Thanks!
Leaving open for backport.
Comment #50
dwwWonderful, thanks!
Comment #52
LendudeUnrelated fail in Drupal\Tests\media_library\FunctionalJavascript\WidgetUploadTest
Comment #54
lauriiiDiscussed with @catch and we agreed that this could be backported to 9.1.x. We also agreed to not backport this to 8.9.x because it's pretty much only open for critical issues at this point.