3 namespace Drupal\Tests\contextual\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
12 class EditModeTest extends JavascriptTestBase {
15 * CSS selector for Drupal's announce element.
17 const ANNOUNCE_SELECTOR = '#drupal-live-announce';
22 public static $modules = [
35 protected function setUp() {
38 $this->drupalLogin($this->createUser([
40 'access contextual links',
43 $this->placeBlock('system_powered_by_block', ['id' => 'powered']);
47 * Tests that Drupal.announce messages appear.
49 public function testAnnounceEditMode() {
50 $web_assert = $this->assertSession();
51 $this->drupalGet('user');
53 // After the page loaded we need to additionally wait until the settings
54 // tray Ajax activity is done.
55 $web_assert->assertWaitOnAjaxRequest();
58 $this->pressToolbarEditButton();
59 $this->assertAnnounceEditMode();
61 $this->pressToolbarEditButton();
62 $this->assertAnnounceLeaveEditMode();
63 // Enable edit mode again.
64 $this->pressToolbarEditButton();
65 // Finally assert that the 'edit mode enabled' announcement is still correct
66 // after toggling the edit mode at least once.
67 $this->assertAnnounceEditMode();
71 * Presses the toolbar edit mode.
73 protected function pressToolbarEditButton() {
74 $edit_button = $this->getSession()->getPage()->find('css', '#toolbar-bar div.contextual-toolbar-tab button');
75 $edit_button->press();
79 * Asserts that the correct message was announced when entering edit mode.
81 protected function assertAnnounceEditMode() {
82 $web_assert = $this->assertSession();
83 // Wait for contextual trigger button.
84 $web_assert->waitForElementVisible('css', '.contextual trigger');
85 $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of');
86 $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.');
90 * Assert that the correct message was announced when leaving edit mode.
92 protected function assertAnnounceLeaveEditMode() {
93 $web_assert = $this->assertSession();
94 $page = $this->getSession()->getPage();
95 // Wait till all the contextual links are hidden.
96 $page->waitFor(1, function () use ($page, $web_assert) {
97 return empty($page->find('css', '.contextual .trigger.visually-hidden'));
99 $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.');
100 $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of');