Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyaka committed Aug 2, 2016
1 parent 062bac8 commit 777eb07
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
4 changes: 2 additions & 2 deletions drag_and_drop_v2/translations/en/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ msgid "Item Bank"
msgstr ""

#: public/js/drag_and_drop.js
msgid "Placed in: "
msgid "Placed in: {zone_title}"
msgstr ""

#: public/js/drag_and_drop.js
msgid "Correctly placed in: "
msgid "Correctly placed in: {zone_title}"
msgstr ""

#: public/js/drag_and_drop.js
Expand Down
8 changes: 4 additions & 4 deletions drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,12 @@ msgid "Item Bank"
msgstr "Ìtém Bänk Ⱡ'σяєм ιρѕυм ∂σł#"

#: public/js/drag_and_drop.js
msgid "Placed in: "
msgstr "Pläçéd ïn: Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"
msgid "Placed in: {zone_title}"
msgstr "Pläçéd ïn: {zone_title} Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"

#: public/js/drag_and_drop.js
msgid "Correctly placed in: "
msgstr "Çörréçtlý pläçéd ïn: Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"
msgid "Correctly placed in: {zone_title}"
msgstr "Çörréçtlý pläçéd ïn: {zone_title} Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"

#: public/js/drag_and_drop.js
msgid "Reset problem"
Expand Down
72 changes: 64 additions & 8 deletions tests/integration/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,21 @@ def wait_until_ondrop_xhr_finished(elem):
)

def place_item(self, item_value, zone_id, action_key=None):
"""
Place item with ID of item_value into zone with ID of zone_id.
zone_id=None means place item back to the item bank.
action_key=None means simulate mouse drag/drop instead of placing the item with keyboard.
"""
if action_key is None:
self.drag_item_to_zone(item_value, zone_id)
else:
self.move_item_to_zone(item_value, zone_id, action_key)

def drag_item_to_zone(self, item_value, zone_id):
"""
Drag item to desired zone using mouse interaction.
zone_id=None means drag item back to the item bank.
"""
element = self._get_item_by_value(item_value)
if zone_id is None:
target = self._get_item_bank()
Expand All @@ -140,20 +149,29 @@ def drag_item_to_zone(self, item_value, zone_id):
action_chains.drag_and_drop(element, target).perform()

def move_item_to_zone(self, item_value, zone_id, action_key):
# Get zone position
if zone_id is None:
zone_position = len(self.all_zones)
zone = self._get_item_bank()
else:
zone_position = self._get_zone_position(zone_id)
zone = self._get_zone_by_id(zone_id)
"""
Place item to descired zone using keybard interaction.
zone_id=None means place item back into the item bank.
"""
# Focus on the item:
item = self._get_item_by_value(item_value)
ActionChains(self.browser).move_to_element(item).perform()
# Press the action key:
item.send_keys(action_key) # Focus is on first *zone* now
self.assert_grabbed_item(item)
for _ in range(zone_position):
# Get desired zone and figure out how many times we have to press Tab to focus the zone.
if zone_id is None: # moving back to the bank
zone = self._get_item_bank()
# When switching focus between zones in keyboard placement mode,
# the item bank always gets focused last (after all regular zones),
# so we have to press Tab once for every regular zone to move focus to the item bank.
tab_press_count = len(self.all_zones)
else:
zone = self._get_zone_by_id(zone_id)
# The number of times we have to press Tab to focus the desired zone equals the zero-based
# position of the zone (zero presses for first zone, one press for second zone, etc).
tab_press_count = self._get_zone_position(zone_id)
for _ in range(tab_press_count):
self._page.send_keys(Keys.TAB)
zone.send_keys(action_key)

Expand Down Expand Up @@ -290,6 +308,38 @@ def parameterized_move_items_between_zones(self, items_map, all_zones, scroll_do
self.place_item(item_key, None, action_key)
self.assert_reverted_item(item_key)

def parameterized_cannot_move_items_between_zones(self, items_map, all_zones, scroll_down=100, action_key=None):
# Scroll drop zones into view to make sure Selenium can successfully drop items
self.scroll_down(pixels=scroll_down)

# Take each item an assigned zone, place it into the correct zone, then ensure it cannot be moved to other.
# zones or back to the bank.
for item_key, definition in items_map.items():
if definition.zone_ids: # skip decoy items
self.place_item(definition.item_id, definition.zone_ids[0], action_key)
self.assert_placed_item(definition.item_id, definition.zone_title, assessment_mode=False)
if action_key:
item = self._get_item_by_value(definition.item_id)
# When using the keyboard, ensure that dropped items cannot get "grabbed".
# Assert item has no tabindex.
self.assertIsNone(item.get_attribute('tabindex'))
# Focus on the item:
ActionChains(self.browser).move_to_element(item).perform()
# Press the action key:
item.send_keys(action_key)
# Assert item is not grabbed.
self.assertEqual(item.get_attribute('aria-grabbed'), 'false')
else:
# When using the mouse, try to drag items and observe it doesn't work.
for zone_id, _zone_title in all_zones:
if zone_id not in definition.zone_ids:
self.place_item(item_key, zone_id, action_key)
self.assert_placed_item(definition.item_id, definition.zone_title, assessment_mode=False)
# Finally, try to move item back to the bank.
self.place_item(item_key, None, action_key)
self.assert_placed_item(definition.item_id, definition.zone_title, assessment_mode=False)


def parameterized_final_feedback_and_reset(
self, items_map, feedback, scroll_down=100, action_key=None, assessment_mode=False
):
Expand Down Expand Up @@ -443,6 +493,12 @@ def test_item_positive_feedback_on_good_move(self, action_key):
def test_item_negative_feedback_on_bad_move(self, action_key):
self.parameterized_item_negative_feedback_on_bad_move(self.items_map, self.all_zones, action_key=action_key)

@data(None, Keys.RETURN, Keys.SPACE, Keys.CONTROL+'m', Keys.COMMAND+'m')
def test_cannot_move_items_between_zones(self, action_key):
self.parameterized_cannot_move_items_between_zones(
self.items_map, self.all_zones, action_key=action_key
)

@data(None, Keys.RETURN, Keys.SPACE, Keys.CONTROL+'m', Keys.COMMAND+'m')
def test_final_feedback_and_reset(self, action_key):
self.parameterized_final_feedback_and_reset(self.items_map, self.feedback, action_key=action_key)
Expand Down

0 comments on commit 777eb07

Please sign in to comment.