You are here

public function WebformCardsAjaxJavaScriptTest::testAjax in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_cards/tests/src/FunctionalJavaScript/WebformCardsAjaxJavaScriptTest.php \Drupal\Tests\webform_cards\FunctionalJavaScript\WebformCardsAjaxJavaScriptTest::testAjax()

Test webform cards ajax.

File

modules/webform_cards/tests/src/FunctionalJavaScript/WebformCardsAjaxJavaScriptTest.php, line 24

Class

WebformCardsAjaxJavaScriptTest
Tests for webform cards ajax.

Namespace

Drupal\Tests\webform_cards\FunctionalJavaScript

Code

public function testAjax() {
  global $base_path;
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();
  $assert_session = $this
    ->assertSession();

  /**************************************************************************/

  // Get the webform and load card 1.
  $this
    ->drupalGet('/webform/test_cards_ajax');
  $assert_session
    ->waitForElement('css', '.webform-card--active[data-webform-key="card_1"]');
  $this
    ->assertCssSelect('[data-webform-card="card_1"].is-active');

  // Move to card 2.
  $page
    ->pressButton('edit-cards-next');
  $assert_session
    ->waitForElement('css', '.webform-card--active[data-webform-key="card_2"]');
  $this
    ->assertCssSelect('[data-webform-card="card_2"].is-active');

  // Move to preview.
  $page
    ->pressButton('edit-preview-next');
  $assert_session
    ->waitForElement('css', '.webform-preview');
  $this
    ->assertCssSelect('[data-webform-page="webform_preview"].is-active');

  // Submit the form.
  $page
    ->pressButton('Submit');
  $assert_session
    ->waitForElement('css', '.webform-confirmation');
  $this
    ->assertCssSelect('[data-webform-page="webform_confirmation"].is-active');

  // Confirm that the confirmation page is inline.
  $actual_path = parse_url($this
    ->getSession()
    ->getCurrentUrl(), PHP_URL_PATH) ?: '';
  $this
    ->assertEquals($base_path . 'webform/test_cards_ajax', $actual_path);

  /**************************************************************************/

  // Get the webform and load card 1.
  $this
    ->drupalGet('/webform/test_cards_ajax');
  $assert_session
    ->waitForElement('css', '.webform-card--active[data-webform-key="card_1"]');
  $this
    ->assertCssSelect('[data-webform-card="card_1"].is-active');

  // Move to card 2.
  $this
    ->executeJqueryEvent('body', 'keydown', [
    'which' => 39,
  ]);
  $assert_session
    ->waitForElement('css', '.webform-card--active[data-webform-key="card_2"]');
  $this
    ->assertCssSelect('[data-webform-card="card_2"].is-active');

  // Move to preview.
  $this
    ->executeJqueryEvent('body', 'keydown', [
    'which' => 39,
  ]);
  $assert_session
    ->waitForElement('css', '.webform-preview');
  $this
    ->assertCssSelect('[data-webform-page="webform_preview"].is-active');

  // Submit the form.
  $this
    ->executeJqueryEvent('body', 'keydown', [
    'which' => 39,
  ]);
  $assert_session
    ->waitForElement('css', '.webform-confirmation');
  $this
    ->assertCssSelect('[data-webform-page="webform_confirmation"].is-active');

  // Confirm that the confirmation page is inline.
  $actual_path = parse_url($this
    ->getSession()
    ->getCurrentUrl(), PHP_URL_PATH) ?: '';
  $this
    ->assertEquals($base_path . 'webform/test_cards_ajax', $actual_path);
}