Problem/Motivation
While working on #2757007: Convert all book web tests to BrowserTestBase, I discovered that, in a JavascriptTestBase
test, it's impossible to swap 2 rows by dragging the lower over upper row. The reverse works: you can swap them by dragging the upper over the lower row.
This behaviour doesn't occur when testing manually
In order to unblock #2757007: Convert all book web tests to BrowserTestBase, I opened this dedicated issue for investigation but it can be also a starting point for a full draggable table test.
It's possible that this behaviour is caused by:
- a bug in our
tabledrag.js
implementation - an upstream cause in
\Behat\Mink\Element\NodeElement::dragTo()
OR
I will let our JavaScript team to find the cause. I'm only providing here this starting test.
Proposed resolution
- Find the cause of this bug and fix if it's a Drupal bug or report upstream.
- Expand the test to cover all draggable table aspects like indenting, other actions test, etc.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#46 | drupal-tabledrag_testing-2769825-46.patch | 9.42 KB | AndyF |
#48 | interdiff_46-48.txt | 1.13 KB | AndyF |
#48 | drupal-tabledrag_testing-2769825-48.patch | 9.27 KB | AndyF |
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaComment #4
claudiu.cristeaComment #5
claudiu.cristeaComment #7
claudiu.cristeaForgot to add the package to the test module.
Comment #9
claudiu.cristeaOK, now #7 clearly shows the bug. Who's gonna take it? :)
Comment #14
pfrenssenWe are experiencing the same thing when testing table drag using Behat. The symptoms are exactly the same, we can drag from up to down, but not from down to up. Behat also uses Mink to interface with the browser.
Comment #18
AndyF CreditAttribution: AndyF at Fabb commentedI also came up against this in #3089151: TableDrag JS :first-of-type issues. If I understand correctly, when being tested with Mink's
dragTo
, the JSdragRow()
is being called once per entire drag action (ie if you drag row 2 over row 1, that only triggers a single call to it). I think this unusual situation causes a bug to manifest whereoldY
is always initially 0, which means the direction is always down, which means the row ends up one row beneath where it should be when dragging upwards.I've rerolled the test against latest and removed the initial set of weight assertions from
testDragAndDrop()
because all the rows start off with a zero weight (but I'm not sure if that's ideal: should we assert the zero weight, or make them have ascending weights?). It looks like a fix might be initialisingoldY
indragStart()
.Thanks!
Comment #20
claudiu.cristeaIn PHPUnit the assertion message should describe the failure, not the success.
Comment #21
claudiu.cristeaMore review.
We should not translate strings in tests.
We should wait for something. E.g. a text or a piece of markup. See
JSWebAssert::waitForElement()
& Co.Wait at the end of the test?
Comment #22
claudiu.cristeaNeeds work for #20 & #21
Comment #23
AndyF CreditAttribution: AndyF at Fabb commentedThanks for the review!
I accidentally left the wait in from debugging the test. I didn't actually write any of the test (apart from that wait!), it's just a reroll of the original patch: I wanted to verify the fix got the existing test passing.
Comment #24
claudiu.cristeaNo, it's me who wrote the tests 😂
Comment #25
AndyF CreditAttribution: AndyF at Fabb commentedAddresses #20 & #21, thanks!
Comment #26
claudiu.cristeaIf the message describes the the incorrect order then we should use
$strings
, not$items
, when we build the$ordered
var.EDIT: Then probably we want other var name. E.g.
$actual_order
?Comment #27
claudiu.cristeaComment #28
AndyF CreditAttribution: AndyF at Fabb commentedOh yes, well spotted, fixed! But having done that, I wonder if it makes sense to explicitly display the values at all: here's the output I got when I forced an error with the new patch:
Would it be better for the message just to be "Found strings incorrectly ordered."?
I also made some small changes to bring the tests more in line with what's already there. I chose not to use
\Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::assertDraggableTable()
because I thought it might be more functional (and less testing implementation) to just verify the order and not the actual weight values, dunno what others might think.Thanks!
Comment #30
claudiu.cristeaAgree, let's remove the list from the error message.
"Strings found on the page but incorrectly ordered." ?
Comment #31
claudiu.cristeaNit.
We can use here:
Comment #32
AndyF CreditAttribution: AndyF at Fabb commented👍 Much better, thanks.
Done.
Comment #33
claudiu.cristeaAs this is a bug, it should go in 8.8.x. I've also triggered a test for 8.8.x.
Comment #34
claudiu.cristeaThis is dead code, right?
Comment #35
AndyF CreditAttribution: AndyF at Fabb commentedYup, dead code removed, thanks!
Comment #36
claudiu.cristeaThank you. As I've only signaled the bug, and provide a raw test to prove it, I think I'm eligible to RTBC this.
Comment #37
alexpottGiven that there are runtime changes have we worked out why this bug is not triggered when testing manually.
This is additional unrelated testing as far as I can see? Is there any reason this had to be added here other than for improved test coverage?
This is a nice implementation of this. I think we should consider adding this to \Drupal\Tests\WebAssert so we can do $this->assertSession()->someFunctionNameThatIHaveNotWorkedOutYet(array) in a follow-up.
One thing that is interesting is should this work against the raw HTML or against the page text. I think it should probably be against the the text rather than the raw HTML. Not sure though. If we do change it then the exception should be ResponseTextException.
Comment #38
AndyF CreditAttribution: AndyF at Fabb commentedMy understanding of what's going on here is that normally the
dragRow()
handler is called multiple times when being dragged manually:So while it will always think that initially you're moving the row down, that doesn't really matter because there will be another call to
dragRow()
at which pointoldY
will be valid and it can correctly work out the direction. It's Mink that creates the unusual behaviour that there's only a single event for the drag, and the bug manifests.Comment #39
claudiu.cristea@alexpott
#37.1: Done.
#37.3:
When this issue has been created there was no draggable table test. So the initial scope was to start a test and also signal this potential bug. In the meantime a test has been added but I see that all existing tests are using the keyboard to manipulate the rows. We can remove the test but I wouldn't do it as it really expands the coverage.
#37.4: we already have #2817657: Add methods to assert that a sequence of strings appears on the page in a given order.
In #2817657: Add methods to assert that a sequence of strings appears on the page in a given order we add both. But, we probably want to add a @todo to remove this function when #2817657: Add methods to assert that a sequence of strings appears on the page in a given order is in. If that goes first we just rework this patch to use it.
Comment #40
alexpottYep, @claudiu.cristea adding a @todo in this issue and adding a task to search for @todo's to the other issue is a good plan
+1 to keeping the additional test coverage I just wanted to check that I understood.
Comment #41
AndyF CreditAttribution: AndyF at Fabb commentedThanks @alexpott. I've added a todo to
\Drupal\FunctionalJavascriptTests\TableDrag\TableDragTest::assertOrder()
and added a task to #2817657: Add methods to assert that a sequence of strings appears on the page in a given order.Comment #42
claudiu.cristeaGreat! As all points were addressed, moving back to RTBC.
Comment #43
AndyF CreditAttribution: AndyF at Fabb commentedIt looks like the same issue might affect claro/js/tabledrag.es6.js, should that be a separate issue?
Comment #44
alexpott@AndyF great catch. We should definitely fix it here too.
Comment #45
claudiu.cristea+1 to fix it here. And, of course, we need test coverage to run with claro.
Comment #46
AndyF CreditAttribution: AndyF at Fabb commentedI've had a go at that - turns out that Claro uses a link rather than a button for the Show row weights toggle. I've added a test method
::findWeightsToggle()
so it can be overridden in the Claro test, but it did occur to me that we could instead use a looser xpath in the base test, perhaps one of these (untested):I erred on the side of caution and currently the base test explicitly tests it's a button and the Claro test tests it's a link. Feedback welcome (:
I also took the opportunity to change the default value of
oldY
tonull
rather than 0, I think that makes sense as it should get explicitly set indragStart()
before use.Thanks!
Comment #47
claudiu.cristeas/Find/Finds
I think overriding the
defaultTheme
protected property should do the job. Still not sure.Comment #48
AndyF CreditAttribution: AndyF at Fabb commentedThanks @claudiu.cristea
\Drupal\FunctionalJavascriptTests\Theme\ClaroMenuUiJavascriptTest
, looking more closely 3 of the existing 4 Claro functional javascript tests do it that way, and\Drupal\FunctionalJavascriptTests\Theme\ClaroViewsUiTest
uses$defaultTheme
, not sure if there's any meaning to be read into that?Comment #49
claudiu.cristeaI guess there's nothing else than the first 3 were written before
$defaultTheme
landed in https://www.drupal.org/node/3083055Claro tabledrag is fixed too now and and also has test coverage. RTBC!
Thank you!
Comment #50
alexpottCommitted and pushed 5b9cb9b7fb to 9.0.x and 912971406c to 8.9.x. Thanks!
Fixed coding standards on commit.
Comment #53
claudiu.cristea@alexpott, as this is a bug with tests, why it's not merged also in 8.8.x?
Comment #54
alexpottI think the bugfix here is not disruptive enough to consider for backport to 8.8.x and fixing JS testing for tabledrag interactions seems like a good thing to do.
Will ask other committers once 8.8.x is open again.
Comment #55
alexpottDiscussed with @lauriii and we agreed that this was not affecting live sites so not worth backporting.