From 777eb07a2da5018236bbf08a0fc4a3d2b22f1622 Mon Sep 17 00:00:00 2001 From: Matjaz Gregoric Date: Tue, 2 Aug 2016 12:16:27 +0800 Subject: [PATCH] Address review comments. --- .../translations/en/LC_MESSAGES/text.po | 4 +- .../translations/eo/LC_MESSAGES/text.po | 8 +-- tests/integration/test_interaction.py | 72 ++++++++++++++++--- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/drag_and_drop_v2/translations/en/LC_MESSAGES/text.po b/drag_and_drop_v2/translations/en/LC_MESSAGES/text.po index 93a88f834..38945eb00 100644 --- a/drag_and_drop_v2/translations/en/LC_MESSAGES/text.po +++ b/drag_and_drop_v2/translations/en/LC_MESSAGES/text.po @@ -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 diff --git a/drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po b/drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po index 0390fd414..193aae68c 100644 --- a/drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po +++ b/drag_and_drop_v2/translations/eo/LC_MESSAGES/text.po @@ -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" diff --git a/tests/integration/test_interaction.py b/tests/integration/test_interaction.py index cdab9561f..b00c19fad 100644 --- a/tests/integration/test_interaction.py +++ b/tests/integration/test_interaction.py @@ -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() @@ -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) @@ -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 ): @@ -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)