3 namespace Drupal\js_webassert_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
10 * Test form for JSWebAssert JavaScriptTestBase.
14 class JsWebAssertTestForm extends FormBase {
19 public function getFormId() {
20 return 'js_webassert_test_form';
24 * Form for testing the addition of various types of elements via AJAX.
26 public function buildForm(array $form, FormStateInterface $form_state) {
27 $form['#prefix'] = '<div id="js_webassert_test_form_wrapper">';
28 $form['#suffix'] = '</div>';
30 // Button to test for the waitForButton() assertion.
31 $form['test_button'] = [
33 '#value' => $this->t('Add button'),
34 '#button_type' => 'primary',
36 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addButton',
41 'wrapper' => 'js_webassert_test_form_wrapper',
44 // Button to test for the waitForLink() assertion.
45 $form['test_link'] = [
47 '#value' => $this->t('Add link'),
48 '#button_type' => 'primary',
50 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addLink',
55 'wrapper' => 'js_webassert_test_form_wrapper',
58 // Button to test for the waitForField() assertion.
59 $form['test_field'] = [
61 '#value' => $this->t('Add field'),
62 '#button_type' => 'primary',
64 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addField',
69 'wrapper' => 'js_webassert_test_form_wrapper',
72 // Button to test for the waitForId() assertion.
75 '#value' => $this->t('Add ID'),
76 '#button_type' => 'primary',
78 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addId',
83 'wrapper' => 'js_webassert_test_form_wrapper',
87 // Button to test the assertWaitOnAjaxRequest() assertion.
88 $form['test_wait_for_element_visible'] = [
90 '#value' => $this->t('Test waitForElementVisible'),
91 '#button_type' => 'primary',
93 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addWaitForElementVisible',
98 'wrapper' => 'js_webassert_test_form_wrapper',
102 // Button to test the assertWaitOnAjaxRequest() assertion.
103 $form['test_assert_wait_on_ajax_request'] = [
105 '#value' => $this->t('Test assertWaitOnAjaxRequest'),
106 '#button_type' => 'primary',
108 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addAssertWaitOnAjaxRequest',
110 'type' => 'throbber',
113 'wrapper' => 'js_webassert_test_form_wrapper',
120 * Ajax callback for the "Add button" button.
122 public static function addButton(array $form, FormStateInterface $form_state) {
123 $form['added_button'] = [
125 '#value' => 'Added button',
126 '#button_type' => 'primary',
132 * Ajax callback for the "Add link" button.
134 public static function addLink(array $form, FormStateInterface $form_state) {
135 $form['added_link'] = [
136 '#title' => 'Added link',
138 '#url' => Url::fromRoute('js_webassert_test.js_webassert_test_form'),
144 * Ajax callback for the "Add field" button.
146 public static function addField(array $form, FormStateInterface $form_state) {
147 $form['added_field'] = [
148 '#type' => 'textfield',
149 '#title' => 'Added textfield',
150 '#name' => 'added_field',
156 * Ajax callback for the "Add ID" button.
158 public static function addId(array $form, FormStateInterface $form_state) {
159 $form['added_id'] = [
160 '#id' => 'js_webassert_test_field_id',
162 '#value' => 'Added ID',
163 '#button_type' => 'primary',
169 * Ajax callback for the "Test waitForAjax" button.
171 public static function addAssertWaitOnAjaxRequest(array $form, FormStateInterface $form_state) {
172 // Attach the library necessary for this test.
173 $form['#attached']['library'][] = 'js_webassert_test/wait_for_ajax_request';
175 $form['test_assert_wait_on_ajax_input'] = [
176 '#type' => 'textfield',
177 '#name' => 'test_assert_wait_on_ajax_input',
184 * Ajax callback for the "Test waitForElementVisible" button.
186 public static function addWaitForElementVisible(array $form, FormStateInterface $form_state) {
187 // Attach the library necessary for this test.
188 $form['#attached']['library'][] = 'js_webassert_test/wait_for_element';
190 $form['element_invisible'] = [
191 '#id' => 'js_webassert_test_element_invisible',
193 '#value' => 'Added WaitForElementVisible',
194 '#button_type' => 'primary',
196 'style' => ['display: none;'],
205 public function submitForm(array &$form, FormStateInterface $form_state) {