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.
Split off from #3153234: [Meta] Olivero JavaScript should be selecting [data-drupal-selector] attributes where possible
We need to be using [data-drupal-selector]
attribute selectors in messages.es6.js
Testing instructions:
- Try to login with invalid credentials
- Note the message that appears. Make sure it looks correct and the close (X) button works.
Remaining Tasks
We need tests for this. We should be able to use Drupal\FunctionalJavascriptTests\Core\JsMessageTest
as a basis for the tests.
Comment | File | Size | Author |
---|---|---|---|
#14 | mixed-source-messages.png | 75.82 KB | andy-blum |
#14 | all-js-messages.png | 35.62 KB | andy-blum |
#14 | all-php-messages.png | 45.75 KB | andy-blum |
#10 | Cursor_and_Status_Messages___Olivero-2.png | 177.62 KB | mherchel |
#10 | Cursor_and_Status_Messages___Olivero.png | 156.29 KB | mherchel |
Issue fork drupal-3212975
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mherchelPatch attached. Tugboat preview at https://3212975-messages-js-tbho9jrqqztqm3ordulbnwqxut4s7jsx.tugboat.qa/
Comment #3
Neslee Canil PintoThis seems to be working, used tugboat preview and followed the steps
1. The close button is working fine
2. [data-drupal-selector] attribute is been present too
Comment #4
Gauravvvv CreditAttribution: Gauravvvv at OpenSense Labs commentedRe-rolled patch #2, attached interdiff for the same.
Comment #5
mherchel#4 looks perfect. Thanks!
Comment #6
lauriiiWhere did you test this? I get following JS error when I try JS messages with the patch.
Comment #7
Gauravvvv CreditAttribution: Gauravvvv at OpenSense Labs commentedHi Lauriii, I didn't get any console error message while tested with the given instructions.
Attached an after-patch screen recording.
Comment #8
mherchelI tested this with the shortcuts module, and by attempting to login with invalid credentials. What steps did you take to do "JS messages"?
Comment #9
lauriiiI used this custom module for generating JS messages: https://github.com/zolhorvath/cd_tools/tree/master/modules/message. Let's also make sure that there's test coverage for the JS messages since based on #4 passing, we are potentially missing test coverage.
Comment #10
mherchelI still cannot reproduce this problem.
Comment #11
mherchelNo tests yet, but here is the fix for the error in #6
Comment #12
mherchelFrom @lauriii in Slack:
Comment #13
Gauravvvv CreditAttribution: Gauravvvv at OpenSense Labs commentedComment #14
andy-blumI'm noticing something a bit strange regarding the messages.
Everything works fine when messages are added in from PHP or from JS via Drupal.Message, but JS messages added in when PHP messages are already present are not properly placed. Screenshots are attached. All messages close as expected, and "nested" messages close when their parent is closed.
Comment #15
mherchelSplit off #14 into #3223264: Olivero: Messages can be malformed when JS creates messages and PHP messages already exist.
Comment #16
mherchelComment #19
mherchelTests failed :(
Comment #22
marcoscanoRe-rolled the previous work for 9.3.x, no changes, on the
3212975-olivero-normalize-javascript
branch. Tests will still fail.Comment #23
marcoscanoAh! Didn't realize the class inherited this
:: testAddRemoveMessages
test :PMore troubleshooting to do there then.
Comment #24
marcoscanoSo the failure was
I'm unfamiliar with this fix, but I'm guessing the behavior is the expected, and just the test needs to be adjusted to pass if the text we are searching is _included_ in the element's text, instead of being an exact match? I updated the test in this direction, seems to be green for me locally.
Comment #25
marcoscanoComment #26
andy-blumWith the exception of the issue spun off in #14, this all looks good to me. Moving to RTBC!
Comment #27
larowlanHiding patches now there's an MR
Comment #28
larowlanLeft a couple of questions on the MR
Comment #29
marcoscanoAddressed review feedback.
(I can't run tests right now so will rely on the testbot to check my changes. Apologies if it comes red for some reason.)
Comment #31
geekygnr CreditAttribution: geekygnr at Lullabot commentedThe issue described in #3212975-24: Olivero: Normalize JavaScript selectors in messages.es6.js bothered me as well and I wanted to dig into it.
The extra text is being added from a visually-hidden h2 that is injected via JS.
You can find the code for this in core/themes/olivero/js/messages.js (https://git.drupalcode.org/issue/drupal-3212975/-/blob/3212975-olivero-n...)
Since this text is known and controlled programmatically I would argue that its existence should be a part of a test. This also creates a bit of a rabbit hole of whether or not visually-hidden aspect of the text should also be tested and if the line between what is visually-hidden and not visually-hidden should be tested. The simple answer would be to alter the expected text to include the message label, the more complex answer would be to have a check in the test to confirm what is visually hidden and what isn't.
I am out of time for now but I can try to take a look at it later in the week. I would also support this being broken off into another issue and marking this as RTBC.
Comment #32
mherchelThanks for looking at this!
Feel free to open up a followup issue. TBH, this issue is just about changing the JS selectors and making sure it works, and IMO we've already had some significant scope creep.
Comment #33
mtiftThis MR looks fairly straightforward. I think it's ready,so setting it back to RTBC.
Comment #34
lauriiiPosted one minor comment on the MR.
Comment #35
mherchelRe-twiggerized the twig. Needs review once again on this commit https://git.drupalcode.org/project/drupal/-/merge_requests/943/diffs?com...
Comment #36
andy-blumThis looks good for the scope of this issue. Note that we may need to update that twig file for accessibility reasons per https://www.drupal.org/project/drupal/issues/2942404
Comment #38
lauriiiCommitted 5698e6f and pushed to 9.3.x. Thanks!