Problem/Motivation

assertOffCanvasFormAfterWait() says it "Waits for the specified form and returns it when available and visible."
What it really does is make sure that there is _any_ form on the page, and also that the off-canvas is open.
But currently it does not check to see if that form is _in_ the off-canvas.

Proposed resolution

Assert that the specific form ID matches, and also only look for the form within the off-canvas, instead of anywhere on the page.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new952 bytes
new1.33 KB

The FAIL patch adds just the assert, which will only find the first form on the page, not the one being loaded in the off-canvas.

The last submitted patch, 2: 3089961-form_id-2-FAIL.patch, failed testing. View results

tim.plunkett’s picture

While #2 will catch the failure, it will be hard to debug. Asserts within closures interfere with the display of error messages.
Here's one that moves the assert out of the closure.

The last submitted patch, 4: 3089961-form_id-4-FAIL.patch, failed testing. View results

tim.plunkett’s picture

Bump.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

tedbow’s picture

Status: Needs review » Needs work
+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
@@ -462,17 +462,20 @@ private function openAddBlockForm($block_title) {
-    $this->assertNotEmpty($page->waitFor($timeout / 1000, function () use ($page, $expected_form_id) {
-      // Ensure the form ID exists, is visible, and has the correct value.
-      $form_id_element = $page->find('hidden_field_selector', ['hidden_field', 'form_id']);
-
+    $form_id_element = $page->waitFor($timeout / 1000, function () use ($page) {

It seems like it would simpler to not use waitFor() at all.

We could just use

$off_canvas = $this->assertSession()->waitForElementVisible('css', '#drupal-off-canvas');
    $this->assertNotNull($off_canvas);

And then change the $form_id_element based off that.

deepak goyal’s picture

Assigned: Unassigned » deepak goyal
deepak goyal’s picture

Assigned: deepak goyal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.53 KB
new1.49 KB

Hi @tedbow

Made changes please review.

Status: Needs review » Needs work

The last submitted patch, 10: 3089961-10.patch, failed testing. View results

tedbow’s picture

+++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
@@ -469,17 +469,12 @@ private function openAddBlockForm($block_title) {
+    $this->assertSame($expected_form_id, $off_canvas->getValue());
+    $this->assertTrue($off_canvas->getParent()->isVisible());

$off_canvas is not for id element. We still need the logic from the previous patch to get that
$off_canvas->find('hidden_field_selector', ['hidden_field', 'form_id'])
'
And then basically the last 3 lines from the previous patch

Lal_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.88 KB
new1.45 KB
tedbow’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
    @@ -463,23 +463,17 @@ private function openAddBlockForm($block_title) {
    -   * @param int $timeout
    -   *   (Optional) Timeout in milliseconds, defaults to 10000.
    +   *
        */
    -  private function assertOffCanvasFormAfterWait($expected_form_id, $timeout = 10000) {
    -    $page = $this->getSession()->getPage();
    +  private function assertOffCanvasFormAfterWait($expected_form_id) {
    

    Since this is private function and no caller was using $timeout we can remove this here 🎉

    Nit: needs work for the extra line at the end of the docblock

  2. +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
    @@ -463,23 +463,17 @@ private function openAddBlockForm($block_title) {
    -    $this->assertNotEmpty($page->waitFor($timeout / 1000, function () use ($page, $expected_form_id) {
    ...
    +    $off_canvas = $this->assertSession()->waitForElementVisible('css', '#drupal-off-canvas');
    

    The actual wait time does not change because \Drupal\FunctionalJavascriptTests\JSWebAssert::waitForElementVisible() defaults to 10000 milliseconds.

  3. While reviewing this patch I noticed that docblock for this function says

    Waits for the specified form and returns it when available and visible.

    But nothing was ever returned from this function and the callers never relied on return value.

    We should update this but I guess strictly speaking it should be another issue.

    I say we fix it in a follow up and don't fix in this issue but if I committer wants to say it should just be fixed here I would glad to have it done here.

Needs work for the nit in 1)

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.87 KB
new670 bytes

Here I have made changes as mentioned in comment #14

tedbow’s picture

Status: Needs review » Reviewed & tested by the community

Thanks everyone! Looks good 🎉

alexpott’s picture

Title: assertOffCanvasFormAfterWait() doesn't check for the correct form ID » [backport] assertOffCanvasFormAfterWait() doesn't check for the correct form ID
Version: 9.1.x-dev » 9.0.x-dev

Committed 700a6ab and pushed to 9.1.x. Thanks!

  • alexpott committed 700a6ab on 9.1.x
    Issue #3089961 by tim.plunkett, Deepak Goyal, Lal_, ravi.shankar, tedbow...

  • alexpott committed 96e0a5e on 9.0.x
    Issue #3089961 by tim.plunkett, Deepak Goyal, Lal_, ravi.shankar, tedbow...

  • alexpott committed 7470bb9 on 8.9.x
    Issue #3089961 by tim.plunkett, Deepak Goyal, Lal_, ravi.shankar, tedbow...
alexpott’s picture

Title: [backport] assertOffCanvasFormAfterWait() doesn't check for the correct form ID » assertOffCanvasFormAfterWait() doesn't check for the correct form ID
Version: 9.0.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Backported to 8.9.x and 9.0.x

Status: Fixed » Closed (fixed)

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