Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert dualmode_insertcell.js #3508

Merged
2 changes: 0 additions & 2 deletions notebook/tests/selenium/test_deletecell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import pytest

def cell_is_deletable(nb, index):
JS = 'return Jupyter.notebook.get_cell({}).is_deletable();'.format(index)
Expand Down
53 changes: 53 additions & 0 deletions notebook/tests/selenium/test_dualmode_insertcell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@


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.focus_cell(2)
notebook.convert_cell_type(2, "markdown")
assert notebook.get_cell_type(2) == "markdown"
notebook.current_cell.send_keys("a")
assert notebook.get_cell_type(3) == "markdown"
notebook.current_cell.send_keys("b")
assert notebook.get_cell_type(4) == "markdown"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the thing this is trying to test no longer works like that. We used to insert a new cell of the same type as the one you had selected, but we eventually decided it was easier to follow if it was always a code cell that was inserted. The test passes, but I think that's two accidents cancelling each other out - the cell you converted to markdown becomes number 3, then number 4, as you insert other cells.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh .. okay. I will remove those steps and assertions then. Do you have any other comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually confused about that. I tried to do the test manually and I wasn't able to insert markdown cells. It all makes sense now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I deeply apologize for the delay in submitting this PR. I will do my best to make sure this doesn't happen again and I hope this doesn't affect your idea of how committed I am to the team and the project.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to apologise! Everyone gets busy at times, and no-one expects volunteer contributors to do things by any set deadline. We might ping you on unfinished pull requests in case you've forgotten about it, or in case you're waiting for us to answer something, but if you don't have time to work on it, that's fine. If it's urgent, someone else can pick it up and finish it, and if not, it can wait. :-)


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"
7 changes: 7 additions & 0 deletions notebook/tests/selenium/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,17 @@ def get_cells_contents(self):
JS = 'return Jupyter.notebook.get_cells().map(function(c) {return c.get_text();})'
return self.browser.execute_script(JS)

def get_cell_contents(self, index=0, selector='div .CodeMirror-code'):
return self.cells[index].find_element_by_css_selector(selector).text

def set_cell_metadata(self, index, key, value):
JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value)
return self.browser.execute_script(JS)

def get_cell_type(self, index=0):
JS = 'return Jupyter.notebook.get_cell({}).cell_type'.format(index)
return self.browser.execute_script(JS)

def set_cell_input_prompt(self, index, prmpt_val):
JS = 'Jupyter.notebook.get_cell({}).set_input_prompt({})'.format(index, prmpt_val)
self.browser.execute_script(JS)
Expand Down