Verified Commit 529d4a64 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3112547 by andypost, dww, yogeshmpawar, Lendude, bnjmnm, danflanagan8,...

Issue #3112547 by andypost, dww, yogeshmpawar, Lendude, bnjmnm, danflanagan8, mglaman, joachim: Views UI tests should not rely on Classy

(cherry picked from commit 38ad49db)
parent f0d9ba00
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ class FieldUITest extends UITestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * Views used by this test.
@@ -44,7 +44,7 @@ public function testFieldUI() {
    // Ensure that the expected tokens appear in the UI.
    $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/age';
    $this->drupalGet($edit_handler_url);
    $xpath = '//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/ul/li';
    $xpath = '//details[@id="edit-options-alter-help"]/ul/li';
    $this->assertSession()->elementTextEquals('xpath', $xpath, '{{ age }} == Age');

    $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/id';
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ class HandlerTest extends UITestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * Views used by this test.
@@ -233,7 +233,7 @@ public function testBrokenHandlers() {
      $result = $this->assertSession()->elementTextEquals('xpath', "//a[contains(@href, '{$href}')]", $text);

      $this->drupalGet($href);
      $this->assertSession()->elementTextContains('xpath', '//h1[@class="page-title"]', $text);
      $this->assertSession()->elementTextContains('xpath', '//h1', $text);

      $original_configuration = [
        'field' => 'id_broken',
+12 −7
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ class PreviewTest extends UITestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * Tests contextual links in the preview form.
@@ -33,7 +33,11 @@ public function testPreviewContextual() {
    $this->submitForm($edit = [], 'Update preview');

    // Verify that the contextual link to add a new field is shown.
    $this->assertSession()->elementsCount('xpath', '//div[@id="views-live-preview"]//ul[contains(@class, "contextual-links")]/li[contains(@class, "filter-add")]', 1);
    $selector = $this->assertSession()->buildXPathQuery('//div[@id="views-live-preview"]//ul[contains(@class, :ul-class)]/li/a[contains(@href, :href)]', [
      ':ul-class' => 'contextual-links',
      ':href' => '/admin/structure/views/nojs/add-handler/test_preview/default/filter',
    ]);
    $this->assertSession()->elementsCount('xpath', $selector, 1);

    $this->submitForm($edit = ['view_args' => '100'], 'Update preview');

@@ -53,15 +57,16 @@ public function testPreviewUI() {

    $this->submitForm($edit = [], 'Update preview');

    $this->assertSession()->elementsCount('xpath', '//div[@class = "view-content"]/div[contains(@class, views-row)]', 5);
    $selector = '//div[@class = "views-row"]';
    $this->assertSession()->elementsCount('xpath', $selector, 5);

    // Filter just the first result.
    $this->submitForm($edit = ['view_args' => '1'], 'Update preview');
    $this->assertSession()->elementsCount('xpath', '//div[@class = "view-content"]/div[contains(@class, views-row)]', 1);
    $this->assertSession()->elementsCount('xpath', $selector, 1);

    // Filter for no results.
    $this->submitForm($edit = ['view_args' => '100'], 'Update preview');
    $this->assertSession()->elementNotExists('xpath', '//div[@class = "view-content"]/div[contains(@class, views-row)]');
    $this->assertSession()->elementNotExists('xpath', $selector);

    // Test that area text and exposed filters are present and rendered.
    $this->assertSession()->fieldExists('id');
@@ -111,12 +116,12 @@ public function testPreviewUI() {
    $this->assertSession()->assertEscaped($query_string);

    // Test that the statistics and query are rendered above the preview.
    $this->assertLessThan(strpos($this->getSession()->getPage()->getContent(), 'view-test-preview'), strpos($this->getSession()->getPage()->getContent(), 'views-query-info'));
    $this->assertLessThan(strpos($this->getSession()->getPage()->getContent(), 'js-view-dom-id'), strpos($this->getSession()->getPage()->getContent(), 'views-query-info'));

    // Test that statistics and query rendered below the preview.
    $settings->set('ui.show.sql_query.where', 'below')->save();
    $this->submitForm($edit = ['view_args' => '100'], 'Update preview');
    $this->assertLessThan(strpos($this->getSession()->getPage()->getContent(), 'views-query-info'), strpos($this->getSession()->getPage()->getContent(), 'view-test-preview'), 'Statistics shown below the preview.');
    $this->assertLessThan(strpos($this->getSession()->getPage()->getContent(), 'views-query-info'), strpos($this->getSession()->getPage()->getContent(), 'js-view-dom-id'), 'Statistics shown below the preview.');

    // Test that the preview title isn't double escaped.
    $this->drupalGet("admin/structure/views/nojs/display/test_preview/default/title");
+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class DisplayTest extends WebDriverTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  public static $testViews = ['test_content_ajax', 'test_display'];

@@ -94,7 +94,7 @@ public function testPageContextualLinks() {
    $page = $this->getSession()->getPage();
    $this->assertSession()->assertWaitOnAjaxRequest();

    $selector = '.view-test-display';
    $selector = '.views-element-container';
    $this->toggleContextualTriggerVisibility($selector);

    $element = $this->getSession()->getPage()->find('css', $selector);
+14 −13
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ class PreviewTest extends WebDriverTestBase {
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
@@ -197,14 +197,14 @@ public function testPreviewWithPagersUI() {
    // Verify elements and links to pages.
    // We expect to find current pages element with no link, next page element
    // with a link, and not to find previous page element.
    $this->assertClass($elements[0], 'is-active', 'Element for current page has .is-active class.');
    $this->assertEquals('Page 1', trim($elements[0]->getHtml()), 'Element for current page is not a link.');

    $this->assertClass($elements[1], 'pager__item--next', 'Element for next page has .pager__item--next class.');
    $this->assertNotEmpty($elements[1]->find('css', 'a'), 'Link to next page found.');
    $next_page_link = $elements[1]->find('css', 'a');
    $this->assertNotEmpty($next_page_link, 'Link to next page found.');
    $this->assertEquals('Go to next page', $next_page_link->getAttribute('title'));

    // Navigate to next page.
    $element = $this->assertSession()->elementExists('xpath', '//li[contains(@class, "pager__item--next")]/a');
    $this->clickPreviewLinkAJAX($element, 3);
    $this->clickPreviewLinkAJAX($next_page_link, 3);

    // Test that the pager is present and rendered.
    $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
@@ -213,14 +213,15 @@ public function testPreviewWithPagersUI() {
    // Verify elements and links to pages.
    // We expect to find 3 elements: previous page with a link, current
    // page with no link, and next page with a link.
    $this->assertClass($elements[0], 'pager__item--previous', 'Element for previous page has .pager__item--previous class.');
    $this->assertNotEmpty($elements[0]->find('css', 'a'), 'Link to previous page found.');
    $previous_page_link = $elements[0]->find('css', 'a');
    $this->assertNotEmpty($previous_page_link, 'Link to previous page found.');
    $this->assertEquals('Go to previous page', $previous_page_link->getAttribute('title'));

    $this->assertClass($elements[1], 'is-active', 'Element for current page has .is-active class.');
    $this->assertEmpty($elements[1]->find('css', 'a'), 'Element for current page has no link.');
    $this->assertEquals('Page 2', trim($elements[1]->getHtml()), 'Element for current page is not a link.');

    $this->assertClass($elements[2], 'pager__item--next', 'Element for next page has .pager__item--next class.');
    $this->assertNotEmpty($elements[2]->find('css', 'a'), 'Link to next page found.');
    $next_page_link = $elements[2]->find('css', 'a');
    $this->assertNotEmpty($next_page_link, 'Link to next page found.');
    $this->assertEquals('Go to next page', $next_page_link->getAttribute('title'));
  }

  /**
@@ -286,7 +287,7 @@ protected function clickPreviewLinkAJAX(NodeElement $element, $row_count) {
   * @internal
   */
  protected function assertPreviewAJAX(int $row_count): void {
    $elements = $this->getSession()->getPage()->findAll('css', '.view-content .views-row');
    $elements = $this->getSession()->getPage()->findAll('css', '#views-live-preview .views-row');
    $this->assertCount($row_count, $elements, 'Expected items found on page.');
  }

Loading