From 67e3c0dd907c17753a2997b9676f25acf74b926f Mon Sep 17 00:00:00 2001 From: Helena McCabe Date: Fri, 13 Apr 2018 17:41:41 -0500 Subject: [PATCH] Adds testing to Daniel's patch --- core/misc/ajax.es6.js | 2 +- core/misc/ajax.js | 2 +- core/modules/views_ui/src/ViewListBuilder.php | 8 ++++++++ .../views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index c3633b4636..d3de666e60 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -888,7 +888,7 @@ if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) { let target = false; - for (let n = elementParents.length - 1; !target && n > 0; n--) { + for (let n = elementParents.length - 1; !target && n >= 0; n--) { target = document.querySelector(`[data-drupal-selector="${elementParents[n].getAttribute('data-drupal-selector')}"]`); } diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 58759ac7a0..74b42051aa 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -420,7 +420,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) { var target = false; - for (var n = elementParents.length - 1; !target && n > 0; n--) { + for (var n = elementParents.length - 1; !target && n >= 0; n--) { target = document.querySelector('[data-drupal-selector="' + elementParents[n].getAttribute('data-drupal-selector') + '"]'); } diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php index 628408e997..b6f1077785 100644 --- a/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -178,6 +178,14 @@ public function getDefaultOperations(EntityInterface $entity) { } } + // ajax.js focuses automatically the data-drupal-selector element. When + // enabling the view again, focusing on the disable link doesn't work, as it + // is hidden. We assign data-drupal-selector to every link, so it focuses + // on the edit link. + foreach ($operations as &$operation) { + $operation['attributes']['data-drupal-selector'][] = 'views-listing-' . $entity->id(); + } + return $operations; } diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php index cab99bd7bc..98c226f84a 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/ViewsListingTest.php @@ -94,6 +94,7 @@ public function testFilterViewsListing() { $enabled_view = $page->find('css', 'tr.views-ui-list-enabled'); // Open the dropdown with additional actions. $enabled_view->find('css', 'li.dropbutton-toggle button')->click(); + $enabled_view_id = $enabled_view->getAttribute('data-drupal-view-id'); $disable_button = $enabled_view->find('css', 'li.disable.dropbutton-action a'); // Check that the disable button is visible now. $this->assertTrue($disable_button->isVisible()); @@ -109,6 +110,11 @@ public function testFilterViewsListing() { // Test that one enabled View has been moved to the disabled list. $this->assertCount($enabled_views_count - 1, $enabled_rows); $this->assertCount($disabled_views_count + 1, $disabled_rows); + + // Test that the keyboard focus is on the dropdown button of the View we + // just disabled. + $this->assertTrue($this->getSession()->evaluateScript("jQuery(document.activeElement).parent().is('li.enable.dropbutton-action')")); + $this->assertTrue($this->getSession()->evaluateScript("jQuery(document.activeElement).parents('tr.views-ui-list-disabled').data('drupal-view-id') == '$enabled_view_id'")); } /**