From d38623d65948462f4d63cc2ba4f1192336cb0aa0 Mon Sep 17 00:00:00 2001
From: Kent Richards <22302-kentr@users.noreply.drupalcode.org>
Date: Fri, 28 Feb 2025 10:44:37 -0700
Subject: [PATCH 1/6] Issue #3085781: Add patch #37, by @kkalashnikov

---
 core/modules/toolbar/js/views/ToolbarVisualView.js     |  4 ++--
 .../FunctionalJavascript/ToolbarIntegrationTest.php    | 10 ++++++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/core/modules/toolbar/js/views/ToolbarVisualView.js b/core/modules/toolbar/js/views/ToolbarVisualView.js
index 89f472f0eafa..00bd236973f6 100644
--- a/core/modules/toolbar/js/views/ToolbarVisualView.js
+++ b/core/modules/toolbar/js/views/ToolbarVisualView.js
@@ -210,7 +210,7 @@
         // Deactivate the previous tab.
         $(this.model.previous('activeTab'))
           .removeClass('is-active')
-          .prop('aria-pressed', false);
+          .attr('aria-pressed', false);
         // Deactivate the previous tray.
         $(this.model.previous('activeTray')).removeClass('is-active');
 
@@ -222,7 +222,7 @@
           $tab
             .addClass('is-active')
             // Mark the tab as pressed.
-            .prop('aria-pressed', true);
+            .attr('aria-pressed', true);
           const name = $tab.attr('data-toolbar-tray');
           // Store the active tab name or remove the setting.
           const id = $tab.get(0).id;
diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
index c315f9f6ebb0..1598b1219eda 100644
--- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -44,10 +44,16 @@ public function testToolbarToggling(): void {
 
     // Test that it is possible to toggle the toolbar tray.
     $content = $page->findLink('Content');
+    $manage_link = $page->find('css', '#toolbar-item-administration');
+    $manage_link->getAttribute('aria-pressed');
+    $this->assertEquals('true', $manage_link->getAttribute('aria-pressed'));
+
     $this->assertTrue($content->isVisible(), 'Toolbar tray is open by default.');
-    $page->clickLink('Manage');
+    $manage_link->click();
+    $this->assertEquals('false', $manage_link->getAttribute('aria-pressed'));
     $this->assertFalse($content->isVisible(), 'Toolbar tray is closed after clicking the "Manage" link.');
-    $page->clickLink('Manage');
+    $manage_link->click();
+    $this->assertEquals('true', $manage_link->getAttribute('aria-pressed'));
     $this->assertTrue($content->isVisible(), 'Toolbar tray is visible again after clicking the "Manage" button a second time.');
 
     // Test toggling the toolbar tray between horizontal and vertical.
-- 
GitLab


From f775f1ef906c08bcc9d6cbf678763b349a8eb1ba Mon Sep 17 00:00:00 2001
From: Kent Richards <22302-kentr@users.noreply.drupalcode.org>
Date: Fri, 28 Feb 2025 20:14:10 -0700
Subject: [PATCH 2/6] Issue #3085781: Apply review notes #40 by @bnjmnm

---
 .../ToolbarIntegrationTest.php                | 52 ++++++++++++++++---
 1 file changed, 44 insertions(+), 8 deletions(-)

diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
index 1598b1219eda..ed0adc6a50e2 100644
--- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -4,6 +4,7 @@
 
 namespace Drupal\Tests\toolbar\FunctionalJavascript;
 
+use Behat\Mink\Element\NodeElement;
 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 
 /**
@@ -43,18 +44,22 @@ public function testToolbarToggling(): void {
     $page = $this->getSession()->getPage();
 
     // Test that it is possible to toggle the toolbar tray.
-    $content = $page->findLink('Content');
+    $content_link = $page->findLink('Content');
     $manage_link = $page->find('css', '#toolbar-item-administration');
-    $manage_link->getAttribute('aria-pressed');
-    $this->assertEquals('true', $manage_link->getAttribute('aria-pressed'));
 
-    $this->assertTrue($content->isVisible(), 'Toolbar tray is open by default.');
+    // Start with open tray.
+    $this->waitAndAssertAriaPressedState($manage_link, TRUE);
+    $this->assertTrue($content_link->isVisible(), 'Toolbar tray is open by default.');
+
+    // Click to close.
     $manage_link->click();
-    $this->assertEquals('false', $manage_link->getAttribute('aria-pressed'));
-    $this->assertFalse($content->isVisible(), 'Toolbar tray is closed after clicking the "Manage" link.');
+    $this->waitAndAssertAriaPressedState($manage_link, FALSE);
+    $this->assertFalse($content_link->isVisible(), 'Toolbar tray is closed after clicking the "Manage" link.');
+
+    // Click to open.
     $manage_link->click();
-    $this->assertEquals('true', $manage_link->getAttribute('aria-pressed'));
-    $this->assertTrue($content->isVisible(), 'Toolbar tray is visible again after clicking the "Manage" button a second time.');
+    $this->waitAndAssertAriaPressedState($manage_link, TRUE);
+    $this->assertTrue($content_link->isVisible(), 'Toolbar tray is visible again after clicking the "Manage" button a second time.');
 
     // Test toggling the toolbar tray between horizontal and vertical.
     $tray = $page->findById('toolbar-item-administration-tray');
@@ -93,4 +98,35 @@ public function testEmptyTray(): void {
     $this->assertFalse($button->isVisible(), 'Orientation toggle from other tray is not visible');
   }
 
+  /**
+   * Asserts that an element's `aria-pressed` attribute matches expected state.
+   *
+   * Uses `waitFor()` to pause until either the condition is met or the timeout
+   * of `1` second has passed.
+   *
+   * @param NodeElement $element
+   *   The element to be tested.
+   * @param bool $expected
+   *   The expected value of `aria-pressed`, as a boolean.
+   * @throws ExpectationFailedException
+   */
+  private function waitAndAssertAriaPressedState(NodeElement $element, $expected): void {
+    $this->assertTrue(
+      $this
+        ->getSession()
+        ->getPage()
+        ->waitFor(1, function() use ($element, $expected): bool {
+          $actual = $element->getAttribute('aria-pressed');
+
+          // Check for $expected == TRUE.
+          if ($expected) {
+            return $actual == 'true';
+          }
+
+          // Check for $expected == FALSE.
+          return $actual == 'false';
+        })
+    );
+  }
+
 }
