.../QuickEditIntegrationTest.php | 58 ++++++++++++++++++---- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php b/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php index b9deebf..236e70e 100644 --- a/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php +++ b/core/modules/quickedit/tests/src/FunctionalJavaScript/QuickEditIntegrationTest.php @@ -203,8 +203,8 @@ public function testArticleNode() { ]); $this->assertSession()->elementExists('css', '#quickedit-entity-toolbar .quickedit-toolgroup.wysiwyg-main > .cke_chrome .cke_top[role="presentation"] .cke_toolbar[role="toolbar"] .cke_toolgroup[role="presentation"] > .cke_button[title="Bold"][role="button"]'); - // Wait for the saving of the title field to complete. - $this->assertJsCondition("Drupal.quickedit.collections.fields.get('node/1/field_tags/en/full[0]').get('state') === 'candidate'"); + // Wait for the validating & saving of the tags field to complete. + $this->awaitEntityInstanceFieldState('node', 1, 0, 'field_tags', 'en', 'candidate'); // Click the tags field. $this->click('.field--name-field-tags'); @@ -220,10 +220,7 @@ public function testArticleNode() { 'node/1/title/en/full' => '.quickedit-changed', 'node/1/field_tags/en/full' => '.quickedit-editor-is-popup', ]); - // Assert the "Loading…" popup appears. - $this->assertSession()->elementExists('css', '.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder'); - // Wait for the form to load. - $this->assertJsCondition('document.querySelector(\'.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder\') === null'); + $this->awaitFormEditor(); $this->assertEntityInstanceFieldStates('node', 1, 0, [ 'node/1/uid/en/full' => 'candidate', 'node/1/created/en/full' => 'candidate', @@ -243,10 +240,7 @@ public function testArticleNode() { ]); // Click 'Save'. - $quickedit_entity_toolbar = $this->getSession()->getPage()->findById('quickedit-entity-toolbar'); - $save_button = $quickedit_entity_toolbar->find('css', 'button.action-save'); - $save_button->press(); - $this->assertSame('Saving', $save_button->getText()); + $this->saveQuickEdit(); $this->assertEntityInstanceStates([ 'node/1[0]' => 'committing', ]); @@ -344,7 +338,17 @@ protected function startQuickEditViaToolbar($entity_type_id, $entity_id, $entity // @todo startViaMouseOver /** - * Awaits quick edit to be initiated for all instances of the given entity. + * Clicks the 'Save' button in the Quick Edit entity toolbar. + */ + protected function saveQuickEdit() { + $quickedit_entity_toolbar = $this->getSession()->getPage()->findById('quickedit-entity-toolbar'); + $save_button = $quickedit_entity_toolbar->find('css', 'button.action-save'); + $save_button->press(); + $this->assertSame('Saving', $save_button->getText()); + } + + /** + * Awaits Quick Edit to be initiated for all instances of the given entity. * * @param $entity_type_id * The entity type ID. @@ -358,6 +362,28 @@ protected function awaitQuickEditForEntity($entity_type_id, $entity_id) { } /** + * Awaits a particular field instance to reach a particular state. + * + * @param string $entity_type_id + * The entity type ID. + * @param string $entity_id + * The entity ID. + * @param string $entity_instance_id + * The entity instance ID. (Instance on the page.) + * @param string $field_name + * The field name. + * @param string $langcode + * The language code. + * @param string $awaited_state + * One of the possible field states. + */ + protected function awaitEntityInstanceFieldState($entity_type_id, $entity_id, $entity_instance_id, $field_name, $langcode, $awaited_state) { + $entity_page_id = $entity_type_id . '/' . $entity_id . '[' . $entity_instance_id . ']'; + $logical_field_id = $entity_type_id . '/' . $entity_id . '/' . $field_name . '/' . $langcode; + $this->assertJsCondition("Drupal.quickedit.collections.entities.get('$entity_page_id').get('fields').findWhere({logicalFieldID: '$logical_field_id'}).get('state') === '$awaited_state';"); + } + + /** * Asserts the state of the Quick Edit entity toolbar. * * @param string $expected_entity_label @@ -502,6 +528,16 @@ function () { } /** + * Awaits the 'form' in-place editor. + */ + protected function awaitFormEditor() { + // Assert the "Loading…" popup appears. + $this->assertSession()->elementExists('css', '.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder'); + // Wait for the form to load. + $this->assertJsCondition('document.querySelector(\'.quickedit-form-container > .quickedit-form[role="dialog"] > .placeholder\') === null'); + } + + /** * Simulates typing in an input[type=text] inside a 'form' in-place editor. * * @param string $input_name