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" ]
0 commit comments