From 054a7a644ed763e241eef3e468e164f3759ee560 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 17 Jan 2017 10:24:32 +0000 Subject: [PATCH] Issue #2731419 by hgoto, michielnugter, pareshpatel, tocab, Chernous_dn, Sabbi0612, cilefen, droplet: "cannot call methods on dialog prior to initialization" logged when resizing after closing a modal --- core/misc/dialog/dialog.position.js | 3 +- .../Dialog/DialogPositionTest.php | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php diff --git a/core/misc/dialog/dialog.position.js b/core/misc/dialog/dialog.position.js index 40bb5b6f03..e3c058f844 100644 --- a/core/misc/dialog/dialog.position.js +++ b/core/misc/dialog/dialog.position.js @@ -100,11 +100,12 @@ $(window) .on('resize.dialogResize scroll.dialogResize', eventData, autoResize) .trigger('resize.dialogResize'); - $(document).on('drupalViewportOffsetChange', eventData, autoResize); + $(document).on('drupalViewportOffsetChange.dialogResize', eventData, autoResize); } }, 'dialog:beforeclose': function (event, dialog, $element) { $(window).off('.dialogResize'); + $(document).off('.dialogResize'); } }); diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php new file mode 100644 index 0000000000..19cf5a4b35 --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php @@ -0,0 +1,52 @@ +drupalCreateUser(['administer blocks']); + $this->drupalLogin($admin_user); + $this->drupalGet('admin/structure/block'); + $session = $this->getSession(); + $assert_session = $this->assertSession(); + $page = $session->getPage(); + + // Open the dialog using the place block link. + $placeBlockLink = $page->findLink('Place block'); + $this->assertTrue($placeBlockLink->isVisible(), 'Place block button exists.'); + $placeBlockLink->click(); + $assert_session->assertWaitOnAjaxRequest(); + $dialog = $page->find('css', '.ui-dialog'); + $this->assertTrue($dialog->isVisible(), 'Dialog is opened after clicking the Place block button.'); + + // Close the dialog again. + $closeButton = $page->find('css', '.ui-dialog-titlebar-close'); + $closeButton->click(); + $assert_session->assertWaitOnAjaxRequest(); + $dialog = $page->find('css', '.ui-dialog'); + $this->assertNull($dialog, 'Dialog is closed after clicking the close button.'); + + // Resize the window. The test should pass after waiting for Javascript to + // finish as no Javascript errors should have been triggered. If there were + // javascript errors the test will fail on that. + $session->resizeWindow(625, 625); + $assert_session->assertWaitOnAjaxRequest(); + } + +} -- GitLab