From c5e9bff084f1dd9c134ee6b1f0ce34e1db4f3a37 2014-03-20 23:11:01 From: Jonathan Frederic Date: 2014-03-20 23:11:01 Subject: [PATCH] Cleaned up test names and locations. --- diff --git a/IPython/html/tests/notebook/arrow_keys.js b/IPython/html/tests/notebook/arrow_keys.js deleted file mode 100644 index 6f089ba..0000000 --- a/IPython/html/tests/notebook/arrow_keys.js +++ /dev/null @@ -1,24 +0,0 @@ -// -// Check for errors with up and down arrow presses in a non-empty notebook. -// -casper.notebook_test(function () { - var result = this.evaluate(function() { - IPython.notebook.command_mode(); - pos0 = IPython.notebook.get_selected_index(); - IPython.keyboard.trigger_keydown('b'); - pos1 = IPython.notebook.get_selected_index(); - IPython.keyboard.trigger_keydown('b'); - pos2 = IPython.notebook.get_selected_index(); - // Simulate the "up arrow" and "down arrow" keys. - IPython.keyboard.trigger_keydown('up'); - pos3 = IPython.notebook.get_selected_index(); - IPython.keyboard.trigger_keydown('down'); - pos4 = IPython.notebook.get_selected_index(); - return pos0 == 0 && - pos1 == 1 && - pos2 == 2 && - pos3 == 1 && - pos4 == 2; - }); - this.test.assertTrue(result, 'Up/down arrow okay in non-empty notebook.'); -}); diff --git a/IPython/html/tests/notebook/dualmode.js b/IPython/html/tests/notebook/dualmode.js index 8e218ea..87b5567 100644 --- a/IPython/html/tests/notebook/dualmode.js +++ b/IPython/html/tests/notebook/dualmode.js @@ -15,7 +15,6 @@ casper.notebook_test(function () { this.execute_cell_then(index); this.then(function () { - this.print_log(); this.validate_notebook_state('initial state', 'edit', 0); this.trigger_keydown('esc'); this.validate_notebook_state('esc', 'command', 0); @@ -62,83 +61,10 @@ casper.notebook_test(function () { this.click_cell_editor(3); this.validate_notebook_state('click cell 3', 'edit', 3); - // shift+enter - // last cell in notebook - var base_index = 3; - this.trigger_keydown('shift+enter'); // Creates one cell - this.validate_notebook_state('shift+enter (no cell below)', 'edit', base_index + 1); - // not last cell in notebook & starts in edit mode - this.click_cell_editor(base_index); - this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); - this.trigger_keydown('shift+enter'); - this.validate_notebook_state('shift+enter (cell exists below)', 'command', base_index + 1); - // starts in command mode - this.trigger_keydown('k'); - this.validate_notebook_state('k in comand mode', 'command', base_index); - this.trigger_keydown('shift+enter'); - this.validate_notebook_state('shift+enter (start in command mode)', 'command', base_index + 1); - - // ctrl+enter - // last cell in notebook - base_index++; - this.trigger_keydown('ctrl+enter'); - this.validate_notebook_state('ctrl+enter (no cell below)', 'command', base_index); - // not last cell in notebook & starts in edit mode - this.click_cell_editor(base_index-1); - this.validate_notebook_state('click cell ' + (base_index-1), 'edit', base_index-1); - this.trigger_keydown('ctrl+enter'); - this.validate_notebook_state('ctrl+enter (cell exists below)', 'command', base_index-1); - // starts in command mode - this.trigger_keydown('j'); - this.validate_notebook_state('j in comand mode', 'command', base_index); - this.trigger_keydown('ctrl+enter'); - this.validate_notebook_state('ctrl+enter (start in command mode)', 'command', base_index); - - // alt+enter - // last cell in notebook - this.trigger_keydown('alt+enter'); // Creates one cell - this.validate_notebook_state('alt+enter (no cell below)', 'edit', base_index + 1); - // not last cell in notebook & starts in edit mode - this.click_cell_editor(base_index); - this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); - this.trigger_keydown('alt+enter'); // Creates one cell - this.validate_notebook_state('alt+enter (cell exists below)', 'edit', base_index + 1); - // starts in command mode - this.trigger_keydown('esc', 'k'); - this.validate_notebook_state('k in comand mode', 'command', base_index); - this.trigger_keydown('alt+enter'); // Creates one cell - this.validate_notebook_state('alt+enter (start in command mode)', 'edit', base_index + 1); - - // Notebook will now have 8 cells, the index of the last cell will be 7. - this.test.assertEquals(this.get_cells_length(), 8, '*-enter commands added cells where needed.'); - this.select_cell(7); - this.validate_notebook_state('click cell ' + 7 + ' and esc', 'command', 7); - - // Cell mode change - this.trigger_keydown('r'); - this.test.assertEquals(this.get_cell(7).cell_type, 'raw', 'r; cell is raw'); - this.trigger_keydown('1'); - this.test.assertEquals(this.get_cell(7).cell_type, 'heading', '1; cell is heading'); - this.test.assertEquals(this.get_cell(7).level, 1, '1; cell is level 1 heading'); - this.trigger_keydown('2'); - this.test.assertEquals(this.get_cell(7).level, 2, '2; cell is level 2 heading'); - this.trigger_keydown('3'); - this.test.assertEquals(this.get_cell(7).level, 3, '3; cell is level 3 heading'); - this.trigger_keydown('4'); - this.test.assertEquals(this.get_cell(7).level, 4, '4; cell is level 4 heading'); - this.trigger_keydown('5'); - this.test.assertEquals(this.get_cell(7).level, 5, '5; cell is level 5 heading'); - this.trigger_keydown('6'); - this.test.assertEquals(this.get_cell(7).level, 6, '6; cell is level 6 heading'); - this.trigger_keydown('m'); - this.test.assertEquals(this.get_cell(7).cell_type, 'markdown', 'm; cell is markdown'); - this.trigger_keydown('y'); - this.test.assertEquals(this.get_cell(7).cell_type, 'code', 'y; cell is code'); - // Cell deletion - this.trigger_keydown('d', 'd'); - this.test.assertEquals(this.get_cells_length(), 7, 'dd actually deletes a cell'); - this.validate_notebook_state('dd', 'command', 6); + this.trigger_keydown('esc', 'd', 'd'); + this.test.assertEquals(this.get_cells_length(), 3, 'dd actually deletes a cell'); + this.validate_notebook_state('dd', 'command', 2); // Make sure that if the time between d presses is too long, nothing gets removed. this.trigger_keydown('d'); @@ -146,140 +72,7 @@ casper.notebook_test(function () { this.wait(1000); this.then(function () { this.trigger_keydown('d'); - this.test.assertEquals(this.get_cells_length(), 7, "d, 1 second wait, d doesn't delete a cell"); - this.validate_notebook_state('d, 1 second wait, d', 'command', 6); - - // Up and down in command mode - this.trigger_keydown('j'); - this.validate_notebook_state('j at end of notebook', 'command', 6); - this.trigger_keydown('down'); - this.validate_notebook_state('down at end of notebook', 'command', 6); - this.trigger_keydown('up'); - this.validate_notebook_state('up', 'command', 5); - this.select_cell(0); - this.validate_notebook_state('select 0', 'command', 0); - this.trigger_keydown('k'); - this.validate_notebook_state('k at top of notebook', 'command', 0); - this.trigger_keydown('up'); - this.validate_notebook_state('up at top of notebook', 'command', 0); - this.trigger_keydown('down'); - this.validate_notebook_state('down', 'command', 1); - - // Up and down in edit mode - this.click_cell_editor(6); - this.validate_notebook_state('click cell 6', 'edit', 6); - this.trigger_keydown('down'); - this.validate_notebook_state('down at end of notebook', 'edit', 6); - this.trigger_keydown('up'); - this.validate_notebook_state('up', 'edit', 5); - this.click_cell_editor(0); - this.validate_notebook_state('click 0', 'edit', 0); - this.trigger_keydown('up'); - this.validate_notebook_state('up at top of notebook', 'edit', 0); - this.trigger_keydown('down'); - this.validate_notebook_state('down', 'edit', 1); - - // Markdown rendering / unredering - this.select_cell(6); - this.validate_notebook_state('select 6', 'command', 6); - this.trigger_keydown('m'); - this.test.assertEquals(this.get_cell(6).cell_type, 'markdown', 'm; cell is markdown'); - this.test.assertEquals(this.get_cell(6).rendered, false, 'm; cell is rendered'); - this.trigger_keydown('enter'); - this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); - this.validate_notebook_state('enter', 'edit', 6); - this.trigger_keydown('ctrl+enter'); - this.test.assertEquals(this.get_cell(6).rendered, true, 'ctrl+enter; cell is rendered'); - this.validate_notebook_state('enter', 'command', 6); - this.trigger_keydown('enter'); - this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); - this.select_cell(5); - this.test.assertEquals(this.get_cell(6).rendered, false, 'select 5; cell 6 is still unrendered'); - this.validate_notebook_state('select 5', 'command', 5); - this.select_cell(6); - this.validate_notebook_state('select 6', 'command', 6); - this.trigger_keydown('ctrl+enter'); - this.test.assertEquals(this.get_cell(6).rendered, true, 'ctrl+enter; cell is rendered'); - this.select_cell(5); - this.validate_notebook_state('select 5', 'command', 5); - this.trigger_keydown('shift+enter'); - this.validate_notebook_state('shift+enter', 'command', 6); - this.test.assertEquals(this.get_cell(6).rendered, true, 'shift+enter; cell is rendered'); - this.trigger_keydown('shift+enter'); // Creates one cell - this.validate_notebook_state('shift+enter', 'edit', 7); - this.test.assertEquals(this.get_cell(6).rendered, true, 'shift+enter; cell is rendered'); - - // Cell movement ( ctrl+(k or j) ) - this.select_cell(2); - this.test.assertEquals(this.get_cell_text(2), b, 'select 2; Cell 2 text is correct'); - this.trigger_keydown('ctrl+k'); // Move cell 2 up one - this.test.assertEquals(this.get_cell_text(1), b, 'ctrl+k; Cell 1 text is correct'); - this.test.assertEquals(this.get_cell_text(2), a, 'ctrl+k; Cell 2 text is correct'); - this.validate_notebook_state('ctrl+k', 'command', 1); - this.trigger_keydown('ctrl+j'); // Move cell 1 down one - this.test.assertEquals(this.get_cell_text(1), a, 'ctrl+j; Cell 1 text is correct'); - this.test.assertEquals(this.get_cell_text(2), b, 'ctrl+j; Cell 2 text is correct'); - this.validate_notebook_state('ctrl+j', 'command', 2); - - // Cell insertion - this.trigger_keydown('a'); // Creates one cell - this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); - 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.validate_notebook_state('b', 'command', 3); - - // 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), '', '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(5); - this.trigger_keydown('c'); // Copy - this.validate_notebook_state('c', 'command', 5); - this.test.assertEquals(this.get_cell_text(5), b, 'Verify that cell 5 is b'); - this.select_cell(6); - this.trigger_keydown('c'); // Copy - this.validate_notebook_state('c', 'command', 6); - this.test.assertEquals(this.get_cell_text(6), c, 'Verify that cell 6 is c'); - this.trigger_keydown('v'); // Paste - this.validate_notebook_state('v', 'command', 7); - this.test.assertEquals(this.get_cell_text(6), c, 'Verify that cell 6 still has the copied contents.'); - this.test.assertEquals(this.get_cell_text(7), c, 'Verify that cell 7 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.'); - - // Split and merge cells - this.select_cell(0); - this.trigger_keydown('a', 'enter'); // Create cell above and enter edit mode. - this.validate_notebook_state('a, enter', 'edit', 0); - this.set_cell_text(0, 'abcd'); - this.set_cell_editor_cursor(0, 0, 2); - this.test.assertEquals(this.get_cell_text(0), 'abcd', 'Verify that cell 0 has the new contents.'); - this.trigger_keydown('alt+-'); // Split - this.test.assertEquals(this.get_cell_text(0), 'ab', 'split; Verify that cell 0 has the first half.'); - this.test.assertEquals(this.get_cell_text(1), 'cd', 'split; Verify that cell 1 has the second half.'); - this.validate_notebook_state('split', 'edit', 1); - this.select_cell(0); // Move up to cell 0 - this.trigger_keydown('shift+m'); // Merge - this.validate_notebook_state('merge', 'command', 0); - this.test.assertEquals(this.get_cell_text(0), 'ab\ncd', 'merge; Verify that cell 0 has the merged contents.'); + this.test.assertEquals(this.get_cells_length(), 3, "d, 1 second wait, d doesn't delete a cell"); + this.validate_notebook_state('d, 1 second wait, d', 'command', 2); }); }); diff --git a/IPython/html/tests/notebook/dualmode_arrows.js b/IPython/html/tests/notebook/dualmode_arrows.js new file mode 100644 index 0000000..4b839ac --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_arrows.js @@ -0,0 +1,49 @@ + +// 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 () { + + // Up and down in command mode + this.select_cell(3); + this.trigger_keydown('j'); + this.validate_notebook_state('j at end of notebook', 'command', 3); + this.trigger_keydown('down'); + this.validate_notebook_state('down at end of notebook', 'command', 3); + this.trigger_keydown('up'); + this.validate_notebook_state('up', 'command', 2); + this.select_cell(0); + this.validate_notebook_state('select 0', 'command', 0); + this.trigger_keydown('k'); + this.validate_notebook_state('k at top of notebook', 'command', 0); + this.trigger_keydown('up'); + this.validate_notebook_state('up at top of notebook', 'command', 0); + this.trigger_keydown('down'); + this.validate_notebook_state('down', 'command', 1); + + // Up and down in edit mode + this.click_cell_editor(3); + this.validate_notebook_state('click cell 3', 'edit', 3); + this.trigger_keydown('down'); + this.validate_notebook_state('down at end of notebook', 'edit', 3); + this.trigger_keydown('up'); + this.validate_notebook_state('up', 'edit', 2); + this.click_cell_editor(0); + this.validate_notebook_state('click 0', 'edit', 0); + this.trigger_keydown('up'); + this.validate_notebook_state('up at top of notebook', 'edit', 0); + this.trigger_keydown('down'); + this.validate_notebook_state('down', 'edit', 1); + }); +}); diff --git a/IPython/html/tests/notebook/dualmode_cellinsert.js b/IPython/html/tests/notebook/dualmode_cellinsert.js new file mode 100644 index 0000000..59b89a3 --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_cellinsert.js @@ -0,0 +1,27 @@ + +// 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 () { + // Cell insertion + this.select_cell(2); + this.trigger_keydown('a'); // Creates one cell + this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); + 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.validate_notebook_state('b', 'command', 3); + }); +}); \ No newline at end of file diff --git a/IPython/html/tests/notebook/dualmode_cellmode.js b/IPython/html/tests/notebook/dualmode_cellmode.js new file mode 100644 index 0000000..d4bf5f0 --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_cellmode.js @@ -0,0 +1,28 @@ +// Test keyboard shortcuts that change the cell's mode. + +// Test +casper.notebook_test(function () { + this.then(function () { + // Cell mode change + this.select_cell(0); + this.trigger_keydown('esc','r'); + this.test.assertEquals(this.get_cell(0).cell_type, 'raw', 'r; cell is raw'); + this.trigger_keydown('1'); + this.test.assertEquals(this.get_cell(0).cell_type, 'heading', '1; cell is heading'); + this.test.assertEquals(this.get_cell(0).level, 1, '1; cell is level 1 heading'); + this.trigger_keydown('2'); + this.test.assertEquals(this.get_cell(0).level, 2, '2; cell is level 2 heading'); + this.trigger_keydown('3'); + this.test.assertEquals(this.get_cell(0).level, 3, '3; cell is level 3 heading'); + this.trigger_keydown('4'); + this.test.assertEquals(this.get_cell(0).level, 4, '4; cell is level 4 heading'); + this.trigger_keydown('5'); + this.test.assertEquals(this.get_cell(0).level, 5, '5; cell is level 5 heading'); + this.trigger_keydown('6'); + this.test.assertEquals(this.get_cell(0).level, 6, '6; cell is level 6 heading'); + this.trigger_keydown('m'); + this.test.assertEquals(this.get_cell(0).cell_type, 'markdown', 'm; cell is markdown'); + this.trigger_keydown('y'); + this.test.assertEquals(this.get_cell(0).cell_type, 'code', 'y; cell is code'); + }); +}); \ No newline at end of file diff --git a/IPython/html/tests/notebook/dualmode_clipboard.js b/IPython/html/tests/notebook/dualmode_clipboard.js new file mode 100644 index 0000000..3bda68d --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_clipboard.js @@ -0,0 +1,55 @@ + + +// 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.'); + }); +}); \ No newline at end of file diff --git a/IPython/html/tests/notebook/dualmode_execute.js b/IPython/html/tests/notebook/dualmode_execute.js new file mode 100644 index 0000000..750486e --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_execute.js @@ -0,0 +1,72 @@ +// Test keyboard invoked execution. + +// 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 () { + + // shift+enter + // last cell in notebook + var base_index = 3; + this.select_cell(base_index); + this.trigger_keydown('shift+enter'); // Creates one cell + this.validate_notebook_state('shift+enter (no cell below)', 'edit', base_index + 1); + // not last cell in notebook & starts in edit mode + this.click_cell_editor(base_index); + this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); + this.trigger_keydown('shift+enter'); + this.validate_notebook_state('shift+enter (cell exists below)', 'command', base_index + 1); + // starts in command mode + this.trigger_keydown('k'); + this.validate_notebook_state('k in comand mode', 'command', base_index); + this.trigger_keydown('shift+enter'); + this.validate_notebook_state('shift+enter (start in command mode)', 'command', base_index + 1); + + // ctrl+enter + // last cell in notebook + base_index++; + this.trigger_keydown('ctrl+enter'); + this.validate_notebook_state('ctrl+enter (no cell below)', 'command', base_index); + // not last cell in notebook & starts in edit mode + this.click_cell_editor(base_index-1); + this.validate_notebook_state('click cell ' + (base_index-1), 'edit', base_index-1); + this.trigger_keydown('ctrl+enter'); + this.validate_notebook_state('ctrl+enter (cell exists below)', 'command', base_index-1); + // starts in command mode + this.trigger_keydown('j'); + this.validate_notebook_state('j in comand mode', 'command', base_index); + this.trigger_keydown('ctrl+enter'); + this.validate_notebook_state('ctrl+enter (start in command mode)', 'command', base_index); + + // alt+enter + // last cell in notebook + this.trigger_keydown('alt+enter'); // Creates one cell + this.validate_notebook_state('alt+enter (no cell below)', 'edit', base_index + 1); + // not last cell in notebook & starts in edit mode + this.click_cell_editor(base_index); + this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); + this.trigger_keydown('alt+enter'); // Creates one cell + this.validate_notebook_state('alt+enter (cell exists below)', 'edit', base_index + 1); + // starts in command mode + this.trigger_keydown('esc', 'k'); + this.validate_notebook_state('k in comand mode', 'command', base_index); + this.trigger_keydown('alt+enter'); // Creates one cell + this.validate_notebook_state('alt+enter (start in command mode)', 'edit', base_index + 1); + + // Notebook will now have 8 cells, the index of the last cell will be 7. + this.test.assertEquals(this.get_cells_length(), 8, '*-enter commands added cells where needed.'); + this.select_cell(7); + this.validate_notebook_state('click cell ' + 7 + ' and esc', 'command', 7); + }); +}); \ No newline at end of file diff --git a/IPython/html/tests/notebook/dualmode_markdown.js b/IPython/html/tests/notebook/dualmode_markdown.js new file mode 100644 index 0000000..924ff8c --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_markdown.js @@ -0,0 +1,39 @@ + +// Test +casper.notebook_test(function () { + var a = 'print("a")'; + var index = this.append_cell(a); + this.execute_cell_then(index); + + this.then(function () { + // Markdown rendering / unredering + this.select_cell(1); + this.validate_notebook_state('select 1', 'command', 1); + this.trigger_keydown('m'); + this.test.assertEquals(this.get_cell(1).cell_type, 'markdown', 'm; cell is markdown'); + this.test.assertEquals(this.get_cell(1).rendered, false, 'm; cell is rendered'); + this.trigger_keydown('enter'); + this.test.assertEquals(this.get_cell(1).rendered, false, 'enter; cell is unrendered'); + this.validate_notebook_state('enter', 'edit', 1); + this.trigger_keydown('ctrl+enter'); + this.test.assertEquals(this.get_cell(1).rendered, true, 'ctrl+enter; cell is rendered'); + this.validate_notebook_state('enter', 'command', 1); + this.trigger_keydown('enter'); + this.test.assertEquals(this.get_cell(1).rendered, false, 'enter; cell is unrendered'); + this.select_cell(0); + this.test.assertEquals(this.get_cell(1).rendered, false, 'select 0; cell 1 is still unrendered'); + this.validate_notebook_state('select 0', 'command', 0); + this.select_cell(1); + this.validate_notebook_state('select 1', 'command', 1); + this.trigger_keydown('ctrl+enter'); + this.test.assertEquals(this.get_cell(1).rendered, true, 'ctrl+enter; cell is rendered'); + this.select_cell(0); + this.validate_notebook_state('select 0', 'command', 0); + this.trigger_keydown('shift+enter'); + this.validate_notebook_state('shift+enter', 'command', 1); + this.test.assertEquals(this.get_cell(1).rendered, true, 'shift+enter; cell is rendered'); + this.trigger_keydown('shift+enter'); // Creates one cell + this.validate_notebook_state('shift+enter', 'edit', 2); + this.test.assertEquals(this.get_cell(1).rendered, true, 'shift+enter; cell is rendered'); + }); +}); \ No newline at end of file diff --git a/IPython/html/tests/notebook/dualmode_merge.js b/IPython/html/tests/notebook/dualmode_merge.js new file mode 100644 index 0000000..5d82798 --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_merge.js @@ -0,0 +1,21 @@ + +// Test +casper.notebook_test(function () { + this.then(function () { + // Split and merge cells + this.select_cell(0); + this.trigger_keydown('a', 'enter'); // Create cell above and enter edit mode. + this.validate_notebook_state('a, enter', 'edit', 0); + this.set_cell_text(0, 'abcd'); + this.set_cell_editor_cursor(0, 0, 2); + this.test.assertEquals(this.get_cell_text(0), 'abcd', 'Verify that cell 0 has the new contents.'); + this.trigger_keydown('alt+-'); // Split + this.test.assertEquals(this.get_cell_text(0), 'ab', 'split; Verify that cell 0 has the first half.'); + this.test.assertEquals(this.get_cell_text(1), 'cd', 'split; Verify that cell 1 has the second half.'); + this.validate_notebook_state('split', 'edit', 1); + this.select_cell(0); // Move up to cell 0 + this.trigger_keydown('shift+m'); // Merge + this.validate_notebook_state('merge', 'command', 0); + this.test.assertEquals(this.get_cell_text(0), 'ab\ncd', 'merge; Verify that cell 0 has the merged contents.'); + }); +}); \ No newline at end of file diff --git a/IPython/html/tests/notebook/dualmode_movecell.js b/IPython/html/tests/notebook/dualmode_movecell.js new file mode 100644 index 0000000..713e38d --- /dev/null +++ b/IPython/html/tests/notebook/dualmode_movecell.js @@ -0,0 +1,25 @@ + +// 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); + + this.then(function () { + // Cell movement ( ctrl+(k or j) ) + this.select_cell(2); + this.test.assertEquals(this.get_cell_text(2), b, 'select 2; Cell 2 text is correct'); + this.trigger_keydown('ctrl+k'); // Move cell 2 up one + this.test.assertEquals(this.get_cell_text(1), b, 'ctrl+k; Cell 1 text is correct'); + this.test.assertEquals(this.get_cell_text(2), a, 'ctrl+k; Cell 2 text is correct'); + this.validate_notebook_state('ctrl+k', 'command', 1); + this.trigger_keydown('ctrl+j'); // Move cell 1 down one + this.test.assertEquals(this.get_cell_text(1), a, 'ctrl+j; Cell 1 text is correct'); + this.test.assertEquals(this.get_cell_text(2), b, 'ctrl+j; Cell 2 text is correct'); + this.validate_notebook_state('ctrl+j', 'command', 2); + }); +}); \ No newline at end of file diff --git a/IPython/html/tests/notebook/merge_cells.js b/IPython/html/tests/notebook/merge_cells_api.js similarity index 100% rename from IPython/html/tests/notebook/merge_cells.js rename to IPython/html/tests/notebook/merge_cells_api.js