You are here

public function ParagraphsFeaturesSingleActionTest::testSingleActionOption in Paragraphs Features 8

Same name and namespace in other branches
  1. 2.x tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php \Drupal\Tests\paragraphs_features\FunctionalJavascript\ParagraphsFeaturesSingleActionTest::testSingleActionOption()

Test display of action.

File

tests/src/FunctionalJavascript/ParagraphsFeaturesSingleActionTest.php, line 15

Class

ParagraphsFeaturesSingleActionTest
Test display of single actions according to the dropdown_to_button setting.

Namespace

Drupal\Tests\paragraphs_features\FunctionalJavascript

Code

public function testSingleActionOption() {

  // Create content type with paragrapjs field.
  $content_type = 'test_single_action';

  // Create nested paragraph with addition of one text test paragraph.
  $this
    ->createTestConfiguration($content_type, 1);

  // 1) Enable setting to show single action as button.
  $this
    ->enableDropdownToButton();

  // Setup content type settings, this will disable all paragraph actions.
  $this
    ->setupParagraphSettings($content_type);
  $this
    ->drupalGet("node/add/{$content_type}");

  // 1a) Check that the remove action is displayed, but no dropdown toggle.
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');

  // 1b) Enable the duplicate action, it should be shown in a dropdown
  // together with the delete action.
  $this
    ->enableDuplicateAction($content_type);

  // Check that dropdown toggle and remove action are displayed.
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');

  // 2) Disable setting to show single action as button, actions should
  // always be shown as dropdown now.
  $this
    ->disableDropdownToButton();

  // 2a) We still have two actions enabled, dropdown should be shown anyway.
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');

  // 2b) Disable the duplicate action, it should still be shown in a dropdown.
  $this
    ->disableDuplicateAction($content_type);
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@name="field_paragraphs_0_remove"]');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//input[@name="field_paragraphs_0_duplicate"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[contains(@class, "paragraphs-dropdown")]');
}