Skip to content

Commit

Permalink
Merge pull request #50 from open-craft/fix-keyboard-help
Browse files Browse the repository at this point in the history
Fix keyboard help hotkey issues
  • Loading branch information
itsjeyd committed Jan 18, 2016
2 parents 1a119b6 + 4ea84c4 commit ae0832c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 0 additions & 4 deletions drag_and_drop_v2/public/js/drag_and_drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function DragAndDropBlock(runtime, element, configuration) {
var SPC = 32;
var TAB = 9;
var M = 77;
var QUESTION_MARK = 63;

var placementMode = false;
var $selectedItem;
Expand Down Expand Up @@ -47,9 +46,6 @@ function DragAndDropBlock(runtime, element, configuration) {
initDroppable();

$(document).on('keydown mousedown touchstart', closePopup);
$(document).on('keypress', function(evt) {
runOnKey(evt, QUESTION_MARK, showKeyboardHelp);
});
$element.on('click', '.keyboard-help-button', showKeyboardHelp);
$element.on('keydown', '.keyboard-help-button', function(evt) {
runOnKey(evt, RET, showKeyboardHelp);
Expand Down
1 change: 0 additions & 1 deletion drag_and_drop_v2/public/js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
h('li', gettext('Press "Enter", "Space", "Ctrl-m", or "⌘-m" on an item to select it for dropping, then navigate to the zone you want to drop it on.')),
h('li', gettext('Press "Enter", "Space", "Ctrl-m", or "⌘-m" to drop the item on the current zone.')),
h('li', gettext('Press "Escape" if you want to cancel the drop operation (e.g. because you would like to select a different item).')),
h('li', gettext('Press "?" at any time to bring up this dialog.')),
])
]),
h('div.modal-actions', [
Expand Down
33 changes: 28 additions & 5 deletions tests/integration/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def _get_input_div_by_value(self, item_value):
element = self._get_item_by_value(item_value)
return element.find_element_by_class_name('numerical-input')

def _get_dialog_components(self, dialog): # pylint: disable=no-self-use
dialog_modal_overlay = dialog.find_element_by_css_selector('.modal-window-overlay')
dialog_modal = dialog.find_element_by_css_selector('.modal-window')
return dialog_modal_overlay, dialog_modal

def _get_dialog_dismiss_button(self, dialog_modal): # pylint: disable=no-self-use
return dialog_modal.find_element_by_css_selector('.modal-dismiss-button')

def _get_zone_position(self, zone_id):
return self.browser.execute_script(
'return $("div[data-zone=\'{zone_id}\']").prevAll(".zone").length'.format(zone_id=zone_id)
Expand Down Expand Up @@ -268,9 +276,8 @@ def get_locations():
def interact_with_keyboard_help(self, scroll_down=250, use_keyboard=False):
keyboard_help_button = self._get_keyboard_help_button()
keyboard_help_dialog = self._get_keyboard_help_dialog()
dialog_modal_overlay = keyboard_help_dialog.find_element_by_css_selector('.modal-window-overlay')
dialog_modal = keyboard_help_dialog.find_element_by_css_selector('.modal-window')
dialog_dismiss_button = dialog_modal.find_element_by_css_selector('.modal-dismiss-button')
dialog_modal_overlay, dialog_modal = self._get_dialog_components(keyboard_help_dialog)
dialog_dismiss_button = self._get_dialog_dismiss_button(dialog_modal)

# Scroll "Keyboard help" button into view to make sure Selenium can successfully click it
self.scroll_down(pixels=scroll_down)
Expand All @@ -291,12 +298,17 @@ def interact_with_keyboard_help(self, scroll_down=250, use_keyboard=False):
self.assertFalse(dialog_modal_overlay.is_displayed())
self.assertFalse(dialog_modal.is_displayed())

if use_keyboard: # Try again with "?" key
self._page.send_keys("?")
if use_keyboard: # Check if "Keyboard Help" dialog can be dismissed using "ESC"
keyboard_help_button.send_keys(Keys.RETURN)

self.assertTrue(dialog_modal_overlay.is_displayed())
self.assertTrue(dialog_modal.is_displayed())

self._page.send_keys(Keys.ESCAPE)

self.assertFalse(dialog_modal_overlay.is_displayed())
self.assertFalse(dialog_modal.is_displayed())


class BasicInteractionTest(InteractionTestBase):
"""
Expand Down Expand Up @@ -482,3 +494,14 @@ def test_final_feedback_and_reset(self):
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=900)
self.interact_with_keyboard_help(scroll_down=0, use_keyboard=True)

0 comments on commit ae0832c

Please sign in to comment.