You are here

public function ParagraphsStableEditPerspectivesUiTest::testPerspectivesWithMultipleFields in Paragraphs 8

Test edit perspectives works fine with multiple fields.

File

tests/src/FunctionalJavascript/ParagraphsStableEditPerspectivesUiTest.php, line 219

Class

ParagraphsStableEditPerspectivesUiTest
Test paragraphs user interface.

Namespace

Drupal\Tests\paragraphs\FunctionalJavascript

Code

public function testPerspectivesWithMultipleFields() {
  $this
    ->loginAsAdmin([
    'edit behavior plugin settings',
  ]);

  // Add a nested Paragraph type.
  $paragraph_type = 'nested_paragraph';
  $this
    ->addParagraphsType($paragraph_type);
  $this
    ->addParagraphsField('nested_paragraph', 'paragraphs', 'paragraph');
  $edit = [
    'behavior_plugins[test_bold_text][enabled]' => TRUE,
  ];
  $this
    ->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type);
  $this
    ->submitForm($edit, 'Save');
  $this
    ->addParagraphedContentType('testcontent');
  $this
    ->addParagraphsField('testcontent', 'field_paragraphs2', 'node');

  // Disable the default paragraph on both the node and the nested paragraph
  // to explicitly test with no paragraph and avoid a loop.
  EntityFormDisplay::load('node.testcontent.default')
    ->setComponent('field_paragraphs', [
    'type' => 'paragraphs',
    'settings' => [
      'default_paragraph_type' => '_none',
    ],
  ])
    ->setComponent('field_paragraphs2', [
    'type' => 'paragraphs',
    'settings' => [
      'default_paragraph_type' => '_none',
    ],
  ])
    ->save();
  EntityFormDisplay::load('paragraph' . '.' . $paragraph_type . '.default')
    ->setComponent('paragraphs', [
    'type' => 'paragraphs',
    'settings' => [
      'default_paragraph_type' => '_none',
    ],
  ])
    ->save();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalGet('node/add/testcontent');
  $assert_session
    ->elementNotExists('css', '.paragraphs-nested');

  // Add a nested paragraph to the first field.
  $button = $this
    ->getSession()
    ->getPage()
    ->findButton('Add nested_paragraph');
  $button
    ->press();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->elementExists('css', '.paragraphs-nested');

  // Add a paragraph to the second field.
  $region_field2 = $this
    ->getSession()
    ->getPage()
    ->find('css', '.field--name-field-paragraphs2');
  $button_field2 = $region_field2
    ->findButton('Add nested_paragraph');
  $button_field2
    ->press();
  $assert_session
    ->assertWaitOnAjaxRequest();

  // Ge the style checkboxes from each field, make sure they are not visible
  // by default.
  $page = $this
    ->getSession()
    ->getPage();
  $style_selector = $page
    ->findField('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]');
  $this
    ->assertFalse($style_selector
    ->isVisible());
  $style_selector2 = $page
    ->findField('field_paragraphs2[0][behavior_plugins][test_bold_text][bold_text]');
  $this
    ->assertFalse($style_selector2
    ->isVisible());

  // Switch to Behavior on the first field, then the second, make sure
  // the visibility of the checkboxes is correct after each change.
  $this
    ->clickLink('Behavior', 0);
  $this
    ->assertTrue($style_selector
    ->isVisible());
  $this
    ->assertFalse($style_selector2
    ->isVisible());
  $this
    ->clickLink('Behavior', 1);
  $this
    ->assertTrue($style_selector
    ->isVisible());
  $this
    ->assertTrue($style_selector2
    ->isVisible());

  // Switch the second field back to Content, verify visibility again.
  $this
    ->clickLink('Content', 1);
  $this
    ->assertTrue($style_selector
    ->isVisible());
  $this
    ->assertFalse($style_selector2
    ->isVisible());
}