Problem/Motivation
We're starting to use variants of assertAnnounceContains to assert Drupal.Announce and its integration with Drupal.Message().add().

It would be good to have a test trait or add it to one of the base test classes. This will help us not duplicate code in different tests and standardize the way we're testing for this.
See Drupal\FunctionalJavascriptTests\Ajax\MessageCommandTest
Proposed resolution
Move assertAnnounceContains and assertAnnounceNotContains into it's own trait vs custom solutions for test modules.
Remaining tasks
per #25 update other places to use new trait.
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #3
oknateHere's a patch for this.
Comment #4
oknateduplicate message, ignore
Comment #5
oknateComment #6
oknateThis should handle aria-live, as that can change from 'polite; to 'assertive' :: assertAnnounceContains()
The test methods currently don't allow you to verify that attribute.
Comment #7
oknateI use a slightly different helper function in this patch: https://www.drupal.org/files/issues/2019-10-21/3087305--interdiff-12-21.txt
Comment #14
smustgrave commentedBelieve this is still a valid request but will need to be updated for D10
Comment #15
smustgrave commentedRerolled.
Also think this falls under unit testing more
Comment #16
darvanenIs this patch intended to replace all instances where #live-announce is used? If so there are some in these two methods masquerading as
waitForText([text])or$this->assertNotEmpty($assert_session->waitForText('[message]'))which break when they cannot be seen as I discovered in #2707291: Disable body-level scrolling when a dialog is open as a modal\Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::switchToMediaLibraryGrid
\Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::switchToMediaLibraryTable
\Drupal\Tests\media_library\FunctionalJavascript\EntityReferenceWidgetTest::testWidget
Comment #17
smustgrave commentedCorrect I believe the intention was to move those announce functions into a single trait.
Comment #18
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #19
smustgrave commentedpatch #15 no longer applied with
error: patch failed: core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php:123
error: core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php: patch does not apply
error: patch failed: core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFilterTest.php:114
error: core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFilterTest.php: patch does not apply
Comment #20
borisson_I found one super small nitpick
This line can be removed I think? It is only used for the check later in the test.
Otherwise this change looks great and is rtbc imo.
Comment #21
dtfabio commentedComment #22
dtfabio commentedI am currently working with @borisson on an internal Calibrate contribution day, I have incorporated his suggestion.
Comment #23
dtfabio commentedI had added all the changes to the interdiff, my apologies here is the correct file.
Comment #24
borisson_Looks like the file was not complete, combined #19 and the interdiff in #23.
Comment #25
longwaveThere are some more tests that look like they could be converted to use the new trait?
core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
core/modules/system/tests/src/FunctionalJavascript/ModuleFilterTest.php
core/modules/system/tests/src/FunctionalJavascript/ModuleUninstallFilterTest.php
core/tests/Drupal/FunctionalJavascriptTests/Ajax/CommandsTest.php
core/tests/Drupal/FunctionalJavascriptTests/Theme/ClaroViewsBulkOperationsTest.php
Comment #26
smustgrave commentedSearched for
->elementTextContains('css', '#drupal-live-announce'
and found 9 instances
Search for
$this->waitForElementTextContains('#drupal-live-announce'
found 2.
Guess those could be converted pretty easily here vs a follow up.
Comment #28
longwaveDiscussed with @lauriii at Drupal Dev Days when committing #2707291: Disable body-level scrolling when a dialog is open as a modal.
We think this should go directly into WebAssert instead of a trait, because we already have a number of status message assertions in WebAssert and we want to encourage people to use this; discovery is harder if this is in a separate trait.