Skip to content

Commit 6d7b6af

Browse files
authored
Merge pull request #4182 from AndresSan6/merge_selected_cells
Add test for JS function "merge_selected_cells" in test_merge_cells.py
2 parents 2345350 + f27e875 commit 6d7b6af

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

notebook/tests/selenium/test_merge_cells.py

Lines changed: 13 additions & 11 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

12-
# Before merging, there are 4 separate cells
13-
assert notebook.get_cells_contents() == [a, b, c, d]
14+
# Before merging, there are 6 separate cells
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

27-
# 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)
29+
# Merge everything down to a single cell with selected cells
30+
notebook.select_cell_range(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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def cells(self):
121121
122122
"""
123123
return self.browser.find_elements_by_class_name("cell")
124-
124+
125125
@property
126126
def current_index(self):
127127
return self.index(self.current_cell)
@@ -151,6 +151,12 @@ def focus_cell(self, index=0):
151151
cell.click()
152152
self.to_command_mode()
153153
self.current_cell = cell
154+
155+
def select_cell_range(self, initial_index=0, final_index=0):
156+
self.focus_cell(initial_index)
157+
self.to_command_mode()
158+
for i in range(final_index - initial_index):
159+
shift(self.browser, 'j')
154160

155161
def find_and_replace(self, index=0, find_txt='', replace_txt=''):
156162
self.focus_cell(index)

0 commit comments

Comments
 (0)