Commit f9445b46 authored by webchick's avatar webchick
Browse files

Issue #2919147 by tedbow, tim.plunkett: When edit mode is enabled new page...

Issue #2919147 by tedbow, tim.plunkett: When edit mode is enabled new page loads will not have Contextual tabbing constrained
parent 35de151d
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
this.listenTo(this.model, 'change:isViewing', this.manageTabbing); this.listenTo(this.model, 'change:isViewing', this.manageTabbing);
$(document).on('keyup', _.bind(this.onKeypress, this)); $(document).on('keyup', _.bind(this.onKeypress, this));
this.manageTabbing();
}, },
/** /**
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
this.listenTo(this.model, 'change:isViewing', this.manageTabbing); this.listenTo(this.model, 'change:isViewing', this.manageTabbing);
$(document).on('keyup', _.bind(this.onKeypress, this)); $(document).on('keyup', _.bind(this.onKeypress, this));
this.manageTabbing();
}, },
render: function render() { render: function render() {
this.$el.find('button').attr('aria-pressed', !this.model.get('isViewing')); this.$el.find('button').attr('aria-pressed', !this.model.get('isViewing'));
......
...@@ -44,27 +44,45 @@ protected function setUp() { ...@@ -44,27 +44,45 @@ protected function setUp() {
} }
/** /**
* Tests that Drupal.announce messages appear. * Tests enabling and disabling edit mode.
*/ */
public function testAnnounceEditMode() { public function testEditModeEnableDisalbe() {
$web_assert = $this->assertSession(); $web_assert = $this->assertSession();
$this->drupalGet('user'); $page = $this->getSession()->getPage();
// Get the page twice to ensure edit mode remains enabled after a new page
// After the page loaded we need to additionally wait until the settings // request.
// tray Ajax activity is done. for ($page_get_count = 0; $page_get_count < 2; $page_get_count++) {
$web_assert->assertWaitOnAjaxRequest(); $this->drupalGet('user');
$expected_restricted_tab_count = 1 + count($page->findAll('css', '[data-contextual-id]'));
// Enable edit mode.
$this->pressToolbarEditButton(); // After the page loaded we need to additionally wait until the settings
$this->assertAnnounceEditMode(); // tray Ajax activity is done.
// Disable edit mode. $web_assert->assertWaitOnAjaxRequest();
$this->pressToolbarEditButton();
$this->assertAnnounceLeaveEditMode(); if ($page_get_count == 0) {
// Enable edit mode again. $unrestricted_tab_count = $this->getTabbableElementsCount();
$this->pressToolbarEditButton(); $this->assertGreaterThan($expected_restricted_tab_count, $unrestricted_tab_count);
// Finally assert that the 'edit mode enabled' announcement is still correct
// after toggling the edit mode at least once. // Enable edit mode.
$this->assertAnnounceEditMode(); // After the first page load the page will be in edit mode when loaded.
$this->pressToolbarEditButton();
}
$this->assertAnnounceEditMode();
$this->assertSame($expected_restricted_tab_count, $this->getTabbableElementsCount());
// Disable edit mode.
$this->pressToolbarEditButton();
$this->assertAnnounceLeaveEditMode();
$this->assertSame($unrestricted_tab_count, $this->getTabbableElementsCount());
// 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();
$this->assertSame($expected_restricted_tab_count, $this->getTabbableElementsCount());
}
} }
/** /**
...@@ -100,4 +118,20 @@ protected function assertAnnounceLeaveEditMode() { ...@@ -100,4 +118,20 @@ protected function assertAnnounceLeaveEditMode() {
$web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of'); $web_assert->elementNotContains('css', static::ANNOUNCE_SELECTOR, 'Tabbing is constrained to a set of');
} }
/**
* Gets the number of elements that are tabbable.
*
* @return int
* The number of tabbable elements.
*/
protected function getTabbableElementsCount() {
// Mark all tabbable elements.
$this->getSession()->executeScript("jQuery(':tabbable').attr('data-marked', '');");
// Count all marked elements.
$count = count($this->getSession()->getPage()->findAll('css', "[data-marked]"));
// Remove set attributes.
$this->getSession()->executeScript("jQuery('[data-marked]').removeAttr('data-marked');");
return $count;
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment