Problem/Motivation

drupalPostAjaxForm() is simulating the behaviour of ajax.js, so using it, doesn't really provide fundamental guarantees.
#2809161: Convert Javascript/AJAX testing to use JavascriptTestBase suggests to convert them to JavascriptTestBase

Proposed resolution

  1. Figure out which part of the test is testing PHP code and which part ajax behaviour
  2. Extract the ajax behaviour into a test that extends JavascriptTestBase

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

michielnugter’s picture

Component: phpunit » system.module
Issue tags: +phpunit initiative

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

martin107’s picture

Status: Active » Postponed
FileSize
3.52 KB

The solution to this conversion exists in this issue.

#2862510: Convert system/tests/src/Ajax to JavascriptTestBase

but by common consent that issue is being shipwrecked -- broken up for parts and spares.

In this patch I am cutting out the conversion specific to ElementValidationTest

This shipwrecking has to be coordinated... the issue below, which is in review, is creating a AjaxTestBase class which this sub-putach assumes in already in core. Therefore I am postponing this issue with the solution almost working.

#2809521: Convert AJAX part of \Drupal\system\Tests\Ajax\AjaxInGroupTest to WebDriverTestBase

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Lendude’s picture

Status: Postponed » Needs work

The AjaxTestBase class was scuttled (in keeping with the maritime theme here), in #2809521: Convert AJAX part of \Drupal\system\Tests\Ajax\AjaxInGroupTest to WebDriverTestBase, so no need to wait for that anymore

martin107’s picture

Status: Needs work » Needs review
FileSize
3.84 KB

Thanks for taking the time to dig through old issues and see that...

Lendude++

The patch needed a reroll... but the patch was so old and the changes so small... that I just started again.

Status: Needs review » Needs work

The last submitted patch, 9: 2809529-9.patch, failed testing. View results

martin107’s picture

Assigned: Unassigned » martin107

Hmm .. that passes locally. I will look into it.

martin107’s picture

Assigned: martin107 » Unassigned
Status: Needs work » Needs review

I have just checked again today. Regarding 2809529-9.patch

I should qualify what I mean by works for me. I'm on PHP 7.2.9

So

composer run-script drupal-phpunit-upgrade

php core/scripts/run-tests.sh --file core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php

martin107’s picture

Just a minor problem I can see -- which I want to fold into the next meaningful change.

public static $modules = ['ajax_test', 'ajax_forms_test'];

should be protected.

Status: Needs review » Needs work

The last submitted patch, 9: 2809529-9.patch, failed testing. View results

Lendude’s picture

Status: Needs work » Needs review
FileSize
1.8 KB
4.25 KB

Fails for me locally too. We need to do some extra things to get the ajax to trigger here.

This form though does some interesting thing when you do trigger ajax. The focus starts bouncing between the two field and this goes into an ajax request loop, so you need to take some steps to break out of that again.

This is more about getting this green than about getting this right. If we can prevent the ajax ping-pong this would probably be cleaner.

martin107’s picture

Thanks for solving the problem,

Having that understanding it really useful...

PS

I am currently starting a online petition to get the "Gordian Knot" renamed the "Lendude Knot".

Lendude’s picture

@martin107 I'm always up for a nice puzzle :)

Little clean up. The ping-pong happens because after the ajax call the focus returns to the text field that triggered it, so if you go to another field with a blur event that returns the focus to itself when its own ajax call finishes.....ping pong!

So the only safe way to clear focus is to reload the page. This seems like a bug to me, but that seems out of scope for this conversion.

proper javascript testing++

I think this version is as clean as we can get it.

jibran’s picture

Overall patch looks good to me. Just found some nits.

+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php
@@ -0,0 +1,51 @@
+    $this->getSession()->getPage()->fillField('drivertext', 'some dumb text');
...
+    $this->getSession()->getPage()->findField('spare_required_field')->focus();
...
+    $this->getSession()->getPage()->fillField('drivernumber', '12345');
+    $this->getSession()->getPage()->findField('spare_required_field')->focus();

At least we can have $session local var. :)

+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/ElementValidationTest.php
@@ -0,0 +1,51 @@
+    $placeholder_text = $this->assertSession()->waitForElement('css', "ul.messages__list li.messages__item em:contains('some dumb text')");
...
+    $placeholder_number = $this->assertSession()->waitForElement('css', "ul.messages__list li.messages__item em:contains('12345')");

$assert_session please.

Lendude’s picture

@jibran thanks as always for the review.

Feedback addressed.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, for addressing the feedback.

  • larowlan committed f2e993d on 8.6.x
    Issue #2809529 by Lendude, martin107: Convert AJAX part of \Drupal\...

  • larowlan committed ebee0dc on 8.7.x
    Issue #2809529 by Lendude, martin107: Convert AJAX part of \Drupal\...
larowlan’s picture

Version: 8.7.x-dev » 8.6.x-dev
Status: Reviewed & tested by the community » Fixed

Committed ebee0dc and pushed to 8.7.x. Thanks!

Cherry picked as f2e993d2c8 and pushed to 8.6.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.