Commit dfe6105d by Jonathan Piacenti

Fix analytics events and add tests.

parent b29dee80
......@@ -166,15 +166,13 @@ function DragAndDropBlock(runtime, element, configuration) {
var applyState = function() {
// Has the feedback popup been closed?
if (state.closing) {
if (previousFeedback) {
publishEvent({
event_type: 'xblock.drag-and-drop-v2.feedback.closed',
content: previousFeedback,
content: previousFeedback || state.feedback,
manually: state.manually_closed,
});
previousFeedback = undefined;
}
}
// Has feedback been set?
if (state.feedback) {
publishEvent({
......@@ -478,8 +476,8 @@ function DragAndDropBlock(runtime, element, configuration) {
state.manually_closed = false;
}
delete state.feedback;
applyState();
delete state.feedback;
};
var resetExercise = function(evt) {
......
......@@ -29,9 +29,10 @@ setup(
install_requires=[
'XBlock',
'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={
'xblock.v1': 'drag-and-drop-v2 = drag_and_drop_v2:DragAndDropBlock',
},
......
from ddt import ddt, data
from mock import Mock, patch
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from workbench.runtime import WorkbenchRuntime
from drag_and_drop_v2.default_data import (
TOP_ZONE_TITLE, MIDDLE_ZONE_TITLE, BOTTOM_ZONE_TITLE,
ITEM_CORRECT_FEEDBACK, ITEM_INCORRECT_FEEDBACK, ITEM_NO_ZONE_FEEDBACK,
......@@ -287,9 +290,9 @@ class InteractionTestBase(object):
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_ID = 'drag_and_drop_v2'
......@@ -317,6 +320,11 @@ class BasicInteractionTest(InteractionTestBase):
def _get_scenario_xml(self): # pylint: disable=no-self-use
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):
self.parameterized_item_positive_feedback_on_good_move(self.items_map)
......@@ -336,6 +344,84 @@ class BasicInteractionTest(InteractionTestBase):
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
class KeyboardInteractionTest(BasicInteractionTest, BaseIntegrationTest):
@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