3 namespace Drupal\Tests\layout_builder\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
8 * Tests the Layout Builder UI.
10 * @group layout_builder
12 class LayoutBuilderUiTest extends WebDriverTestBase {
15 * Path prefix for the field UI for the test bundle.
19 const FIELD_UI_PREFIX = 'admin/structure/types/manage/bundle_with_section_field';
21 public static $modules = [
30 protected function setUp() {
33 // @todo The Layout Builder UI relies on local tasks; fix in
34 // https://www.drupal.org/project/drupal/issues/2917777.
35 $this->drupalPlaceBlock('local_tasks_block');
37 $this->createContentType(['type' => 'bundle_with_section_field']);
39 $this->drupalLogin($this->drupalCreateUser([
40 'configure any layout',
41 'administer node display',
42 'administer node fields',
47 * Tests the message indicating unsaved changes.
49 public function testUnsavedChangesMessage() {
50 $assert_session = $this->assertSession();
51 $page = $this->getSession()->getPage();
53 // Enable layout builder.
54 $this->drupalPostForm(
55 static::FIELD_UI_PREFIX . '/display/default',
56 ['layout[enabled]' => TRUE],
60 // Make and then cancel changes.
61 $this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display-layout/default');
62 $page->clickLink('Cancel Layout');
63 $assert_session->pageTextNotContains('You have unsaved changes.');
65 // Make and then save changes.
66 $this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display-layout/default');
67 $page->clickLink('Save Layout');
68 $assert_session->pageTextNotContains('You have unsaved changes.');
72 * Asserts that modifying a layout works as expected.
75 * The path to a Layout Builder UI page.
77 protected function assertModifiedLayout($path) {
78 $assert_session = $this->assertSession();
79 $page = $this->getSession()->getPage();
81 $this->drupalGet($path);
82 $page->clickLink('Add Section');
83 $assert_session->assertWaitOnAjaxRequest();
84 $assert_session->pageTextNotContains('You have unsaved changes.');
85 $page->clickLink('One column');
86 $assert_session->assertWaitOnAjaxRequest();
87 $assert_session->pageTextContainsOnce('You have unsaved changes.');
90 $this->drupalGet($path);
91 $assert_session->pageTextContainsOnce('You have unsaved changes.');