Merge pull request #4142 from askerry/selenium_merge_cells

Migrate test for merge cells api to selenium
Thomas Kluyver 7 years ago committed by GitHub
commit a036ba2cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,43 +0,0 @@
//
// Test merging two notebook cells.
//
casper.notebook_test(function() {
var that = this;
var set_cells_text = function () {
that.evaluate(function() {
var cell_one = IPython.notebook.get_selected_cell();
cell_one.set_text('a = 5');
});
that.trigger_keydown('b');
that.evaluate(function() {
var cell_two = IPython.notebook.get_selected_cell();
cell_two.set_text('print(a)');
});
};
this.evaluate(function () {
IPython.notebook.command_mode();
});
// merge_cell_above()
set_cells_text();
var output_above = this.evaluate(function () {
IPython.notebook.merge_cell_above();
return IPython.notebook.get_selected_cell().get_text();
});
// merge_cell_below()
set_cells_text();
var output_below = this.evaluate(function() {
IPython.notebook.select(0);
IPython.notebook.merge_cell_below();
return IPython.notebook.get_selected_cell().get_text();
});
this.test.assertEquals(output_above, 'a = 5\n\nprint(a)',
'Successful merge_cell_above().');
this.test.assertEquals(output_below, 'a = 5\n\nprint(a)',
'Successful merge_cell_below().');
});

@ -0,0 +1,32 @@
"""Tests the merge cell api."""
def test_merge_cells(notebook):
# Add cells to notebook
a = "foo = 5"
b = "bar = 10"
c = "print(foo)"
d = "print(bar)"
notebook.edit_cell(index=0, content=a)
notebook.append(b, c, d)
# Before merging, there are 4 separate cells
assert notebook.get_cells_contents() == [a, b, c, d]
# Focus on the second cell and merge it with the cell above
notebook.focus_cell(1)
notebook.browser.execute_script("Jupyter.notebook.merge_cell_above();")
merged_a_b = "%s\n\n%s" % (a, b)
assert notebook.get_cells_contents() == [merged_a_b, c, d]
# Focus on the second cell and merge it with the cell below
notebook.focus_cell(1)
notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();")
merged_c_d = "%s\n\n%s" % (c, d)
assert notebook.get_cells_contents() == [merged_a_b, merged_c_d]
# Merge everything down to a single cell
notebook.focus_cell(0)
notebook.browser.execute_script("Jupyter.notebook.merge_cell_below();")
merged_all = "%s\n\n%s" % (merged_a_b, merged_c_d)
assert notebook.get_cells_contents() == [merged_all]
Loading…
Cancel
Save