Problem/Motivation

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

assertAnnounceContains

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

oknate created an issue. See original summary.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

oknate’s picture

Issue summary: View changes
StatusFileSize
new11.59 KB

Here's a patch for this.

oknate’s picture

duplicate message, ignore

oknate’s picture

Status: Active » Needs review
oknate’s picture

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

<div id="drupal-live-announce" class="visually-hidden" aria-live="polite" aria-busy="false">Hello, Bruce</div>
oknate’s picture

I use a slightly different helper function in this patch: https://www.drupal.org/files/issues/2019-10-21/3087305--interdiff-12-21.txt

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

Believe this is still a valid request but will need to be updated for D10

smustgrave’s picture

Component: ajax system » phpunit
Status: Needs work » Needs review
StatusFileSize
new3.44 KB
new11.36 KB

Rerolled.

Also think this falls under unit testing more

darvanen’s picture

Is 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

smustgrave’s picture

Correct I believe the intention was to move those announce functions into a single trait.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

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

smustgrave’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new1000 bytes
new11.31 KB

patch #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

borisson_’s picture

Status: Needs review » Needs work

I found one super small nitpick

+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFilterTest.php
@@ -131,9 +134,7 @@ public function testBlockFilter() {
     $announce_element = $page->find('css', '#drupal-live-announce');

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.

dtfabio’s picture

Assigned: Unassigned » dtfabio
Status: Needs work » Active
dtfabio’s picture

Assigned: dtfabio » Unassigned
Status: Active » Needs review
StatusFileSize
new10.1 KB
new10.1 KB

I am currently working with @borisson on an internal Calibrate contribution day, I have incorporated his suggestion.

dtfabio’s picture

StatusFileSize
new798 bytes

I had added all the changes to the interdiff, my apologies here is the correct file.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new11.35 KB

Looks like the file was not complete, combined #19 and the interdiff in #23.

longwave’s picture

Status: Reviewed & tested by the community » Needs review

There 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

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

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

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Issue tags: +ddd2023

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

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.