-- 
GitLab


From b8f618c44122b1733c2fd5e16cdf561434d11881 Mon Sep 17 00:00:00 2001
From: Kent Richards <22302-kentr@users.noreply.drupalcode.org>
Date: Fri, 28 Feb 2025 20:23:13 -0700
Subject: [PATCH 3/6] Issue #3085781: Code style fixes

---
 .../tests/src/FunctionalJavascript/ToolbarIntegrationTest.php  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
index ed0adc6a50e2..66102556d52b 100644
--- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -104,10 +104,11 @@ public function testEmptyTray(): void {
    * Uses `waitFor()` to pause until either the condition is met or the timeout
    * of `1` second has passed.
    *
-   * @param NodeElement $element
+   * @param \Behat\Mink\Element\NodeElement $element
    *   The element to be tested.
    * @param bool $expected
    *   The expected value of `aria-pressed`, as a boolean.
+   *
    * @throws ExpectationFailedException
    */
   private function waitAndAssertAriaPressedState(NodeElement $element, $expected): void {
-- 
GitLab


From a2528c761ca260f4c45648d66152caea24a03973 Mon Sep 17 00:00:00 2001
From: Kent Richards <22302-kentr@users.noreply.drupalcode.org>
Date: Fri, 28 Feb 2025 20:31:30 -0700
Subject: [PATCH 4/6] Issue #3085781: Really fix code style issues

---
 .../tests/src/FunctionalJavascript/ToolbarIntegrationTest.php   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
index 66102556d52b..875b4f71051a 100644
--- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -116,7 +116,7 @@ private function waitAndAssertAriaPressedState(NodeElement $element, $expected):
       $this
         ->getSession()
         ->getPage()
-        ->waitFor(1, function() use ($element, $expected): bool {
+        ->waitFor(1, function () use ($element, $expected): bool {
           $actual = $element->getAttribute('aria-pressed');
 
           // Check for $expected == TRUE.
-- 
GitLab


From be23acdf178392aa3b893498dc1d07a56efeba46 Mon Sep 17 00:00:00 2001
From: Kent Richards <22302-kentr@users.noreply.drupalcode.org>
Date: Fri, 28 Feb 2025 20:34:55 -0700
Subject: [PATCH 5/6] Issue #3085781: Add type hint

---
 .../tests/src/FunctionalJavascript/ToolbarIntegrationTest.php   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
index 875b4f71051a..e33eb9fcd9b7 100644
--- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -111,7 +111,7 @@ public function testEmptyTray(): void {
    *
    * @throws ExpectationFailedException
    */
-  private function waitAndAssertAriaPressedState(NodeElement $element, $expected): void {
+  private function waitAndAssertAriaPressedState(NodeElement $element, bool $expected): void {
     $this->assertTrue(
       $this
         ->getSession()
-- 
GitLab


From 3582e4876c6936d86936696216c5d689d24312f0 Mon Sep 17 00:00:00 2001
From: Kent Richards <22302-kentr@users.noreply.drupalcode.org>
Date: Fri, 28 Feb 2025 20:44:17 -0700
Subject: [PATCH 6/6] Issue #3085781: Streamline
 waitAndAssertAriaPressedState()

---
 .../FunctionalJavascript/ToolbarIntegrationTest.php | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
index e33eb9fcd9b7..dcf0ff6d79c3 100644
--- a/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
+++ b/core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.php
@@ -117,15 +117,12 @@ private function waitAndAssertAriaPressedState(NodeElement $element, bool $expec
         ->getSession()
         ->getPage()
         ->waitFor(1, function () use ($element, $expected): bool {
-          $actual = $element->getAttribute('aria-pressed');
+          // Get boolean representation of `aria-pressed`.
+          // TRUE if `aria-pressed="true"`, FALSE otherwise.
+          $actual = $element->getAttribute('aria-pressed') == 'true';
 
-          // Check for $expected == TRUE.
-          if ($expected) {
-            return $actual == 'true';
-          }
-
-          // Check for $expected == FALSE.
-          return $actual == 'false';
+          // Exit `waitFor()` when $actual == $expected.
+          return $actual == $expected;
         })
     );
   }
-- 
GitLab