Commit dfe6105d by Jonathan Piacenti

Fix analytics events and add tests.

parent b29dee80
...@@ -166,14 +166,12 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -166,14 +166,12 @@ function DragAndDropBlock(runtime, element, configuration) {
var applyState = function() { var applyState = function() {
// Has the feedback popup been closed? // Has the feedback popup been closed?
if (state.closing) { if (state.closing) {
if (previousFeedback) { publishEvent({
publishEvent({ event_type: 'xblock.drag-and-drop-v2.feedback.closed',
event_type: 'xblock.drag-and-drop-v2.feedback.closed', content: previousFeedback || state.feedback,
content: previousFeedback, manually: state.manually_closed,
manually: state.manually_closed, });
}); previousFeedback = undefined;
previousFeedback = undefined;
}
} }
// Has feedback been set? // Has feedback been set?
if (state.feedback) { if (state.feedback) {
...@@ -478,8 +476,8 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -478,8 +476,8 @@ function DragAndDropBlock(runtime, element, configuration) {
state.manually_closed = false; state.manually_closed = false;
} }
delete state.feedback;
applyState(); applyState();
delete state.feedback;
}; };
var resetExercise = function(evt) { var resetExercise = function(evt) {
......
...@@ -29,9 +29,10 @@ setup( ...@@ -29,9 +29,10 @@ setup(
install_requires=[ install_requires=[
'XBlock', 'XBlock',
'xblock-utils', 'xblock-utils',
'ddt' 'ddt',
'mock',
], ],
dependency_links = ['http://github.com/edx/xblock-utils/tarball/master#egg=xblock-utils'], dependency_links=['http://github.com/edx/xblock-utils/tarball/master#egg=xblock-utils'],
entry_points={ entry_points={
'xblock.v1': 'drag-and-drop-v2 = drag_and_drop_v2:DragAndDropBlock', 'xblock.v1': 'drag-and-drop-v2 = drag_and_drop_v2:DragAndDropBlock',
}, },
......
from ddt import ddt, data from ddt import ddt, data
from mock import Mock, patch
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import ActionChains from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from workbench.runtime import WorkbenchRuntime
from drag_and_drop_v2.default_data import ( from drag_and_drop_v2.default_data import (
TOP_ZONE_TITLE, MIDDLE_ZONE_TITLE, BOTTOM_ZONE_TITLE, TOP_ZONE_TITLE, MIDDLE_ZONE_TITLE, BOTTOM_ZONE_TITLE,
ITEM_CORRECT_FEEDBACK, ITEM_INCORRECT_FEEDBACK, ITEM_NO_ZONE_FEEDBACK, ITEM_CORRECT_FEEDBACK, ITEM_INCORRECT_FEEDBACK, ITEM_NO_ZONE_FEEDBACK,
...@@ -287,9 +290,9 @@ class InteractionTestBase(object): ...@@ -287,9 +290,9 @@ class InteractionTestBase(object):
self.assertTrue(dialog_modal.is_displayed()) self.assertTrue(dialog_modal.is_displayed())
class BasicInteractionTest(InteractionTestBase): class DefaultDataTestMixin(object):
""" """
Testing interactions with Drag and Drop XBlock against default data. If default data changes this will break. Provides a test scenario with default options.
""" """
PAGE_TITLE = 'Drag and Drop v2' PAGE_TITLE = 'Drag and Drop v2'
PAGE_ID = 'drag_and_drop_v2' PAGE_ID = 'drag_and_drop_v2'
...@@ -317,6 +320,11 @@ class BasicInteractionTest(InteractionTestBase): ...@@ -317,6 +320,11 @@ class BasicInteractionTest(InteractionTestBase):
def _get_scenario_xml(self): # pylint: disable=no-self-use def _get_scenario_xml(self): # pylint: disable=no-self-use
return "<vertical_demo><drag-and-drop-v2/></vertical_demo>" return "<vertical_demo><drag-and-drop-v2/></vertical_demo>"
class BasicInteractionTest(DefaultDataTestMixin, InteractionTestBase):
"""
Testing interactions with Drag and Drop XBlock against default data. If default data changes this will break.
"""
def test_item_positive_feedback_on_good_move(self): def test_item_positive_feedback_on_good_move(self):
self.parameterized_item_positive_feedback_on_good_move(self.items_map) self.parameterized_item_positive_feedback_on_good_move(self.items_map)
...@@ -336,6 +344,84 @@ class BasicInteractionTest(InteractionTestBase): ...@@ -336,6 +344,84 @@ class BasicInteractionTest(InteractionTestBase):
self.interact_with_keyboard_help() self.interact_with_keyboard_help()
class EventsFiredTest(DefaultDataTestMixin, InteractionTestBase, BaseIntegrationTest):
def setUp(self):
mock = Mock()
context = patch.object(WorkbenchRuntime, 'publish', mock)
context.start()
self.addCleanup(context.stop)
self.publish = mock
super(EventsFiredTest, self).setUp()
def _get_scenario_xml(self): # pylint: disable=no-self-use
return "<vertical_demo><drag-and-drop-v2/></vertical_demo>"
def test_loaded(self):
dummy, name, data = self.publish.call_args[0]
self.assertEqual(name, 'xblock.drag-and-drop-v2.loaded')
self.assertEqual(
data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'user_id': 'student_1'
}
)
def test_picked_up(self):
self.parameterized_item_positive_feedback_on_good_move(self.items_map)
dummy, name, data = self.publish.call_args_list[1][0]
self.assertEqual(name, 'xblock.drag-and-drop-v2.item.picked-up')
self.assertEqual(
data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'user_id': 'student_1',
'item_id': 0,
}
)
def test_dropped(self):
self.parameterized_item_positive_feedback_on_good_move(self.items_map)
# Skipping to 3, since 2 is grade event.
dummy, name, data = self.publish.call_args_list[3][0]
self.assertEqual(name, 'xblock.drag-and-drop-v2.item.dropped')
self.assertEqual(
data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'input': None,
'is_correct': True,
'is_correct_location': True,
'item_id': 0,
'location': u'The Top Zone',
'user_id': 'student_1',
}
)
def test_feedback_opened(self):
self.parameterized_item_positive_feedback_on_good_move(self.items_map)
dummy, name, data = self.publish.call_args_list[4][0]
self.assertEqual(name, 'xblock.drag-and-drop-v2.feedback.opened')
self.assertEqual(
data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'content': u'Correct! This one belongs to The Top Zone.',
'user_id': 'student_1',
}
)
def test_feedback_closed(self):
self.parameterized_item_positive_feedback_on_good_move(self.items_map)
dummy, name, data = self.publish.call_args_list[5][0]
self.assertEqual(name, 'xblock.drag-and-drop-v2.feedback.closed')
self.assertEqual(
data, {
'component_id': u'drag-and-drop-v2.drag-and-drop-v2.d0.u0',
'user_id': 'student_1',
'manually': False,
'content': u'Correct! This one belongs to The Top Zone.',
}
)
@ddt @ddt
class KeyboardInteractionTest(BasicInteractionTest, BaseIntegrationTest): class KeyboardInteractionTest(BasicInteractionTest, BaseIntegrationTest):
@data(Keys.RETURN, Keys.SPACE, Keys.CONTROL+'m', Keys.COMMAND+'m') @data(Keys.RETURN, Keys.SPACE, Keys.CONTROL+'m', Keys.COMMAND+'m')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment