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:

  1. Try to login with invalid credentials
  2. 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.

Issue fork drupal-3212975

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mherchel created an issue. See original summary.

mherchel’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
2.87 KB
Neslee Canil Pinto’s picture

FileSize
552.23 KB

This 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

Gauravvvv’s picture

Re-rolled patch #2, attached interdiff for the same.

mherchel’s picture

Status: Needs review » Reviewed & tested by the community

#4 looks perfect. Thanks!

lauriii’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
126.05 KB

Where did you test this? I get following JS error when I try JS messages with the patch.

Gauravvvv’s picture

Hi Lauriii, I didn't get any console error message while tested with the given instructions.

Attached an after-patch screen recording.

mherchel’s picture

Status: Needs review » Needs work

Where did you test this? I get following JS error when I try JS messages with the patch.

I tested this with the shortcuts module, and by attempting to login with invalid credentials. What steps did you take to do "JS messages"?

lauriii’s picture

Issue tags: +Needs tests

I 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.

mherchel’s picture

I still cannot reproduce this problem.

mherchel’s picture

No tests yet, but here is the fix for the error in #6

mherchel’s picture

From @lauriii in Slack:

I think Drupal\FunctionalJavascriptTests\Core\JsMessageTest is the test you might want to use as a basis for your test

Gauravvvv’s picture

Status: Needs work » Needs review
andy-blum’s picture

I'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.

mherchel’s picture

mherchel’s picture

Issue summary: View changes

thejimbirch made their first commit to this issue’s fork.

mherchel’s picture

Status: Needs review » Needs work

Tests failed :(

marcoscano made their first commit to this issue’s fork.

marcoscano’s picture

Re-rolled the previous work for 9.3.x, no changes, on the 3212975-olivero-normalize-javascript branch. Tests will still fail.

marcoscano’s picture

Ah! Didn't realize the class inherited this :: testAddRemoveMessages test :P
More troubleshooting to do there then.

marcoscano’s picture

So the failure was

Testing Drupal\FunctionalJavascriptTests\Theme\OliveroMessagesTest
.F                                                                  2 / 2 (100%)

Time: 00:12.833, Memory: 4.00 MB

There was 1 failure:

1) Drupal\FunctionalJavascriptTests\Theme\OliveroMessagesTest::testAddRemoveMessages
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'This is a message of the type, status. You be the judge of its importance.'
+    0 => 'Status message This is a message of the type, status. You be the judge of its importance. Close message'
 )

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:96
/var/www/html/core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php:121
/var/www/html/core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php:55
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:722

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.

marcoscano’s picture

Status: Needs work » Needs review
andy-blum’s picture

Status: Needs review » Reviewed & tested by the community

With the exception of the issue spun off in #14, this all looks good to me. Moving to RTBC!

larowlan’s picture

Hiding patches now there's an MR

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs tests

Left a couple of questions on the MR

marcoscano’s picture

Addressed 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.)

geekygnr made their first commit to this issue’s fork.

geekygnr’s picture

The 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.

mherchel’s picture

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.

Thanks 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.

mtift’s picture

Status: Needs review » Reviewed & tested by the community

This MR looks fairly straightforward. I think it's ready,so setting it back to RTBC.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

Posted one minor comment on the MR.

mherchel’s picture

Status: Needs work » Needs review

Re-twiggerized the twig. Needs review once again on this commit https://git.drupalcode.org/project/drupal/-/merge_requests/943/diffs?com...

andy-blum’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2942404: Messages should have role=status instead of role=contentinfo

This 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

  • lauriii committed 5698e6f on 9.3.x
    Issue #3212975 by marcoscano, mherchel, thejimbirch, Gauravmahlawat,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5698e6f and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.