Problem/Motivation
The basis for this test was build in #1686174: Refactor machine-name.js
Currently the machine name element has no javascript test coverage. There are a number of issues with the machine name field that will all require javascript testing.
This issue will provide a base test setup that the other issues can then build upon. It will only test functionality that currently works, and bugs found while building this will be addressed in follow up issues.
Issues that depend on this (add more if we find more issues):
Proposed resolution
- Add test
Remaining tasks
- Review
- Rework(?)
- Commit :)
User interface changes
- NO
API changes
- NO
Data model changes
- NO
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff.patch | 2.23 KB | droplet |
| #17 | add_test_coverage_for_machine_name_js_2821320_17.patch | 7.39 KB | droplet |
| #16 | add_test_coverage_for_machine_name_js_2821320_16.patch | 6.96 KB | michielnugter |
| #16 | interdiff-13-16.txt | 891 bytes | michielnugter |
| #13 | add_test_coverage_for_machine_name_js_2821320_13.patch | 6.94 KB | michielnugter |
Comments
Comment #2
michielnugter commentedInterdiff is for changes from the last patch in #1686174.
Comment #3
michielnugter commentedComment #4
michielnugter commentedSmall question: Is there a meta issue for adding functional JavaScript testcoverage to Drupal Core? If not, should there be one? I'd really like to work on this some more.
Comment #5
lendudeUpdated the issue summary a bit.
A javascript meta issue for the whole of core would probably be too big in scope.
I set up a meta issue just for Views #2752931: [meta] Implement Javascript testing for Views and the Views UI so that is somewhat more limited in scope and pretty maintainable. There might be other meta's like that floating around.
Comment #6
droplet commented@michielnugter,
There're some issues needed JSTests:
https://www.drupal.org/project/issues/search?projects=Drupal+core&projec...
Huge one:
#2809161: Convert Javascript/AJAX testing to use JavascriptTestBase
I very enjoy to see your detail reports of each update, you might be interested in the following issue:
#2820079: Convert \Drupal\book\Tests\BookTest::testBookOrdering() to a JavascriptTestBase test
Comment #7
michielnugter commentedThanks for the links, I'll start following these issues.
I'll try to review some patches and create tests where missing. I also hope (eventually) to be able to contribute some to the ES6 refactoring step.
Comment #8
lendudeLast couple of nitpicks then I think this is ready:
needs a different @group
One newline too many.
'role' Left over from when this used add role page.
These variables are not really needed, this can just be done in the assert right?
Maybe add an short explanation why isVisible() doesn't work here.
I would just use $test_values[1]['expected'], that way the $test_values can be reused in further test we might want to add later.
Comment #9
michielnugter commentedThanks for the review again!
I fixed all the mentioned issues, I chose the field group as other field tests are in this group as well.
Comment #10
droplet commentedWOW mate! I think you're the only one will understand me on another issue #2820079: Convert \Drupal\book\Tests\BookTest::testBookOrdering() to a JavascriptTestBase test. It's great code. Validate result on generated HTML ( ->getHTML() )
It needed longer timeout and JS condition to aviod random failing. 300ms isn't always 300ms in JS :)
Comment #11
lendudeWell waitOnAutocomplete also adds another wait(300), so the total wait before waiting for the ajax request to finish is already 600ms. I feel this should be sufficient. If that won't do then we need to not wait() a set number of ms, but just wait for the expected value to appear, but I think this is much cleaner.
@droplet I feel this is good to go now, but of course feel free to set back to needs work if you disagree on the timing thing!
@michielnugter nice work!
Comment #12
droplet commented@Lendude,
OK. Let's go.
Comment #13
michielnugter commentedI tried various things with the timing and I actually got the test to fail once at 250ms. It seems risky to keep it at 300ms as it's a risk that the test will fail incorrectly. I upped to timeout to 400ms, this is safe for the average range the timout ms is in. It shouldn't be too high again because it will delay each complete test suite on Drupal..
As for waiting for the value to appear, that's actually the behaviour we're testing here. If implemented this way a max. time is still required, thus keeping the risk of incorrect failure.
See interdiff for the change.
Comment #14
michielnugter commented@droplet I'll look into the mentioned issue and see if I can make sense of it :)
Comment #15
droplet commented@michielnugter,
Thanks.
It will be stopped when the JS condition is met.
@see: \vendor\behat\mink\src\Driver\DriverInterface.php
In fact, the `waitOnAutocomplete()` should not set a fixed 300ms also. But it's out of this issue scope.
Actually we have a real example with similar problem over there, you can see how unstable the PhantomJS test is.
https://www.drupal.org/node/2782915#comment-11728915
Unless we think it's a UX issue and should be tested the action within 300ms execution time. Otherwise, we can increase the timeout there with JS condition.
Comment #16
michielnugter commentedReally helpful feedback, I'm learning a lot and fast. Thanks!
I updated the patch to use the wait() command instead of the manual timeout and waitOnAutocomplete().
Comment #17
droplet commentedAll good.
Enhanced a little bit to cover 2nd machine name also. It's easy to use a bad selector & bubble up in JS
Comment #18
alexpottCommitted and pushed 2cde5b6 to 8.3.x and d97733a to 8.2.x. Thanks!