Merge pull request #4617 from TeresaPartidaS/convert_multiselect_toggle_js_to_selenium

Migrate multiselect toggle test to selenium
Thomas Kluyver 7 years ago committed by GitHub
commit 8ae0c047a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,70 +0,0 @@
// Test
casper.notebook_test(function () {
var that = this;
var a = 'print("a")';
var index = this.append_cell(a);
var b = 'print("b")';
index = this.append_cell(b);
var c = 'print("c")';
index = this.append_cell(c);
this.then(function () {
/**
* Test that cells, which start off not collapsed, are collapsed after
* calling the multiselected cell toggle.
*/
var cell_output_states = this.evaluate(function() {
Jupyter.notebook.select(0);
Jupyter.notebook.extend_selection_by(2);
var indices = Jupyter.notebook.get_selected_cells_indices();
Jupyter.notebook.toggle_cells_outputs();
return indices.map(function(index) {
return Jupyter.notebook.get_cell(index).collapsed;
});
});
this.test.assert(cell_output_states.every(function(cell_output_state) {
return cell_output_state == false;
}), "ensure that all cells are not collapsed");
/**
* Test that cells, which start off not scrolled are scrolled after
* calling the multiselected scroll toggle.
*/
var cell_scrolled_states = this.evaluate(function() {
Jupyter.notebook.select(0);
Jupyter.notebook.extend_selection_by(2);
var indices = Jupyter.notebook.get_selected_cells_indices();
Jupyter.notebook.toggle_cells_outputs_scroll();
return indices.map(function(index) {
return Jupyter.notebook.get_cell(index).output_area.scroll_state;
});
});
this.test.assert(cell_scrolled_states.every(function(cell_scroll_state) {
return cell_scroll_state;
}), "ensure that all have scrolling enabled");
/**
* Test that cells, which start off not cleared are cleared after
* calling the multiselected scroll toggle.
*/
var cell_outputs_cleared = this.evaluate(function() {
Jupyter.notebook.select(0);
Jupyter.notebook.extend_selection_by(2);
var indices = Jupyter.notebook.get_selected_cells_indices();
Jupyter.notebook.clear_cells_outputs();
return indices.map(function(index) {
return Jupyter.notebook.get_cell(index).output_area.element.html();
});
});
this.test.assert(cell_outputs_cleared.every(function(cell_output_state) {
return cell_output_state == "";
}), "ensure that all cells are cleared");
});
});

@ -0,0 +1,48 @@
def test_multiselect_toggle(notebook):
def extend_selection_by(delta):
notebook.browser.execute_script(
"Jupyter.notebook.extend_selection_by(arguments[0]);", delta)
def n_selected_cells():
return notebook.browser.execute_script(
"return Jupyter.notebook.get_selected_cells().length;")
def select_cells():
notebook.focus_cell(0)
extend_selection_by(2)
a = 'print("a")'
b = 'print("b")'
c = 'print("c")'
notebook.edit_cell(index=0, content=a)
notebook.append(b, c)
# Test that cells, which start off not collapsed, are collapsed after
# calling the multiselected cell toggle.
select_cells()
assert n_selected_cells() == 3
notebook.browser.execute_script("Jupyter.notebook.execute_selected_cells();")
select_cells()
notebook.browser.execute_script("Jupyter.notebook.toggle_cells_outputs();")
cell_output_states = notebook.browser.execute_script(
"return Jupyter.notebook.get_cells().map(c => c.collapsed)")
assert cell_output_states == [False] * 3, "ensure that all cells are not collapsed"
# Test that cells, which start off not scrolled are scrolled after
# calling the multiselected scroll toggle.
select_cells()
assert n_selected_cells() == 3
notebook.browser.execute_script("Jupyter.notebook.toggle_cells_outputs_scroll();")
cell_scrolled_states = notebook.browser.execute_script(
"return Jupyter.notebook.get_cells().map(c => c.output_area.scroll_state)")
assert all(cell_scrolled_states), "ensure that all have scrolling enabled"
# Test that cells, which start off not cleared are cleared after
# calling the multiselected scroll toggle.
select_cells()
assert n_selected_cells() == 3
notebook.browser.execute_script("Jupyter.notebook.clear_cells_outputs();")
cell_outputs_cleared = notebook.browser.execute_script(
"return Jupyter.notebook.get_cells().map(c => c.output_area.element.html())")
assert cell_outputs_cleared == [""] * 3, "ensure that all cells are cleared"
Loading…
Cancel
Save