X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews_ui%2Ftests%2Fsrc%2FFunctionalJavascript%2FDisplayTest.php;fp=web%2Fcore%2Fmodules%2Fviews_ui%2Ftests%2Fsrc%2FFunctionalJavascript%2FDisplayTest.php;h=c8d37f21c3cae180ee91c1b086698ec317dd91c8;hp=0000000000000000000000000000000000000000;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a diff --git a/web/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php b/web/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php new file mode 100644 index 000000000..c8d37f21c --- /dev/null +++ b/web/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php @@ -0,0 +1,125 @@ +drupalCreateUser([ + 'administer site configuration', + 'administer views', + 'administer nodes', + 'access content overview', + 'access contextual links', + ]); + + // Disable automatic live preview to make the sequence of calls clearer. + \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save(); + $this->drupalLogin($admin_user); + } + + /** + * Tests adding a display. + */ + public function testAddDisplay() { + $this->drupalGet('admin/structure/views/view/test_content_ajax'); + $page = $this->getSession()->getPage(); + + $page->find('css', '#views-display-menu-tabs .add')->click(); + + // Wait for the animation to complete. + $this->assertSession()->assertWaitOnAjaxRequest(); + + // Add the diplay. + $page->find('css', '#edit-displays-top-add-display-block')->click(); + + $element = $page->findById('views-display-menu-tabs')->findLink('Block'); + $this->assertNotEmpty($element); + } + + /** + * Tests contextual links on Views page displays. + */ + public function testPageContextualLinks() { + $view = View::load('test_display'); + $view->enable()->save(); + $this->container->get('router.builder')->rebuildIfNeeded(); + + // Create node so the view has content and the contextual area is higher + // than 0 pixels. + $this->drupalCreateContentType(['type' => 'page']); + $this->createNode(); + + // When no "main content" block is placed, we find a contextual link + // placeholder for editing just the view. + $this->drupalGet('test-display'); + $page = $this->getSession()->getPage(); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $selector = '.view-test-display'; + $this->toggleContextualTriggerVisibility($selector); + + $element = $this->getSession()->getPage()->find('css', $selector); + $element->find('css', '.contextual button')->press(); + + $contextual_container_id = 'entity.view.edit_form:view=test_display:location=page&name=test_display&display_id=page_1&langcode=en'; + $contextual_container = $page->find('css', '[data-contextual-id="' . $contextual_container_id . '"]'); + $this->assertNotEmpty($contextual_container); + + $edit_link = $contextual_container->findLink('Edit view'); + $this->assertNotEmpty($edit_link); + + // When a "main content" is placed, we still find a contextual link + // placeholder for editing just the view (not the main content block). + // @see system_block_view_system_main_block_alter() + $this->drupalPlaceBlock('system_main_block', ['id' => 'main_content']); + $contextual_container = $page->find('css', '[data-contextual-id="' . $contextual_container_id . '"]'); + $this->assertNotEmpty($contextual_container); + } + + /** + * Toggles the visibility of a contextual trigger. + * + * @param string $selector + * The selector for the element that contains the contextual Rink. + */ + protected function toggleContextualTriggerVisibility($selector) { + // Hovering over the element itself with should be enough, but does not + // work. Manually remove the visually-hidden class. + $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');"); + } + +}