3 namespace Drupal\Tests\views_ui\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\simpletest\NodeCreationTrait;
7 use Drupal\views\Entity\View;
8 use Drupal\views\Tests\ViewTestData;
11 * Tests the display UI.
15 class DisplayTest extends WebDriverTestBase {
17 use NodeCreationTrait;
22 public static $modules = [
31 public static $testViews = ['test_content_ajax', 'test_display'];
36 public function setUp() {
39 ViewTestData::createTestViews(self::class, ['views_test_config']);
41 $admin_user = $this->drupalCreateUser([
42 'administer site configuration',
45 'access content overview',
46 'access contextual links',
49 // Disable automatic live preview to make the sequence of calls clearer.
50 \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
51 $this->drupalLogin($admin_user);
55 * Tests adding a display.
57 public function testAddDisplay() {
58 $this->drupalGet('admin/structure/views/view/test_content_ajax');
59 $page = $this->getSession()->getPage();
61 $page->find('css', '#views-display-menu-tabs .add')->click();
63 // Wait for the animation to complete.
64 $this->assertSession()->assertWaitOnAjaxRequest();
67 $page->find('css', '#edit-displays-top-add-display-block')->click();
69 $element = $page->findById('views-display-menu-tabs')->findLink('Block');
70 $this->assertNotEmpty($element);
74 * Tests contextual links on Views page displays.
76 public function testPageContextualLinks() {
77 $view = View::load('test_display');
78 $view->enable()->save();
79 $this->container->get('router.builder')->rebuildIfNeeded();
81 // Create node so the view has content and the contextual area is higher
83 $this->drupalCreateContentType(['type' => 'page']);
86 // When no "main content" block is placed, we find a contextual link
87 // placeholder for editing just the view.
88 $this->drupalGet('test-display');
89 $page = $this->getSession()->getPage();
90 $this->assertSession()->assertWaitOnAjaxRequest();
92 $selector = '.view-test-display';
93 $this->toggleContextualTriggerVisibility($selector);
95 $element = $this->getSession()->getPage()->find('css', $selector);
96 $element->find('css', '.contextual button')->press();
98 $contextual_container_id = 'entity.view.edit_form:view=test_display:location=page&name=test_display&display_id=page_1&langcode=en';
99 $contextual_container = $page->find('css', '[data-contextual-id="' . $contextual_container_id . '"]');
100 $this->assertNotEmpty($contextual_container);
102 $edit_link = $contextual_container->findLink('Edit view');
103 $this->assertNotEmpty($edit_link);
105 // When a "main content" is placed, we still find a contextual link
106 // placeholder for editing just the view (not the main content block).
107 // @see system_block_view_system_main_block_alter()
108 $this->drupalPlaceBlock('system_main_block', ['id' => 'main_content']);
109 $contextual_container = $page->find('css', '[data-contextual-id="' . $contextual_container_id . '"]');
110 $this->assertNotEmpty($contextual_container);
114 * Toggles the visibility of a contextual trigger.
116 * @param string $selector
117 * The selector for the element that contains the contextual Rink.
119 protected function toggleContextualTriggerVisibility($selector) {
120 // Hovering over the element itself with should be enough, but does not
121 // work. Manually remove the visually-hidden class.
122 $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');");