class CustomDataInteractionTest(StandardInteractionTest): items_map = { 0: ItemDefinition(0, "Item 0", "", ['zone-1'], "Zone 1", "Yes 1", "No 1"), 1: ItemDefinition(1, "Item 1", "", ['zone-2'], "Zone 2", "Yes 2", "No 2"), 2: ItemDefinition(2, "Item 2", "", [], None, "", "No Zone for this") } all_zones = [('zone-1', 'Zone 1'), ('zone-2', 'Zone 2')] feedback = {"intro": "Some Intro Feed", "final": "Some Final Feed"} def _get_scenario_xml(self): return self._get_custom_scenario_xml("data/test_data.json")
class MultipleValidOptionsInteractionTest(DefaultDataTestMixin, InteractionTestBase, BaseIntegrationTest): items_map = { 0: ItemDefinition(0, "Item", "", ['zone-1', 'zone-2'], ["Zone 1", "Zone 2"], ["Yes 1", "Yes 1"], ["No 1", "No 1"]), } def test_multiple_positive_feedback(self): popup = self._get_popup() feedback_popup_content = self._get_popup_content() reset = self._get_reset_button() self.scroll_down(pixels=100) for item in self.items_map.values(): for i, zone in enumerate(item.zone_ids): self.place_item(item.item_id, zone, None) self.wait_until_html_in(item.feedback_positive[i], feedback_popup_content) self.assert_popup_correct(popup) self.assert_placed_item(item.item_id, item.zone_title[i]) reset.click() self.wait_until_disabled(reset) def _get_scenario_xml(self): return self._get_custom_scenario_xml( "data/test_multiple_options_data.json")
class CustomHtmlDataInteractionTest(StandardInteractionTest): items_map = { 0: ItemDefinition(0, "Item 0", "", ['zone-1'], 'Zone <i>1</i>', "Yes <b>1</b>", "No <b>1</b>"), 1: ItemDefinition(1, "Item 1", "", ['zone-2'], 'Zone <b>2</b>', "Yes <i>2</i>", "No <i>2</i>"), 2: ItemDefinition(2, "Item 2", "", [], None, "", "No Zone for <i>X</i>") } all_zones = [('zone-1', 'Zone 1'), ('zone-2', 'Zone 2')] feedback = { "intro": "Intro <i>Feed</i>", "final": "Final <b>Feed</b>" } def _get_scenario_xml(self): return self._get_custom_scenario_xml("data/test_html_data.json")
class ItemDroppedEventTest(DefaultDataTestMixin, BaseEventsTests): """ Test that the item.dropped event behaves properly. """ items_map = { 0: ItemDefinition(0, "Has name", "", 'zone-1', "Zone 1", "Yes", "No"), 1: ItemDefinition(1, "", "https://placehold.it/100x100", 'zone-2', "Zone 2", "Yes", "No"), } scenarios = ( ( ['zone-1', 'zone-2'], [{ 'is_correct': True, 'item': "Has name", 'item_id': 0, 'location': 'Zone 1', 'location_id': 'zone-1' }, { 'is_correct': True, 'item': "https://placehold.it/100x100", 'item_id': 1, 'location': 'Zone 2', 'location_id': 'zone-2' }], ), ( ['zone-2', 'zone-1'], [{ 'is_correct': False, 'item': "Has name", 'item_id': 0, 'location': 'Zone 2', 'location_id': 'zone-2' }, { 'is_correct': False, 'item': "https://placehold.it/100x100", 'item_id': 1, 'location': 'Zone 1', 'location_id': 'zone-1' }], ), ) def _get_scenario_xml(self): return self._get_custom_scenario_xml("data/test_item_dropped.json") @data(*scenarios) # pylint: disable=star-args @unpack def test_item_dropped_event(self, placement, expected_events): for i, zone in enumerate(placement): self.place_item(i, zone, Keys.RETURN) events = self.publish.call_args_list event_name = 'edx.drag_and_drop_v2.item.dropped' published_events = [ event[0][2] for event in events if event[0][1] == event_name ] self.assertEqual(published_events, expected_events)
class MultipleBlocksDataInteraction(ParameterizedTestsMixin, InteractionTestBase, BaseIntegrationTest): PAGE_TITLE = 'Drag and Drop v2 Multiple Blocks' PAGE_ID = 'drag_and_drop_v2_multi' BLOCK1_DATA_FILE = "data/test_data.json" BLOCK2_DATA_FILE = "data/test_data_other.json" item_maps = { 'block1': { 0: ItemDefinition(0, "Item 0", "", ['zone-1'], 'Zone 1', "Yes 1", "No 1"), 1: ItemDefinition(1, "Item 1", "", ['zone-2'], 'Zone 2', "Yes 2", "No 2"), 2: ItemDefinition(2, "Item 2", "", [], None, "", "No Zone for this") }, 'block2': { 10: ItemDefinition(10, "Item 10", "", ['zone-51'], 'Zone 51', "Correct 1", "Incorrect 1"), 20: ItemDefinition(20, "Item 20", "", ['zone-52'], 'Zone 52', "Correct 2", "Incorrect 2"), 30: ItemDefinition(30, "Item 30", "", [], None, "", "No Zone for this") }, } all_zones = { 'block1': [('zone-1', 'Zone 1'), ('zone-2', 'Zone 2')], 'block2': [('zone-51', 'Zone 51'), ('zone-52', 'Zone 52')] } feedback = { 'block1': { "intro": "Some Intro Feed", "final": "Some Final Feed" }, 'block2': { "intro": "Other Intro Feed", "final": "Other Final Feed" }, } def _get_scenario_xml(self): blocks_xml = "\n".join([ "<drag-and-drop-v2 data='{data}'/>".format( data=loader.load_unicode(filename)) for filename in (self.BLOCK1_DATA_FILE, self.BLOCK2_DATA_FILE) ]) return "<vertical_demo>{dnd_blocks}</vertical_demo>".format( dnd_blocks=blocks_xml) def test_item_positive_feedback_on_good_move(self): self._switch_to_block(0) self.parameterized_item_positive_feedback_on_good_move( self.item_maps['block1']) self._switch_to_block(1) self.parameterized_item_positive_feedback_on_good_move( self.item_maps['block2'], scroll_down=900) def test_item_negative_feedback_on_bad_move(self): self._switch_to_block(0) self.parameterized_item_negative_feedback_on_bad_move( self.item_maps['block1'], self.all_zones['block1']) self._switch_to_block(1) self.parameterized_item_negative_feedback_on_bad_move( self.item_maps['block2'], self.all_zones['block2'], scroll_down=900) def test_final_feedback_and_reset(self): self._switch_to_block(0) self.parameterized_final_feedback_and_reset(self.item_maps['block1'], self.feedback['block1']) self._switch_to_block(1) self.parameterized_final_feedback_and_reset(self.item_maps['block2'], self.feedback['block2'], scroll_down=900) def test_keyboard_help(self): self._switch_to_block(0) # Test mouse and keyboard interaction self.interact_with_keyboard_help() self.interact_with_keyboard_help(use_keyboard=True) self._switch_to_block(1) # Test mouse and keyboard interaction self.interact_with_keyboard_help(scroll_down=1200) self.interact_with_keyboard_help(scroll_down=0, use_keyboard=True)