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 jstests to selenium: deletecell.js #3465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 0 additions & 107 deletions notebook/tests/notebook/deletecell.js

This file was deleted.

60 changes: 60 additions & 0 deletions notebook/tests/selenium/test_deletecell.py
@@ -0,0 +1,60 @@
import os
import pytest

def cell_is_deletable(nb, index):
JS = 'return Jupyter.notebook.get_cell({}).is_deletable();'.format(index)
return nb.browser.execute_script(JS)

def delete_cell(notebook, index):
notebook.focus_cell(index)
notebook.to_command_mode
notebook.current_cell.send_keys('dd')

def test_delete_cells(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()

# Validate initial state
assert notebook.get_cells_contents() == [a, b, c]
for cell in range(0, 3):
assert cell_is_deletable(notebook, cell)

notebook.set_cell_metadata(0, 'deletable', 'false')
notebook.set_cell_metadata(1, 'deletable', 0
)
assert not cell_is_deletable(notebook, 0)
assert cell_is_deletable(notebook, 1)
assert cell_is_deletable(notebook, 2)

# Try to delete cell a (should not be deleted)
delete_cell(notebook, 0)
assert notebook.get_cells_contents() == [a, b, c]

# Try to delete cell b (should succeed)
delete_cell(notebook, 1)
assert notebook.get_cells_contents() == [a, c]

# Try to delete cell c (should succeed)
delete_cell(notebook, 1)
assert notebook.get_cells_contents() == [a]

# Change the deletable state of cell a
notebook.set_cell_metadata(0, 'deletable', 'true')

# Try to delete cell a (should succeed)
delete_cell(notebook, 0)
assert len(notebook.cells) == 1 # it contains an empty cell

# Make sure copied cells are deletable
notebook.edit_cell(index=0, content=a)
notebook.set_cell_metadata(0, 'deletable', 'false')
assert not cell_is_deletable(notebook, 0)
notebook.to_command_mode()
notebook.current_cell.send_keys('cv')
assert len(notebook.cells) == 2
assert cell_is_deletable(notebook, 1)
8 changes: 8 additions & 0 deletions notebook/tests/selenium/utils.py
Expand Up @@ -127,6 +127,14 @@ def wait_for_stale_cell(self, cell):
wait = WebDriverWait(self.browser, 10)
element = wait.until(EC.staleness_of(cell))

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 set_cell_metadata(self, index, key, value):
JS = 'Jupyter.notebook.get_cell({}).metadata.{} = {}'.format(index, key, value)
return self.browser.execute_script(JS)

def edit_cell(self, cell=None, index=0, content="", render=False):
"""Set the contents of a cell to *content*, by cell object or by index
"""
Expand Down