In some executions, we get the the questionnaire orders [0, 1, 3, 2, 4] instead of the expected [0, 2, 3, 1, 4] order:
|
def test_question_ordering(self): |
|
with self.enter_staff_mode(): |
|
self.selenium.get(self.url) |
|
moving_arrows = self.selenium.find_elements(By.CLASS_NAME, "movable-icon") |
|
self.assertEqual(len(moving_arrows), 7) # one extra for "add another" row, one for hidden template row |
|
ActionChains(self.selenium).drag_and_drop(moving_arrows[3], moving_arrows[1]).perform() |
|
self.selenium.find_element(By.ID, "questionnaire-save-btn").click() |
|
|
|
expected_order = [0, 2, 3, 1, 4] # yields order Q0, Q3, Q1, Q2, Q4 |
|
for a in self.assignments: |
|
a.refresh_from_db() |
|
database_order = [a.order for a in self.assignments] |
|
self.assertEqual(database_order, expected_order) |
The order we get means that the fourth questionnaire was "dragged above" the third, but not above the second yet, where it was actually supposed to go.
Just from staring at the code, my hypothesis is that the ActionChain.perform call does not guarantee that the code from Sortable.js has finished reordering the elements in the DOM. When we submit the form, the drag operation has only "reached" the first step of the reordering yet, but we still re-fill the order form fields, and end up with this half-done order. If this is the reason, we should be able to fix this by adding another wait step before submitting the form, waiting for the row elements to the in the proper order.
In some executions, we get the the questionnaire orders
[0, 1, 3, 2, 4]instead of the expected[0, 2, 3, 1, 4]order:EvaP/evap/staff/tests/test_live.py
Lines 291 to 303 in 4cfb861
The order we get means that the fourth questionnaire was "dragged above" the third, but not above the second yet, where it was actually supposed to go.
Just from staring at the code, my hypothesis is that the
ActionChain.performcall does not guarantee that the code fromSortable.jshas finished reordering the elements in the DOM. When we submit the form, the drag operation has only "reached" the first step of the reordering yet, but we still re-fill theorderform fields, and end up with this half-done order. If this is the reason, we should be able to fix this by adding another wait step before submitting the form, waiting for the row elements to the in the proper order.