You are here

public function ParagraphsFeaturesTest::testDeleteConfirmation in Thunder 8.2

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/Integration/ParagraphsFeaturesTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ParagraphsFeaturesTest::testDeleteConfirmation()
  2. 8.3 tests/src/FunctionalJavascript/Integration/ParagraphsFeaturesTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ParagraphsFeaturesTest::testDeleteConfirmation()
  3. 8.4 tests/src/FunctionalJavascript/Integration/ParagraphsFeaturesTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ParagraphsFeaturesTest::testDeleteConfirmation()
  4. 6.2.x tests/src/FunctionalJavascript/Integration/ParagraphsFeaturesTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ParagraphsFeaturesTest::testDeleteConfirmation()
  5. 6.0.x tests/src/FunctionalJavascript/Integration/ParagraphsFeaturesTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ParagraphsFeaturesTest::testDeleteConfirmation()
  6. 6.1.x tests/src/FunctionalJavascript/Integration/ParagraphsFeaturesTest.php \Drupal\Tests\thunder\FunctionalJavascript\Integration\ParagraphsFeaturesTest::testDeleteConfirmation()

Testing of delete confirmation for paragraphs.

File

tests/src/FunctionalJavascript/Integration/ParagraphsFeaturesTest.php, line 29

Class

ParagraphsFeaturesTest
Tests the paragraph feature for delete confirmation dialog.

Namespace

Drupal\Tests\thunder\FunctionalJavascript\Integration

Code

public function testDeleteConfirmation() {
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->articleFillNew([
    'field_channel' => 1,
    'title[0][value]' => 'Article 1',
    'field_seo_title[0][value]' => 'Article 1',
  ]);

  // Add text paragraph with two elements.
  $this
    ->addTextParagraph(static::$paragraphsField, 'Test Delete Confirmation to delete text');
  $this
    ->addTextParagraph(static::$paragraphsField, 'Test Delete Confirmation to stay text');
  $this
    ->clickSave();
  $this
    ->drupalGet('node/10/edit');
  $customDeleteButton = $page
    ->find('xpath', '//div[contains(@id, "field-paragraphs-0-item-wrapper")]//button[contains(@class, "paragraph-form-item__action--remove")]');
  $hiddenDeleteButton = $page
    ->find('xpath', '//div[contains(@id, "field-paragraphs-0-item-wrapper")]//button[contains(@class, "paragraph-form-item__action--remove")]');
  $this
    ->assertTrue($customDeleteButton
    ->isVisible(), 'Delete button should be visible and not hidden behind drop-down');
  $this
    ->assertTrue($hiddenDeleteButton
    ->isVisible(), 'Default button from paragraphs should not be visible');
  $this
    ->scrollElementInView('div[id^="field-paragraphs-0-item-wrapper"] button.paragraph-form-item__action--remove');
  $customDeleteButton
    ->click();
  $confirmButton = $page
    ->find('xpath', '//*[contains(@class, "paragraphs-features__delete-confirmation")]//button[contains(@class, "paragraphs-features__delete-confirmation__remove-button")]');
  $confirmButton
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertEquals(1, $this
    ->getNumberOfParagraphs(static::$paragraphsField));
  $this
    ->editParagraph($page, 'field_paragraphs', 1);
  $customFormDeleteButton = $page
    ->find('xpath', '//div[contains(@id, "field-paragraphs-1-item-wrapper")]//button[contains(@class, "paragraph-form-item__action--remove")]');
  $hiddenFormDeleteButton = $page
    ->find('xpath', '//div[contains(@id, "field-paragraphs-1-item-wrapper")]//button[contains(@class, "paragraph-form-item__action--remove")]');
  $this
    ->assertTrue($customFormDeleteButton
    ->isVisible(), 'Delete button should be visible');
  $this
    ->assertTrue($hiddenFormDeleteButton
    ->isVisible(), 'Default button from paragraphs should not be visible');
  $this
    ->scrollElementInView('div[id^="field-paragraphs-1-item-wrapper"] button.paragraph-form-item__action--remove');
  $customFormDeleteButton
    ->click();
  $this
    ->assertFalse($customFormDeleteButton
    ->isVisible(), 'Delete button should hidden behind confirmation dialog');
  $cancelButton = $page
    ->find('xpath', '//*[contains(@class, "paragraphs-features__delete-confirmation")]//button[contains(@class, "paragraphs-features__delete-confirmation__cancel-button")]');
  $cancelButton
    ->click();
  $this
    ->assertEquals(1, $this
    ->getNumberOfParagraphs(static::$paragraphsField));
  $this
    ->assertTrue($customFormDeleteButton
    ->isVisible(), 'Delete button should be visible again');
}