Skip to content

Commit f21650e

Browse files
authored
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
2 parents 1ffd35f + d8120e5 commit f21650e

File tree

3 files changed

+107
-55
lines changed

3 files changed

+107
-55
lines changed

notebook/tests/notebook/dualmode_arrows.js

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""Tests arrow keys on both command and edit mode"""
2+
from selenium.webdriver.common.keys import Keys
3+
4+
def test_dualmode_arrows(notebook):
5+
6+
# Tests in command mode.
7+
# Setting up the cells to test the keys to move up.
8+
notebook.to_command_mode()
9+
[notebook.body.send_keys("b") for i in range(3)]
10+
11+
# Use both "k" and up arrow keys to moving up and enter a value.
12+
# Once located on the top cell, use the up arrow keys to prove the top cell is still selected.
13+
notebook.body.send_keys("k")
14+
notebook.body.send_keys(Keys.ENTER)
15+
notebook.body.send_keys("2")
16+
notebook.to_command_mode()
17+
notebook.body.send_keys(Keys.UP)
18+
notebook.body.send_keys(Keys.ENTER)
19+
notebook.body.send_keys("1")
20+
notebook.to_command_mode()
21+
notebook.body.send_keys("k")
22+
notebook.body.send_keys(Keys.UP)
23+
notebook.body.send_keys(Keys.ENTER)
24+
notebook.body.send_keys("0")
25+
notebook.to_command_mode()
26+
assert notebook.get_cells_contents() == ["0", "1", "2", ""]
27+
28+
# Use the "k" key on the top cell as well
29+
notebook.body.send_keys("k")
30+
notebook.body.send_keys(Keys.ENTER)
31+
notebook.body.send_keys(" edit #1")
32+
notebook.to_command_mode()
33+
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", ""]
34+
35+
# Setting up the cells to test the keys to move down
36+
[notebook.body.send_keys("j") for i in range(3)]
37+
[notebook.body.send_keys("a") for i in range(2)]
38+
notebook.body.send_keys("k")
39+
40+
# Use both "j" key and down arrow keys to moving down and enter a value.
41+
# Once located on the bottom cell, use the down arrow key to prove the bottom cell is still selected.
42+
notebook.body.send_keys(Keys.DOWN)
43+
notebook.body.send_keys(Keys.ENTER)
44+
notebook.body.send_keys("3")
45+
notebook.to_command_mode()
46+
notebook.body.send_keys("j")
47+
notebook.body.send_keys(Keys.ENTER)
48+
notebook.body.send_keys("4")
49+
notebook.to_command_mode()
50+
notebook.body.send_keys("j")
51+
notebook.body.send_keys(Keys.DOWN)
52+
notebook.body.send_keys(Keys.ENTER)
53+
notebook.body.send_keys("5")
54+
notebook.to_command_mode()
55+
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5"]
56+
57+
# Use the "j" key on the top cell as well
58+
notebook.body.send_keys("j")
59+
notebook.body.send_keys(Keys.ENTER)
60+
notebook.body.send_keys(" edit #1")
61+
notebook.to_command_mode()
62+
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1"]
63+
64+
# On the bottom cell, use both left and right arrow keys to prove the bottom cell is still selected.
65+
notebook.body.send_keys(Keys.LEFT)
66+
notebook.body.send_keys(Keys.ENTER)
67+
notebook.body.send_keys(", #2")
68+
notebook.to_command_mode()
69+
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1, #2"]
70+
notebook.body.send_keys(Keys.RIGHT)
71+
notebook.body.send_keys(Keys.ENTER)
72+
notebook.body.send_keys(" and #3")
73+
notebook.to_command_mode()
74+
assert notebook.get_cells_contents() == ["0 edit #1", "1", "2", "3", "4", "5 edit #1, #2 and #3"]
75+
76+
77+
# Tests in edit mode.
78+
# First, erase the previous content and then setup the cells to test the keys to move up.
79+
[notebook.browser.find_element_by_class_name("fa-cut.fa").click() for i in range(6)]
80+
[notebook.body.send_keys("b") for i in range(2)]
81+
notebook.body.send_keys("a")
82+
notebook.body.send_keys(Keys.ENTER)
83+
84+
# Use the up arrow key to move down and enter a value.
85+
# 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.
86+
# Once located on the top cell, use the up arrow key to prove the top cell is still selected.
87+
notebook.body.send_keys(Keys.UP)
88+
notebook.body.send_keys("1")
89+
notebook.body.send_keys(Keys.LEFT)
90+
[notebook.body.send_keys(Keys.UP) for i in range(2)]
91+
notebook.body.send_keys("0")
92+
93+
# Use the down arrow key to move down and enter a value.
94+
# We will use the right arrow key to move one char to the right since moving down puts selector to the last character.
95+
# Once located on the bottom cell, use the down arrow key to prove the bottom cell is still selected.
96+
notebook.body.send_keys(Keys.DOWN)
97+
notebook.body.send_keys(Keys.RIGHT)
98+
notebook.body.send_keys(Keys.DOWN)
99+
notebook.body.send_keys("2")
100+
[notebook.body.send_keys(Keys.DOWN) for i in range(2)]
101+
notebook.body.send_keys("3")
102+
notebook.to_command_mode()
103+
assert notebook.get_cells_contents() == ["0", "1", "2", "3"]

notebook/tests/selenium/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def edit_cell(self, cell=None, index=0, content="", render=False):
239239

240240
# Select & delete anything already in the cell
241241
self.current_cell.send_keys(Keys.ENTER)
242-
ctrl(self.browser, 'a')
242+
cmdtrl(self.browser, 'a')
243243
self.current_cell.send_keys(Keys.DELETE)
244244

245245
for line_no, line in enumerate(content.splitlines()):
@@ -359,9 +359,9 @@ def shift(browser, k):
359359
"""Send key combination Shift+(k)"""
360360
trigger_keystrokes(browser, "shift-%s"%k)
361361

362-
def ctrl(browser, k):
363-
"""Send key combination Ctrl+(k)"""
364-
trigger_keystrokes(browser, "control-%s"%k)
362+
def cmdtrl(browser, k):
363+
"""Send key combination Ctrl+(k) or Command+(k) for MacOS"""
364+
trigger_keystrokes(browser, "command-%s"%k) if os.uname()[0] == "Darwin" else trigger_keystrokes(browser, "control-%s"%k)
365365

366366
def trigger_keystrokes(browser, *keys):
367367
""" Send the keys in sequence to the browser.

0 commit comments

Comments
 (0)