Merge pull request #4512 from emiliotl/convert_dmode_arrows_and_fix_dmode_insert_tests

Fixed dualmode insert test and convert dualmode arrows test to selenium
This commit is contained in:
Thomas Kluyver 2019-04-01 14:57:22 +01:00 committed by GitHub
commit f21650ed0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 55 deletions

View File

@ -1,51 +0,0 @@
// Test
casper.notebook_test(function () {
var a = 'print("a")';
var index = this.append_cell(a);
this.execute_cell_then(index);
var b = 'print("b")';
index = this.append_cell(b);
this.execute_cell_then(index);
var c = 'print("c")';
index = this.append_cell(c);
this.execute_cell_then(index);
this.then(function () {
// Up and down in command mode
this.select_cell(3);
this.trigger_keydown('j');
this.validate_notebook_state('j at end of notebook', 'command', 3);
this.trigger_keydown('down');
this.validate_notebook_state('down at end of notebook', 'command', 3);
this.trigger_keydown('up');
this.validate_notebook_state('up', 'command', 2);
this.select_cell(0);
this.validate_notebook_state('select 0', 'command', 0);
this.trigger_keydown('k');
this.validate_notebook_state('k at top of notebook', 'command', 0);
this.trigger_keydown('up');
this.validate_notebook_state('up at top of notebook', 'command', 0);
this.trigger_keydown('down');
this.validate_notebook_state('down', 'command', 1);
// Up and down in edit mode
this.click_cell_editor(3);
this.validate_notebook_state('click cell 3', 'edit', 3);
this.trigger_keydown('down');
this.validate_notebook_state('down at end of notebook', 'edit', 3);
this.set_cell_editor_cursor(3, 0, 0);
this.trigger_keydown('up');
this.validate_notebook_state('up', 'edit', 2);
this.click_cell_editor(0);
this.validate_notebook_state('click 0', 'edit', 0);
this.trigger_keydown('up');
this.validate_notebook_state('up at top of notebook', 'edit', 0);
this.set_cell_editor_cursor(0, 0, 10);
this.trigger_keydown('down');
this.validate_notebook_state('down', 'edit', 1);
});
});

View File

@ -0,0 +1,103 @@
"""Tests arrow keys on both command and edit mode"""
from selenium.webdriver.common.keys import Keys
def test_dualmode_arrows(notebook):
# Tests in command mode.
# Setting up the cells to test the keys to move up.
notebook.to_command_mode()
[notebook.body.send_keys("b") for i in range(3)]
# Use both "k" and up arrow keys to moving up and enter a value.
# Once located on the top cell, use the up arrow keys to prove the top cell is still selected.
notebook.body.send_keys("k")
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys("2")
notebook.to_command_mode()
notebook.body.send_keys(Keys.UP)
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys("1")
notebook.to_command_mode()
notebook.body.send_keys("k")
notebook.body.send_keys(Keys.UP)
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys("0")
notebook.to_command_mode()
assert notebook.get_cells_contents() == ["0", "1", "2", ""]
# Use the "k" key on the top cell as well
notebook.body.send_keys("k")
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys(" edit #1")
notebook.to_command_mode()
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", ""]
# Setting up the cells to test the keys to move down
[notebook.body.send_keys("j") for i in range(3)]
[notebook.body.send_keys("a") for i in range(2)]
notebook.body.send_keys("k")
# Use both "j" key and down arrow keys to moving down and enter a value.
# Once located on the bottom cell, use the down arrow key to prove the bottom cell is still selected.
notebook.body.send_keys(Keys.DOWN)
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys("3")
notebook.to_command_mode()
notebook.body.send_keys("j")
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys("4")
notebook.to_command_mode()
notebook.body.send_keys("j")
notebook.body.send_keys(Keys.DOWN)
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys("5")
notebook.to_command_mode()
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5"]
# Use the "j" key on the top cell as well
notebook.body.send_keys("j")
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys(" edit #1")
notebook.to_command_mode()
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1"]
# On the bottom cell, use both left and right arrow keys to prove the bottom cell is still selected.
notebook.body.send_keys(Keys.LEFT)
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys(", #2")
notebook.to_command_mode()
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1, #2"]
notebook.body.send_keys(Keys.RIGHT)
notebook.body.send_keys(Keys.ENTER)
notebook.body.send_keys(" and #3")
notebook.to_command_mode()
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1, #2 and #3"]
# Tests in edit mode.
# First, erase the previous content and then setup the cells to test the keys to move up.
[notebook.browser.find_element_by_class_name("fa-cut.fa").click() for i in range(6)]
[notebook.body.send_keys("b") for i in range(2)]
notebook.body.send_keys("a")
notebook.body.send_keys(Keys.ENTER)
# Use the up arrow key to move down and enter a value.
# We will use the left arrow key to move one char to the left since moving up on last character only moves selector to the first one.
# Once located on the top cell, use the up arrow key to prove the top cell is still selected.
notebook.body.send_keys(Keys.UP)
notebook.body.send_keys("1")
notebook.body.send_keys(Keys.LEFT)
[notebook.body.send_keys(Keys.UP) for i in range(2)]
notebook.body.send_keys("0")
# Use the down arrow key to move down and enter a value.
# We will use the right arrow key to move one char to the right since moving down puts selector to the last character.
# Once located on the bottom cell, use the down arrow key to prove the bottom cell is still selected.
notebook.body.send_keys(Keys.DOWN)
notebook.body.send_keys(Keys.RIGHT)
notebook.body.send_keys(Keys.DOWN)
notebook.body.send_keys("2")
[notebook.body.send_keys(Keys.DOWN) for i in range(2)]
notebook.body.send_keys("3")
notebook.to_command_mode()
assert notebook.get_cells_contents() == ["0", "1", "2", "3"]

View File

@ -239,7 +239,7 @@ class Notebook:
# Select & delete anything already in the cell
self.current_cell.send_keys(Keys.ENTER)
ctrl(self.browser, 'a')
cmdtrl(self.browser, 'a')
self.current_cell.send_keys(Keys.DELETE)
for line_no, line in enumerate(content.splitlines()):
@ -359,9 +359,9 @@ def shift(browser, k):
"""Send key combination Shift+(k)"""
trigger_keystrokes(browser, "shift-%s"%k)
def ctrl(browser, k):
"""Send key combination Ctrl+(k)"""
trigger_keystrokes(browser, "control-%s"%k)
def cmdtrl(browser, k):
"""Send key combination Ctrl+(k) or Command+(k) for MacOS"""
trigger_keystrokes(browser, "command-%s"%k) if os.uname()[0] == "Darwin" else trigger_keystrokes(browser, "control-%s"%k)
def trigger_keystrokes(browser, *keys):
""" Send the keys in sequence to the browser.