function HtmxDynamicFormTest::testPartialTarget

Verify that an hx-partial response replaces the target.

File

core/tests/Drupal/FunctionalJavascriptTests/Core/Htmx/HtmxDynamicFormTest.php, line 144

Class

HtmxDynamicFormTest
Tests that dynamic forms powered by HTMX work as expected.

Namespace

Drupal\FunctionalJavascriptTests\Core\Htmx

Code

public function testPartialTarget() : void {
  $this->drupalLogin($this->drupalCreateUser([
    'access content',
  ]));
  $this->drupalGet('htmx-test-attachments/form-builder-test/');
  $this->assertSession()
    ->elementExists('css', '[data-drupal-wrapper-selector="edit-partial-replace"]');
  $this->assertSession()
    ->pageTextNotContains('Inserted by htmx!');
  $checkbox = $this->assertSession()
    ->elementExists('css', '[name="partial"]');
  $checkbox->click();
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  $this->assertSession()
    ->elementNotExists('css', '[data-drupal-wrapper-selector="edit-partial-replace"]');
  $this->assertSession()
    ->pageTextContainsOnce('Inserted by htmx!');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.