WebformCardsAjaxJavaScriptTest.php in Webform 8.5
File
modules/webform_cards/tests/src/FunctionalJavaScript/WebformCardsAjaxJavaScriptTest.php
View source
<?php
namespace Drupal\Tests\webform_cards\FunctionalJavaScript;
use Drupal\Tests\webform\FunctionalJavascript\WebformWebDriverTestBase;
class WebformCardsAjaxJavaScriptTest extends WebformWebDriverTestBase {
public static $modules = [
'webform',
'webform_cards',
'webform_cards_test',
];
public function testAjax() {
global $base_path;
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$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');
$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');
$page
->pressButton('edit-preview-next');
$assert_session
->waitForElement('css', '.webform-preview');
$this
->assertCssSelect('[data-webform-page="webform_preview"].is-active');
$page
->pressButton('Submit');
$assert_session
->waitForElement('css', '.webform-confirmation');
$this
->assertCssSelect('[data-webform-page="webform_confirmation"].is-active');
$actual_path = parse_url($this
->getSession()
->getCurrentUrl(), PHP_URL_PATH) ?: '';
$this
->assertEquals($base_path . 'webform/test_cards_ajax', $actual_path);
$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');
$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');
$this
->executeJqueryEvent('body', 'keydown', [
'which' => 39,
]);
$assert_session
->waitForElement('css', '.webform-preview');
$this
->assertCssSelect('[data-webform-page="webform_preview"].is-active');
$this
->executeJqueryEvent('body', 'keydown', [
'which' => 39,
]);
$assert_session
->waitForElement('css', '.webform-confirmation');
$this
->assertCssSelect('[data-webform-page="webform_confirmation"].is-active');
$actual_path = parse_url($this
->getSession()
->getCurrentUrl(), PHP_URL_PATH) ?: '';
$this
->assertEquals($base_path . 'webform/test_cards_ajax', $actual_path);
}
}