Merge pull request #3508 from Sheshtawy/convert-dualmode-insertcell-to-selenium
Convert dualmode_insertcell.js
commit
2aca6f98b0
@ -1,82 +0,0 @@
|
||||
|
||||
// Test
|
||||
casper.notebook_test(function () {
|
||||
var a = 'print("a")';
|
||||
var index = this.append_cell(a);
|
||||
this.execute_cell_then(index);
|
||||
|
||||
var b = 'print("b")';
|
||||
index = this.append_cell(b);
|
||||
this.execute_cell_then(index);
|
||||
|
||||
var c = 'print("c")';
|
||||
index = this.append_cell(c);
|
||||
this.execute_cell_then(index);
|
||||
|
||||
this.thenEvaluate(function() {
|
||||
IPython.notebook.default_cell_type = 'code';
|
||||
});
|
||||
|
||||
this.then(function () {
|
||||
// Cell insertion
|
||||
this.select_cell(2);
|
||||
this.trigger_keydown('m'); // Make it markdown
|
||||
this.trigger_keydown('a'); // Creates one cell
|
||||
this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty');
|
||||
this.test.assertEquals(this.get_cell(2).cell_type, 'code', 'a; inserts a code cell');
|
||||
this.validate_notebook_state('a', 'command', 2);
|
||||
this.trigger_keydown('b'); // Creates one cell
|
||||
this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty');
|
||||
this.test.assertEquals(this.get_cell_text(3), '', 'b; New cell 3 text is empty');
|
||||
this.test.assertEquals(this.get_cell(3).cell_type, 'code', 'b; inserts a code cell');
|
||||
this.validate_notebook_state('b', 'command', 3);
|
||||
});
|
||||
|
||||
this.thenEvaluate(function() {
|
||||
IPython.notebook.class_config.set('default_cell_type', 'selected');
|
||||
});
|
||||
|
||||
this.then(function () {
|
||||
this.select_cell(2);
|
||||
this.trigger_keydown('m'); // switch it to markdown for the next test
|
||||
this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'test cell is markdown');
|
||||
this.trigger_keydown('a'); // new cell above
|
||||
this.test.assertEquals(this.get_cell(2).cell_type, 'markdown', 'a; inserts a markdown cell when markdown selected');
|
||||
this.trigger_keydown('b'); // new cell below
|
||||
this.test.assertEquals(this.get_cell(3).cell_type, 'markdown', 'b; inserts a markdown cell when markdown selected');
|
||||
});
|
||||
|
||||
this.thenEvaluate(function() {
|
||||
IPython.notebook.class_config.set('default_cell_type', 'above');
|
||||
});
|
||||
|
||||
this.then(function () {
|
||||
this.select_cell(2);
|
||||
this.trigger_keydown('y'); // switch it to code for the next test
|
||||
this.test.assertEquals(this.get_cell(2).cell_type, 'code', 'test cell is code');
|
||||
this.trigger_keydown('b'); // new cell below
|
||||
this.test.assertEquals(this.get_cell(3).cell_type, 'code', 'b; inserts a code cell below code cell');
|
||||
this.trigger_keydown('a'); // new cell above
|
||||
this.test.assertEquals(this.get_cell(3).cell_type, 'code', 'a; inserts a code cell above code cell');
|
||||
});
|
||||
|
||||
this.then(function () {
|
||||
this.set_cell_text(1, 'cell1');
|
||||
this.select_cell(1);
|
||||
this.select_cell(2, false);
|
||||
this.trigger_keydown('a');
|
||||
this.test.assertEquals(this.get_cell_text(1), '', 'a; New cell 1 text is empty');
|
||||
this.test.assertEquals(this.get_cell_text(2), 'cell1', 'a; Cell 2 text is old cell 1');
|
||||
|
||||
this.set_cell_text(1, 'cell1');
|
||||
this.set_cell_text(2, 'cell2');
|
||||
this.set_cell_text(3, 'cell3');
|
||||
this.select_cell(1);
|
||||
this.select_cell(2, false);
|
||||
this.trigger_keydown('b');
|
||||
this.test.assertEquals(this.get_cell_text(1), 'cell1', 'b; Cell 1 remains');
|
||||
this.test.assertEquals(this.get_cell_text(2), 'cell2', 'b; Cell 2 remains');
|
||||
this.test.assertEquals(this.get_cell_text(3), '', 'b; Cell 3 is new');
|
||||
this.test.assertEquals(this.get_cell_text(4), 'cell3', 'b; Cell 4 text is old cell 3');
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,57 @@
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
from .utils import shift
|
||||
|
||||
def test_insert_cell(notebook):
|
||||
a = "print('a')"
|
||||
b = "print('b')"
|
||||
c = "print('c')"
|
||||
|
||||
notebook.edit_cell(index=0, content=a)
|
||||
notebook.append(b, c)
|
||||
notebook.to_command_mode()
|
||||
|
||||
assert notebook.get_cells_contents() == [a, b, c]
|
||||
|
||||
notebook.to_command_mode()
|
||||
notebook.focus_cell(2)
|
||||
notebook.convert_cell_type(2, "markdown")
|
||||
|
||||
# insert code cell above
|
||||
notebook.current_cell.send_keys("a")
|
||||
assert notebook.get_cell_contents(2) == ""
|
||||
assert notebook.get_cell_type(2) == "code"
|
||||
assert len(notebook.cells) == 4
|
||||
|
||||
# insert code cell below
|
||||
notebook.current_cell.send_keys("b")
|
||||
assert notebook.get_cell_contents(2) == ""
|
||||
assert notebook.get_cell_contents(3) == ""
|
||||
assert notebook.get_cell_type(3) == "code"
|
||||
assert len(notebook.cells) == 5
|
||||
|
||||
notebook.edit_cell(index=1, content="cell1")
|
||||
notebook.focus_cell(1)
|
||||
notebook.current_cell.send_keys("a")
|
||||
assert notebook.get_cell_contents(1) == ""
|
||||
assert notebook.get_cell_contents(2) == "cell1"
|
||||
|
||||
notebook.edit_cell(index=1, content='cell1')
|
||||
notebook.edit_cell(index=2, content='cell2')
|
||||
notebook.edit_cell(index=3, content='cell3')
|
||||
notebook.focus_cell(2)
|
||||
notebook.current_cell.send_keys("b")
|
||||
assert notebook.get_cell_contents(1) == "cell1"
|
||||
assert notebook.get_cell_contents(2) == "cell2"
|
||||
assert notebook.get_cell_contents(3) == ""
|
||||
assert notebook.get_cell_contents(4) == "cell3"
|
||||
|
||||
# insert above multiple selected cells
|
||||
notebook.focus_cell(1)
|
||||
shift(notebook.browser, Keys.DOWN)
|
||||
notebook.current_cell.send_keys('a')
|
||||
|
||||
# insert below multiple selected cells
|
||||
notebook.focus_cell(2)
|
||||
shift(notebook.browser, Keys.DOWN)
|
||||
notebook.current_cell.send_keys('b')
|
||||
assert notebook.get_cells_contents()[1:5] == ["", "cell1", "cell2", ""]
|
||||
Loading…
Reference in new issue