|
| 1 | +from selenium.webdriver.common.keys import Keys |
| 2 | +from .utils import shift |
| 3 | + |
| 4 | +def test_insert_cell(notebook): |
| 5 | + a = "print('a')" |
| 6 | + b = "print('b')" |
| 7 | + c = "print('c')" |
| 8 | + |
| 9 | + notebook.edit_cell(index=0, content=a) |
| 10 | + notebook.append(b, c) |
| 11 | + notebook.to_command_mode() |
| 12 | + |
| 13 | + assert notebook.get_cells_contents() == [a, b, c] |
| 14 | + |
| 15 | + notebook.to_command_mode() |
| 16 | + notebook.focus_cell(2) |
| 17 | + notebook.convert_cell_type(2, "markdown") |
| 18 | + |
| 19 | + # insert code cell above |
| 20 | + notebook.current_cell.send_keys("a") |
| 21 | + assert notebook.get_cell_contents(2) == "" |
| 22 | + assert notebook.get_cell_type(2) == "code" |
| 23 | + assert len(notebook.cells) == 4 |
| 24 | + |
| 25 | + # insert code cell below |
| 26 | + notebook.current_cell.send_keys("b") |
| 27 | + assert notebook.get_cell_contents(2) == "" |
| 28 | + assert notebook.get_cell_contents(3) == "" |
| 29 | + assert notebook.get_cell_type(3) == "code" |
| 30 | + assert len(notebook.cells) == 5 |
| 31 | + |
| 32 | + notebook.edit_cell(index=1, content="cell1") |
| 33 | + notebook.focus_cell(1) |
| 34 | + notebook.current_cell.send_keys("a") |
| 35 | + assert notebook.get_cell_contents(1) == "" |
| 36 | + assert notebook.get_cell_contents(2) == "cell1" |
| 37 | + |
| 38 | + notebook.edit_cell(index=1, content='cell1') |
| 39 | + notebook.edit_cell(index=2, content='cell2') |
| 40 | + notebook.edit_cell(index=3, content='cell3') |
| 41 | + notebook.focus_cell(2) |
| 42 | + notebook.current_cell.send_keys("b") |
| 43 | + assert notebook.get_cell_contents(1) == "cell1" |
| 44 | + assert notebook.get_cell_contents(2) == "cell2" |
| 45 | + assert notebook.get_cell_contents(3) == "" |
| 46 | + assert notebook.get_cell_contents(4) == "cell3" |
| 47 | + |
| 48 | + # insert above multiple selected cells |
| 49 | + notebook.focus_cell(1) |
| 50 | + shift(notebook.browser, Keys.DOWN) |
| 51 | + notebook.current_cell.send_keys('a') |
| 52 | + |
| 53 | + # insert below multiple selected cells |
| 54 | + notebook.focus_cell(2) |
| 55 | + shift(notebook.browser, Keys.DOWN) |
| 56 | + notebook.current_cell.send_keys('b') |
| 57 | + assert notebook.get_cells_contents()[1:5] == ["", "cell1", "cell2", ""] |
0 commit comments