Skip to content

Commit 1c87821

Browse files
author
Andres Sanchez
committed
Modifications to test JS funcion in test_merge_cells.py
1 parent 2af7440 commit 1c87821

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

notebook/tests/selenium/test_merge_cells.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ def test_merge_cells(notebook):
44
# Add cells to notebook
55
a = "foo = 5"
66
b = "bar = 10"
7-
c = "print(foo)"
8-
d = "print(bar)"
7+
c = "baz = 15"
8+
d = "print(foo)"
9+
e = "print(bar)"
10+
f = "print(baz)"
911
notebook.edit_cell(index=0, content=a)
10-
notebook.append(b, c, d)
12+
notebook.append(b, c, d, e, f)
1113

1214
# Before merging, there are 4 separate cells
13-
assert notebook.get_cells_contents() == [a, b, c, d]
15+
assert notebook.get_cells_contents() == [a, b, c, d, e, f]
1416

1517
# Focus on the second cell and merge it with the cell above
1618
notebook.focus_cell(1)
1719
notebook.browser.execute_script("Jupyter.notebook.merge_cell_above();")
1820
merged_a_b = "%s\n\n%s" % (a, b)
19-
assert notebook.get_cells_contents() == [merged_a_b, c, d]
21+
assert notebook.get_cells_contents() == [merged_a_b, c, d, e, f]
2022

2123
# Focus on the second cell and merge it with the cell below
2224
notebook.focus_cell(1)
2325
notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();")
2426
merged_c_d = "%s\n\n%s" % (c, d)
25-
assert notebook.get_cells_contents() == [merged_a_b, merged_c_d]
27+
assert notebook.get_cells_contents() == [merged_a_b, merged_c_d, e, f]
2628

2729
# Merge everything down to a single cell
28-
notebook.focus_cell(0)
29-
notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();")
30-
merged_all = "%s\n\n%s" % (merged_a_b, merged_c_d)
30+
notebook.select_command_lines(0,3)
31+
notebook.browser.execute_script("Jupyter.notebook.merge_selected_cells();")
32+
merged_all = "%s\n\n%s\n\n%s\n\n%s" % (merged_a_b, merged_c_d, e, f)
3133
assert notebook.get_cells_contents() == [merged_all]
3234

notebook/tests/selenium/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def cells(self):
6969
7070
"""
7171
return self.browser.find_elements_by_class_name("cell")
72+
73+
@property
74+
def inputs(self):
75+
"""Gets all inputs once they are visible.
76+
77+
"""
78+
return self.browser.find_elements_by_class_name("input")
7279

7380
@property
7481
def current_index(self):
@@ -99,6 +106,12 @@ def focus_cell(self, index=0):
99106
cell.click()
100107
self.to_command_mode()
101108
self.current_cell = cell
109+
110+
def select_command_lines(self, initial_index=0, final_index=0):
111+
self.focus_cell(initial_index)
112+
self.to_command_mode()
113+
for i in range(final_index - initial_index):
114+
shift(self.browser, 'j')
102115

103116
def find_and_replace(self, index=0, find_txt='', replace_txt=''):
104117
self.focus_cell(index)

0 commit comments

Comments
 (0)