mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-01 12:56:54 +08:00
Merge pull request #816 from captainsafia/add-multiselect-toggle-tests
Add tests for multiselect toggles
This commit is contained in:
commit
79df8c6469
@ -307,22 +307,23 @@ define(function(require){
|
||||
}
|
||||
},
|
||||
'toggle-cell-output-collapsed' : {
|
||||
help : 'toggle output',
|
||||
help : 'toggle output of selected cells',
|
||||
help_index : 'gb',
|
||||
handler : function (env) {
|
||||
env.notebook.toggle_output();
|
||||
env.notebook.toggle_cells_outputs();
|
||||
}
|
||||
},
|
||||
'toggle-cell-output-scrolled' : {
|
||||
help : 'toggle output scrolling',
|
||||
help : 'toggle output scrolling of selected cells',
|
||||
help_index : 'gc',
|
||||
handler : function (env) {
|
||||
env.notebook.toggle_output_scroll();
|
||||
env.notebook.toggle_cells_outputs_scroll();
|
||||
}
|
||||
},
|
||||
'clear-cell-output' : {
|
||||
help : 'clear output of selected cells',
|
||||
handler : function (env) {
|
||||
env.notebook.clear_output();
|
||||
env.notebook.clear_cells_outputs();
|
||||
}
|
||||
},
|
||||
'move-cell-down' : {
|
||||
|
@ -1645,6 +1645,20 @@ define(function (require) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear multiple selected CodeCells' output areas.
|
||||
*
|
||||
*/
|
||||
Notebook.prototype.clear_cells_outputs = function(indices) {
|
||||
if (!indices) {
|
||||
var indices = this.get_selected_cells_indices();
|
||||
}
|
||||
|
||||
for (var i = 0; i < indices.length; i++){
|
||||
this.clear_output(indices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear each code cell's output area.
|
||||
*/
|
||||
@ -1698,6 +1712,21 @@ define(function (require) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle whether all selected cells' outputs are collapsed or expanded.
|
||||
*
|
||||
* @param {integer} indices - the indices of the cells to toggle
|
||||
*/
|
||||
Notebook.prototype.toggle_cells_outputs = function(indices) {
|
||||
if (!indices) {
|
||||
var indices = this.get_selected_cells_indices();
|
||||
}
|
||||
|
||||
for (var i = 0; i < indices.length; i++){
|
||||
this.toggle_output(indices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the output of all cells.
|
||||
*/
|
||||
@ -1725,6 +1754,21 @@ define(function (require) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle a scrollbar for selected long cells' outputs.
|
||||
*
|
||||
* @param {integer} indices - the indices of the cells to toggle
|
||||
*/
|
||||
Notebook.prototype.toggle_cells_outputs_scroll = function(indices) {
|
||||
if (!indices) {
|
||||
var indices = this.get_selected_cells_indices();
|
||||
}
|
||||
|
||||
for (var i = 0; i < indices.length; i++){
|
||||
this.toggle_output_scroll(indices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the scrolling of long output on all cells.
|
||||
*/
|
||||
|
70
notebook/tests/notebook/multiselect_toggle.js
Normal file
70
notebook/tests/notebook/multiselect_toggle.js
Normal file
@ -0,0 +1,70 @@
|
||||
// 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");
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user