X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fcontextual%2Ftests%2Fsrc%2FFunctionalJavascript%2FEditModeTest.php;fp=web%2Fcore%2Fmodules%2Fcontextual%2Ftests%2Fsrc%2FFunctionalJavascript%2FEditModeTest.php;h=dc978aad1dc158a231ff1413930fe74fa3ce601c;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php b/web/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php new file mode 100644 index 000000000..dc978aad1 --- /dev/null +++ b/web/core/modules/contextual/tests/src/FunctionalJavascript/EditModeTest.php @@ -0,0 +1,103 @@ +drupalLogin($this->createUser([ + 'administer blocks', + 'access contextual links', + 'access toolbar', + ])); + $this->placeBlock('system_powered_by_block', ['id' => 'powered']); + } + + /** + * Tests that Drupal.announce messages appear. + */ + public function testAnnounceEditMode() { + $web_assert = $this->assertSession(); + $this->drupalGet('user'); + + // After the page loaded we need to additionally wait until the settings + // tray Ajax activity is done. + $web_assert->assertWaitOnAjaxRequest(); + + // Enable edit mode. + $this->pressToolbarEditButton(); + $this->assertAnnounceEditMode(); + // Disable edit mode. + $this->pressToolbarEditButton(); + $this->assertAnnounceLeaveEditMode(); + // Enable edit mode again. + $this->pressToolbarEditButton(); + // Finally assert that the 'edit mode enabled' announcement is still correct + // after toggling the edit mode at least once. + $this->assertAnnounceEditMode(); + } + + /** + * Presses the toolbar edit mode. + */ + protected function pressToolbarEditButton() { + $edit_button = $this->getSession()->getPage()->find('css', '#toolbar-bar div.contextual-toolbar-tab button'); + $edit_button->press(); + } + + /** + * Asserts that the correct message was announced when entering edit mode. + */ + protected function assertAnnounceEditMode() { + $web_assert = $this->assertSession(); + // Wait for contextual trigger button. + $web_assert->waitForElementVisible('css', '.contextual trigger'); + $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of'); + $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.'); + } + + /** + * Assert that the correct message was announced when leaving edit mode. + */ + protected function assertAnnounceLeaveEditMode() { + $web_assert = $this->assertSession(); + $page = $this->getSession()->getPage(); + // Wait till all the contextual links are hidden. + $page->waitFor(1, function () use ($page, $web_assert) { + return empty($page->find('css', '.contextual .trigger.visually-hidden')); + }); + $web_assert->elementContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is no longer constrained by the Contextual module.'); + $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of'); + } + +}