Convert dualmode_clipboard to selenium

This commit is contained in:
Luis Rodriguez 2019-05-08 11:08:09 -07:00
parent 3cdc418799
commit 5b162cfdf9
2 changed files with 59 additions and 55 deletions

View File

@ -1,55 +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.then(function () {
// Copy/paste/cut
var num_cells = this.get_cells_length();
this.test.assertEquals(this.get_cell_text(1), a, 'Verify that cell 1 is a');
this.select_cell(1);
this.trigger_keydown('x'); // Cut
this.validate_notebook_state('x', 'command', 1);
this.test.assertEquals(this.get_cells_length(), num_cells-1, 'Verify that a cell was removed.');
this.test.assertEquals(this.get_cell_text(1), b, 'Verify that cell 2 is now where cell 1 was.');
this.select_cell(2);
this.trigger_keydown('v'); // Paste
this.validate_notebook_state('v', 'command', 3); // Selection should move to pasted cell, below current cell.
this.test.assertEquals(this.get_cell_text(3), a, 'Verify that cell 3 has the cut contents.');
this.test.assertEquals(this.get_cells_length(), num_cells, 'Verify a the cell was added.');
this.trigger_keydown('v'); // Paste
this.validate_notebook_state('v', 'command', 4); // Selection should move to pasted cell, below current cell.
this.test.assertEquals(this.get_cell_text(4), a, 'Verify that cell 4 has the cut contents.');
this.test.assertEquals(this.get_cells_length(), num_cells+1, 'Verify a the cell was added.');
this.select_cell(1);
this.trigger_keydown('c'); // Copy
this.validate_notebook_state('c', 'command', 1);
this.test.assertEquals(this.get_cell_text(1), b, 'Verify that cell 1 is b');
this.select_cell(2);
this.trigger_keydown('c'); // Copy
this.validate_notebook_state('c', 'command', 2);
this.test.assertEquals(this.get_cell_text(2), c, 'Verify that cell 2 is c');
this.select_cell(4);
this.trigger_keydown('v'); // Paste
this.validate_notebook_state('v', 'command', 5);
this.test.assertEquals(this.get_cell_text(2), c, 'Verify that cell 2 still has the copied contents.');
this.test.assertEquals(this.get_cell_text(5), c, 'Verify that cell 5 has the copied contents.');
this.test.assertEquals(this.get_cells_length(), num_cells+2, 'Verify a the cell was added.');
this.select_cell(0);
this.trigger_keydown('shift-v'); // Paste
this.validate_notebook_state('shift-v', 'command', 0);
this.test.assertEquals(this.get_cell_text(0), c, 'Verify that cell 0 has the copied contents.');
this.test.assertEquals(this.get_cells_length(), num_cells+3, 'Verify a the cell was added.');
});
});

View File

@ -0,0 +1,59 @@
"""Test"""
from .utils import shift, validate_notebook_state
def test_dualmode_clipboard(notebook):
a = 'print("a")'
notebook.append(a)
notebook.execute_cell(1)
b = 'print("b")'
notebook.append(b)
notebook.execute_cell(2)
c = 'print("c")'
notebook.append(c)
notebook.execute_cell(3)
#Copy/past/cut
num_cells = len(notebook.cells)
assert notebook.get_cell_contents(1) == a #Cell 1 is a
notebook.focus_cell(1)
notebook.body.send_keys("x") #Cut
validate_notebook_state(notebook, 'command', 1)
assert notebook.get_cell_contents(1) == b #Cell 2 is now where cell 1 was
assert len(notebook.cells) == num_cells-1 #A cell was removed
notebook.focus_cell(2)
notebook.body.send_keys("v") #Paste
validate_notebook_state(notebook, 'command', 3)
assert notebook.get_cell_contents(3) == a #Cell 3 has the cut contents
assert len(notebook.cells) == num_cells #A cell was added
notebook.body.send_keys("v") #Paste
validate_notebook_state(notebook, 'command', 4)
assert notebook.get_cell_contents(4) == a #Cell a has the cut contents
assert len(notebook.cells) == num_cells+1 #A cell was added
notebook.focus_cell(1)
notebook.body.send_keys("c") #Copy
validate_notebook_state(notebook, 'command', 1)
assert notebook.get_cell_contents(1) == b #Cell 1 is b
notebook.focus_cell(2)
notebook.body.send_keys("c") #Copy
validate_notebook_state(notebook, 'command', 2)
assert notebook.get_cell_contents(2) == c #Cell 2 is c
notebook.focus_cell(4)
notebook.body.send_keys("v") #Paste
validate_notebook_state(notebook, 'command', 5)
assert notebook.get_cell_contents(2) == c #Cell 2 has the copied contents
assert notebook.get_cell_contents(5) == c #Cell 5 has the copied contents
assert len(notebook.cells) == num_cells+2 #A cell was added
notebook.focus_cell(0)
shift(notebook.browser, 'v') #Paste
validate_notebook_state(notebook, 'command', 0)
assert notebook.get_cell_contents(0) == c #Cell 0 has the copied contents
assert len(notebook.cells) == num_cells+3 #A cell was added