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.
12 class JsWebAssertTestForm extends FormBase {
17 public function getFormId() {
18 return 'js_webassert_test_form';
22 * Form for testing the addition of various types of elements via AJAX.
24 public function buildForm(array $form, FormStateInterface $form_state) {
25 $form['#prefix'] = '<div id="js_webassert_test_form_wrapper">';
26 $form['#suffix'] = '</div>';
28 // Button to test for the waitForButton() assertion.
29 $form['test_button'] = [
31 '#value' => $this->t('Add button'),
32 '#button_type' => 'primary',
34 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addButton',
39 'wrapper' => 'js_webassert_test_form_wrapper',
42 // Button to test for the waitForLink() assertion.
43 $form['test_link'] = [
45 '#value' => $this->t('Add link'),
46 '#button_type' => 'primary',
48 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addLink',
53 'wrapper' => 'js_webassert_test_form_wrapper',
56 // Button to test for the waitForField() assertion.
57 $form['test_field'] = [
59 '#value' => $this->t('Add field'),
60 '#button_type' => 'primary',
62 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addField',
67 'wrapper' => 'js_webassert_test_form_wrapper',
70 // Button to test for the waitForId() assertion.
73 '#value' => $this->t('Add ID'),
74 '#button_type' => 'primary',
76 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addId',
81 'wrapper' => 'js_webassert_test_form_wrapper',
85 // Button to test the assertWaitOnAjaxRequest() assertion.
86 $form['test_wait_for_element_visible'] = [
88 '#value' => $this->t('Test waitForElementVisible'),
89 '#button_type' => 'primary',
91 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addWaitForElementVisible',
96 'wrapper' => 'js_webassert_test_form_wrapper',
100 // Button to test the assertWaitOnAjaxRequest() assertion.
101 $form['test_assert_wait_on_ajax_request'] = [
103 '#value' => $this->t('Test assertWaitOnAjaxRequest'),
104 '#button_type' => 'primary',
106 'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addAssertWaitOnAjaxRequest',
108 'type' => 'throbber',
111 'wrapper' => 'js_webassert_test_form_wrapper',
118 * Ajax callback for the "Add button" button.
120 public static function addButton(array $form, FormStateInterface $form_state) {
121 $form['added_button'] = [
123 '#value' => 'Added button',
124 '#button_type' => 'primary',
130 * Ajax callback for the "Add link" button.
132 public static function addLink(array $form, FormStateInterface $form_state) {
133 $form['added_link'] = [
134 '#title' => 'Added link',
136 '#url' => Url::fromRoute('js_webassert_test.js_webassert_test_form')
141 * Ajax callback for the "Add field" button.
143 public static function addField(array $form, FormStateInterface $form_state) {
144 $form['added_field'] = [
145 '#type' => 'textfield',
146 '#title' => 'Added textfield',
147 '#name' => 'added_field',
153 * Ajax callback for the "Add ID" button.
155 public static function addId(array $form, FormStateInterface $form_state) {
156 $form['added_id'] = [
157 '#id' => 'js_webassert_test_field_id',
159 '#value' => 'Added ID',
160 '#button_type' => 'primary',
166 * Ajax callback for the "Test waitForAjax" button.
168 public static function addAssertWaitOnAjaxRequest(array $form, FormStateInterface $form_state) {
169 // Attach the library necessary for this test.
170 $form['#attached']['library'][] = 'js_webassert_test/wait_for_ajax_request';
172 $form['test_assert_wait_on_ajax_input'] = [
173 '#type' => 'textfield',
174 '#name' => 'test_assert_wait_on_ajax_input',
182 * Ajax callback for the "Test waitForElementVisible" button.
184 public static function addWaitForElementVisible(array $form, FormStateInterface $form_state) {
185 // Attach the library necessary for this test.
186 $form['#attached']['library'][] = 'js_webassert_test/wait_for_element';
188 $form['element_invisible'] = [
189 '#id' => 'js_webassert_test_element_invisible',
191 '#value' => 'Added WaitForElementVisible',
192 '#button_type' => 'primary',
194 'style' => ['display: none;'],
203 public function submitForm(array &$form, FormStateInterface $form_state) {