diff -u b/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php b/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php --- b/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/TableDrag/TableDragTest.php @@ -206,7 +206,7 @@ $this->assertDraggableTable([ ['id' => 1, 'weight' => -10, 'parent' => '', 'indentation' => 0, 'changed' => FALSE], ['id' => 3, 'weight' => -10, 'parent' => 1, 'indentation' => 1, 'changed' => FALSE], - ['id' => 2, 'weight' => -9, 'parent' => '', 'indentation' => 0, 'changed' => TRUE ], + ['id' => 2, 'weight' => -9, 'parent' => '', 'indentation' => 0, 'changed' => TRUE], ['id' => 4, 'weight' => -8, 'parent' => '', 'indentation' => 0, 'changed' => FALSE], ['id' => 5, 'weight' => -7, 'parent' => '', 'indentation' => 0, 'changed' => FALSE], ]); @@ -236,7 +236,7 @@ */ protected function assertDraggableTable(array $structure) { $rows = $this->getSession()->getPage()->findAll('xpath', '//table[@id="tabledrag-test-table"]/tbody/tr'); - $this->assertSameSize($structure, $rows); + $this->assertSession()->elementsCount('xpath', '//table[@id="tabledrag-test-table"]/tbody/tr', count($structure)); foreach ($structure as $delta => $expected) { $this->assertTableRow($rows[$delta], $expected['id'], $expected['weight'], $expected['parent'], $expected['indentation'], $expected['changed']); @@ -260,12 +260,19 @@ * Whether or not the row should have been marked as changed. */ protected function assertTableRow(NodeElement $row, $id, $weight, $parent = '', $indentation = 0, $changed = FALSE) { + // Assert that the row position is correct by checking that the id + // corresponds. $this->assertSession()->hiddenFieldValueEquals("table[$id][id]", $id, $row); + // To wait until all the JS DOM manipulations are done, wait for the parent + // input field to be updated. + $row->waitFor(1000, function () use ($row, $id, $parent) { + return $row->find('xpath', "//input[@type='hidden'][@name='table[$id][parent]'][@value='$parent']"); + }); $this->assertSession()->hiddenFieldValueEquals("table[$id][parent]", $parent, $row); $this->assertSession()->fieldValueEquals("table[$id][weight]", $weight, $row); $this->assertSession()->elementsCount('css', '.js-indentation.indentation', $indentation, $row); // A row is marked as changed when the related markup is present. - $this->assertEquals($changed, !empty($row->find('css', 'abbr.tabledrag-changed'))); + $this->assertSession()->elementsCount('css', 'abbr.tabledrag-changed', (int) $changed, $row); } /**