Show More
@@ -0,0 +1,78 b'' | |||||
|
1 | // Test the notebook dual mode feature. | |||
|
2 | ||||
|
3 | // Test | |||
|
4 | casper.notebook_test(function () { | |||
|
5 | var a = 'print("a")'; | |||
|
6 | var index = this.append_cell(a); | |||
|
7 | this.execute_cell_then(index); | |||
|
8 | ||||
|
9 | var b = 'print("b")'; | |||
|
10 | index = this.append_cell(b); | |||
|
11 | this.execute_cell_then(index); | |||
|
12 | ||||
|
13 | var c = 'print("c")'; | |||
|
14 | index = this.append_cell(c); | |||
|
15 | this.execute_cell_then(index); | |||
|
16 | ||||
|
17 | this.then(function () { | |||
|
18 | this.validate_notebook_state('initial state', 'edit', 0); | |||
|
19 | this.trigger_keydown('esc'); | |||
|
20 | this.validate_notebook_state('esc', 'command', 0); | |||
|
21 | this.trigger_keydown('down'); | |||
|
22 | this.validate_notebook_state('down', 'command', 1); | |||
|
23 | this.trigger_keydown('enter'); | |||
|
24 | this.validate_notebook_state('enter', 'edit', 1); | |||
|
25 | this.trigger_keydown('j'); | |||
|
26 | this.validate_notebook_state('j in edit mode', 'edit', 1); | |||
|
27 | this.trigger_keydown('esc'); | |||
|
28 | this.validate_notebook_state('esc', 'command', 1); | |||
|
29 | this.trigger_keydown('j'); | |||
|
30 | this.validate_notebook_state('j in command mode', 'command', 2); | |||
|
31 | this.click_cell_editor(0); | |||
|
32 | this.validate_notebook_state('click cell 0', 'edit', 0); | |||
|
33 | this.click_cell_editor(3); | |||
|
34 | this.validate_notebook_state('click cell 3', 'edit', 3); | |||
|
35 | this.trigger_keydown('esc'); | |||
|
36 | this.validate_notebook_state('esc', 'command', 3); | |||
|
37 | ||||
|
38 | // Open keyboard help | |||
|
39 | this.evaluate(function(){ | |||
|
40 | $('#keyboard_shortcuts a').click(); | |||
|
41 | }, {}); | |||
|
42 | ||||
|
43 | this.trigger_keydown('k'); | |||
|
44 | this.validate_notebook_state('k in command mode while keyboard help is up', 'command', 3); | |||
|
45 | ||||
|
46 | // Close keyboard help | |||
|
47 | this.evaluate(function(){ | |||
|
48 | $('div.modal button.close').click(); | |||
|
49 | }, {}); | |||
|
50 | ||||
|
51 | this.trigger_keydown('k'); | |||
|
52 | this.validate_notebook_state('k in command mode', 'command', 2); | |||
|
53 | this.click_cell_editor(0); | |||
|
54 | this.validate_notebook_state('click cell 0', 'edit', 0); | |||
|
55 | this.focus_notebook(); | |||
|
56 | this.validate_notebook_state('focus #notebook', 'command', 0); | |||
|
57 | this.click_cell_editor(0); | |||
|
58 | this.validate_notebook_state('click cell 0', 'edit', 0); | |||
|
59 | this.focus_notebook(); | |||
|
60 | this.validate_notebook_state('focus #notebook', 'command', 0); | |||
|
61 | this.click_cell_editor(3); | |||
|
62 | this.validate_notebook_state('click cell 3', 'edit', 3); | |||
|
63 | ||||
|
64 | // Cell deletion | |||
|
65 | this.trigger_keydown('esc', 'd', 'd'); | |||
|
66 | this.test.assertEquals(this.get_cells_length(), 3, 'dd actually deletes a cell'); | |||
|
67 | this.validate_notebook_state('dd', 'command', 2); | |||
|
68 | ||||
|
69 | // Make sure that if the time between d presses is too long, nothing gets removed. | |||
|
70 | this.trigger_keydown('d'); | |||
|
71 | }); | |||
|
72 | this.wait(1000); | |||
|
73 | this.then(function () { | |||
|
74 | this.trigger_keydown('d'); | |||
|
75 | this.test.assertEquals(this.get_cells_length(), 3, "d, 1 second wait, d doesn't delete a cell"); | |||
|
76 | this.validate_notebook_state('d, 1 second wait, d', 'command', 2); | |||
|
77 | }); | |||
|
78 | }); |
@@ -0,0 +1,51 b'' | |||||
|
1 | ||||
|
2 | // Test | |||
|
3 | casper.notebook_test(function () { | |||
|
4 | var a = 'print("a")'; | |||
|
5 | var index = this.append_cell(a); | |||
|
6 | this.execute_cell_then(index); | |||
|
7 | ||||
|
8 | var b = 'print("b")'; | |||
|
9 | index = this.append_cell(b); | |||
|
10 | this.execute_cell_then(index); | |||
|
11 | ||||
|
12 | var c = 'print("c")'; | |||
|
13 | index = this.append_cell(c); | |||
|
14 | this.execute_cell_then(index); | |||
|
15 | ||||
|
16 | this.then(function () { | |||
|
17 | ||||
|
18 | // Up and down in command mode | |||
|
19 | this.select_cell(3); | |||
|
20 | this.trigger_keydown('j'); | |||
|
21 | this.validate_notebook_state('j at end of notebook', 'command', 3); | |||
|
22 | this.trigger_keydown('down'); | |||
|
23 | this.validate_notebook_state('down at end of notebook', 'command', 3); | |||
|
24 | this.trigger_keydown('up'); | |||
|
25 | this.validate_notebook_state('up', 'command', 2); | |||
|
26 | this.select_cell(0); | |||
|
27 | this.validate_notebook_state('select 0', 'command', 0); | |||
|
28 | this.trigger_keydown('k'); | |||
|
29 | this.validate_notebook_state('k at top of notebook', 'command', 0); | |||
|
30 | this.trigger_keydown('up'); | |||
|
31 | this.validate_notebook_state('up at top of notebook', 'command', 0); | |||
|
32 | this.trigger_keydown('down'); | |||
|
33 | this.validate_notebook_state('down', 'command', 1); | |||
|
34 | ||||
|
35 | // Up and down in edit mode | |||
|
36 | this.click_cell_editor(3); | |||
|
37 | this.validate_notebook_state('click cell 3', 'edit', 3); | |||
|
38 | this.trigger_keydown('down'); | |||
|
39 | this.validate_notebook_state('down at end of notebook', 'edit', 3); | |||
|
40 | this.set_cell_editor_cursor(3, 0, 0); | |||
|
41 | this.trigger_keydown('up'); | |||
|
42 | this.validate_notebook_state('up', 'edit', 2); | |||
|
43 | this.click_cell_editor(0); | |||
|
44 | this.validate_notebook_state('click 0', 'edit', 0); | |||
|
45 | this.trigger_keydown('up'); | |||
|
46 | this.validate_notebook_state('up at top of notebook', 'edit', 0); | |||
|
47 | this.set_cell_editor_cursor(0, 0, 10); | |||
|
48 | this.trigger_keydown('down'); | |||
|
49 | this.validate_notebook_state('down', 'edit', 1); | |||
|
50 | }); | |||
|
51 | }); |
@@ -0,0 +1,27 b'' | |||||
|
1 | ||||
|
2 | // Test | |||
|
3 | casper.notebook_test(function () { | |||
|
4 | var a = 'print("a")'; | |||
|
5 | var index = this.append_cell(a); | |||
|
6 | this.execute_cell_then(index); | |||
|
7 | ||||
|
8 | var b = 'print("b")'; | |||
|
9 | index = this.append_cell(b); | |||
|
10 | this.execute_cell_then(index); | |||
|
11 | ||||
|
12 | var c = 'print("c")'; | |||
|
13 | index = this.append_cell(c); | |||
|
14 | this.execute_cell_then(index); | |||
|
15 | ||||
|
16 | this.then(function () { | |||
|
17 | // Cell insertion | |||
|
18 | this.select_cell(2); | |||
|
19 | this.trigger_keydown('a'); // Creates one cell | |||
|
20 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); | |||
|
21 | this.validate_notebook_state('a', 'command', 2); | |||
|
22 | this.trigger_keydown('b'); // Creates one cell | |||
|
23 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); | |||
|
24 | this.test.assertEquals(this.get_cell_text(3), '', 'b; New cell 3 text is empty'); | |||
|
25 | this.validate_notebook_state('b', 'command', 3); | |||
|
26 | }); | |||
|
27 | }); No newline at end of file |
@@ -0,0 +1,28 b'' | |||||
|
1 | // Test keyboard shortcuts that change the cell's mode. | |||
|
2 | ||||
|
3 | // Test | |||
|
4 | casper.notebook_test(function () { | |||
|
5 | this.then(function () { | |||
|
6 | // Cell mode change | |||
|
7 | this.select_cell(0); | |||
|
8 | this.trigger_keydown('esc','r'); | |||
|
9 | this.test.assertEquals(this.get_cell(0).cell_type, 'raw', 'r; cell is raw'); | |||
|
10 | this.trigger_keydown('1'); | |||
|
11 | this.test.assertEquals(this.get_cell(0).cell_type, 'heading', '1; cell is heading'); | |||
|
12 | this.test.assertEquals(this.get_cell(0).level, 1, '1; cell is level 1 heading'); | |||
|
13 | this.trigger_keydown('2'); | |||
|
14 | this.test.assertEquals(this.get_cell(0).level, 2, '2; cell is level 2 heading'); | |||
|
15 | this.trigger_keydown('3'); | |||
|
16 | this.test.assertEquals(this.get_cell(0).level, 3, '3; cell is level 3 heading'); | |||
|
17 | this.trigger_keydown('4'); | |||
|
18 | this.test.assertEquals(this.get_cell(0).level, 4, '4; cell is level 4 heading'); | |||
|
19 | this.trigger_keydown('5'); | |||
|
20 | this.test.assertEquals(this.get_cell(0).level, 5, '5; cell is level 5 heading'); | |||
|
21 | this.trigger_keydown('6'); | |||
|
22 | this.test.assertEquals(this.get_cell(0).level, 6, '6; cell is level 6 heading'); | |||
|
23 | this.trigger_keydown('m'); | |||
|
24 | this.test.assertEquals(this.get_cell(0).cell_type, 'markdown', 'm; cell is markdown'); | |||
|
25 | this.trigger_keydown('y'); | |||
|
26 | this.test.assertEquals(this.get_cell(0).cell_type, 'code', 'y; cell is code'); | |||
|
27 | }); | |||
|
28 | }); No newline at end of file |
@@ -0,0 +1,55 b'' | |||||
|
1 | ||||
|
2 | ||||
|
3 | // Test | |||
|
4 | casper.notebook_test(function () { | |||
|
5 | var a = 'print("a")'; | |||
|
6 | var index = this.append_cell(a); | |||
|
7 | this.execute_cell_then(index); | |||
|
8 | ||||
|
9 | var b = 'print("b")'; | |||
|
10 | index = this.append_cell(b); | |||
|
11 | this.execute_cell_then(index); | |||
|
12 | ||||
|
13 | var c = 'print("c")'; | |||
|
14 | index = this.append_cell(c); | |||
|
15 | this.execute_cell_then(index); | |||
|
16 | ||||
|
17 | this.then(function () { | |||
|
18 | // Copy/paste/cut | |||
|
19 | var num_cells = this.get_cells_length(); | |||
|
20 | this.test.assertEquals(this.get_cell_text(1), a, 'Verify that cell 1 is a'); | |||
|
21 | this.select_cell(1); | |||
|
22 | this.trigger_keydown('x'); // Cut | |||
|
23 | this.validate_notebook_state('x', 'command', 1); | |||
|
24 | this.test.assertEquals(this.get_cells_length(), num_cells-1, 'Verify that a cell was removed.'); | |||
|
25 | this.test.assertEquals(this.get_cell_text(1), b, 'Verify that cell 2 is now where cell 1 was.'); | |||
|
26 | this.select_cell(2); | |||
|
27 | this.trigger_keydown('v'); // Paste | |||
|
28 | this.validate_notebook_state('v', 'command', 3); // Selection should move to pasted cell, below current cell. | |||
|
29 | this.test.assertEquals(this.get_cell_text(3), a, 'Verify that cell 3 has the cut contents.'); | |||
|
30 | this.test.assertEquals(this.get_cells_length(), num_cells, 'Verify a the cell was added.'); | |||
|
31 | this.trigger_keydown('v'); // Paste | |||
|
32 | this.validate_notebook_state('v', 'command', 4); // Selection should move to pasted cell, below current cell. | |||
|
33 | this.test.assertEquals(this.get_cell_text(4), a, 'Verify that cell 4 has the cut contents.'); | |||
|
34 | this.test.assertEquals(this.get_cells_length(), num_cells+1, 'Verify a the cell was added.'); | |||
|
35 | this.select_cell(1); | |||
|
36 | this.trigger_keydown('c'); // Copy | |||
|
37 | this.validate_notebook_state('c', 'command', 1); | |||
|
38 | this.test.assertEquals(this.get_cell_text(1), b, 'Verify that cell 1 is b'); | |||
|
39 | this.select_cell(2); | |||
|
40 | this.trigger_keydown('c'); // Copy | |||
|
41 | this.validate_notebook_state('c', 'command', 2); | |||
|
42 | this.test.assertEquals(this.get_cell_text(2), c, 'Verify that cell 2 is c'); | |||
|
43 | this.select_cell(4); | |||
|
44 | this.trigger_keydown('v'); // Paste | |||
|
45 | this.validate_notebook_state('v', 'command', 5); | |||
|
46 | this.test.assertEquals(this.get_cell_text(2), c, 'Verify that cell 2 still has the copied contents.'); | |||
|
47 | this.test.assertEquals(this.get_cell_text(5), c, 'Verify that cell 5 has the copied contents.'); | |||
|
48 | this.test.assertEquals(this.get_cells_length(), num_cells+2, 'Verify a the cell was added.'); | |||
|
49 | this.select_cell(0); | |||
|
50 | this.trigger_keydown('shift-v'); // Paste | |||
|
51 | this.validate_notebook_state('shift-v', 'command', 0); | |||
|
52 | this.test.assertEquals(this.get_cell_text(0), c, 'Verify that cell 0 has the copied contents.'); | |||
|
53 | this.test.assertEquals(this.get_cells_length(), num_cells+3, 'Verify a the cell was added.'); | |||
|
54 | }); | |||
|
55 | }); No newline at end of file |
@@ -0,0 +1,72 b'' | |||||
|
1 | // Test keyboard invoked execution. | |||
|
2 | ||||
|
3 | // Test | |||
|
4 | casper.notebook_test(function () { | |||
|
5 | var a = 'print("a")'; | |||
|
6 | var index = this.append_cell(a); | |||
|
7 | this.execute_cell_then(index); | |||
|
8 | ||||
|
9 | var b = 'print("b")'; | |||
|
10 | index = this.append_cell(b); | |||
|
11 | this.execute_cell_then(index); | |||
|
12 | ||||
|
13 | var c = 'print("c")'; | |||
|
14 | index = this.append_cell(c); | |||
|
15 | this.execute_cell_then(index); | |||
|
16 | ||||
|
17 | this.then(function () { | |||
|
18 | ||||
|
19 | // shift-enter | |||
|
20 | // last cell in notebook | |||
|
21 | var base_index = 3; | |||
|
22 | this.select_cell(base_index); | |||
|
23 | this.trigger_keydown('shift-enter'); // Creates one cell | |||
|
24 | this.validate_notebook_state('shift-enter (no cell below)', 'edit', base_index + 1); | |||
|
25 | // not last cell in notebook & starts in edit mode | |||
|
26 | this.click_cell_editor(base_index); | |||
|
27 | this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); | |||
|
28 | this.trigger_keydown('shift-enter'); | |||
|
29 | this.validate_notebook_state('shift-enter (cell exists below)', 'command', base_index + 1); | |||
|
30 | // starts in command mode | |||
|
31 | this.trigger_keydown('k'); | |||
|
32 | this.validate_notebook_state('k in comand mode', 'command', base_index); | |||
|
33 | this.trigger_keydown('shift-enter'); | |||
|
34 | this.validate_notebook_state('shift-enter (start in command mode)', 'command', base_index + 1); | |||
|
35 | ||||
|
36 | // ctrl-enter | |||
|
37 | // last cell in notebook | |||
|
38 | base_index++; | |||
|
39 | this.trigger_keydown('ctrl-enter'); | |||
|
40 | this.validate_notebook_state('ctrl-enter (no cell below)', 'command', base_index); | |||
|
41 | // not last cell in notebook & starts in edit mode | |||
|
42 | this.click_cell_editor(base_index-1); | |||
|
43 | this.validate_notebook_state('click cell ' + (base_index-1), 'edit', base_index-1); | |||
|
44 | this.trigger_keydown('ctrl-enter'); | |||
|
45 | this.validate_notebook_state('ctrl-enter (cell exists below)', 'command', base_index-1); | |||
|
46 | // starts in command mode | |||
|
47 | this.trigger_keydown('j'); | |||
|
48 | this.validate_notebook_state('j in comand mode', 'command', base_index); | |||
|
49 | this.trigger_keydown('ctrl-enter'); | |||
|
50 | this.validate_notebook_state('ctrl-enter (start in command mode)', 'command', base_index); | |||
|
51 | ||||
|
52 | // alt-enter | |||
|
53 | // last cell in notebook | |||
|
54 | this.trigger_keydown('alt-enter'); // Creates one cell | |||
|
55 | this.validate_notebook_state('alt-enter (no cell below)', 'edit', base_index + 1); | |||
|
56 | // not last cell in notebook & starts in edit mode | |||
|
57 | this.click_cell_editor(base_index); | |||
|
58 | this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); | |||
|
59 | this.trigger_keydown('alt-enter'); // Creates one cell | |||
|
60 | this.validate_notebook_state('alt-enter (cell exists below)', 'edit', base_index + 1); | |||
|
61 | // starts in command mode | |||
|
62 | this.trigger_keydown('esc', 'k'); | |||
|
63 | this.validate_notebook_state('k in comand mode', 'command', base_index); | |||
|
64 | this.trigger_keydown('alt-enter'); // Creates one cell | |||
|
65 | this.validate_notebook_state('alt-enter (start in command mode)', 'edit', base_index + 1); | |||
|
66 | ||||
|
67 | // Notebook will now have 8 cells, the index of the last cell will be 7. | |||
|
68 | this.test.assertEquals(this.get_cells_length(), 8, '*-enter commands added cells where needed.'); | |||
|
69 | this.select_cell(7); | |||
|
70 | this.validate_notebook_state('click cell ' + 7 + ' and esc', 'command', 7); | |||
|
71 | }); | |||
|
72 | }); No newline at end of file |
@@ -0,0 +1,39 b'' | |||||
|
1 | ||||
|
2 | // Test | |||
|
3 | casper.notebook_test(function () { | |||
|
4 | var a = 'print("a")'; | |||
|
5 | var index = this.append_cell(a); | |||
|
6 | this.execute_cell_then(index); | |||
|
7 | ||||
|
8 | this.then(function () { | |||
|
9 | // Markdown rendering / unredering | |||
|
10 | this.select_cell(1); | |||
|
11 | this.validate_notebook_state('select 1', 'command', 1); | |||
|
12 | this.trigger_keydown('m'); | |||
|
13 | this.test.assertEquals(this.get_cell(1).cell_type, 'markdown', 'm; cell is markdown'); | |||
|
14 | this.test.assertEquals(this.get_cell(1).rendered, false, 'm; cell is rendered'); | |||
|
15 | this.trigger_keydown('enter'); | |||
|
16 | this.test.assertEquals(this.get_cell(1).rendered, false, 'enter; cell is unrendered'); | |||
|
17 | this.validate_notebook_state('enter', 'edit', 1); | |||
|
18 | this.trigger_keydown('ctrl-enter'); | |||
|
19 | this.test.assertEquals(this.get_cell(1).rendered, true, 'ctrl-enter; cell is rendered'); | |||
|
20 | this.validate_notebook_state('enter', 'command', 1); | |||
|
21 | this.trigger_keydown('enter'); | |||
|
22 | this.test.assertEquals(this.get_cell(1).rendered, false, 'enter; cell is unrendered'); | |||
|
23 | this.select_cell(0); | |||
|
24 | this.test.assertEquals(this.get_cell(1).rendered, false, 'select 0; cell 1 is still unrendered'); | |||
|
25 | this.validate_notebook_state('select 0', 'command', 0); | |||
|
26 | this.select_cell(1); | |||
|
27 | this.validate_notebook_state('select 1', 'command', 1); | |||
|
28 | this.trigger_keydown('ctrl-enter'); | |||
|
29 | this.test.assertEquals(this.get_cell(1).rendered, true, 'ctrl-enter; cell is rendered'); | |||
|
30 | this.select_cell(0); | |||
|
31 | this.validate_notebook_state('select 0', 'command', 0); | |||
|
32 | this.trigger_keydown('shift-enter'); | |||
|
33 | this.validate_notebook_state('shift-enter', 'command', 1); | |||
|
34 | this.test.assertEquals(this.get_cell(1).rendered, true, 'shift-enter; cell is rendered'); | |||
|
35 | this.trigger_keydown('shift-enter'); // Creates one cell | |||
|
36 | this.validate_notebook_state('shift-enter', 'edit', 2); | |||
|
37 | this.test.assertEquals(this.get_cell(1).rendered, true, 'shift-enter; cell is rendered'); | |||
|
38 | }); | |||
|
39 | }); No newline at end of file |
@@ -0,0 +1,21 b'' | |||||
|
1 | ||||
|
2 | // Test | |||
|
3 | casper.notebook_test(function () { | |||
|
4 | this.then(function () { | |||
|
5 | // Split and merge cells | |||
|
6 | this.select_cell(0); | |||
|
7 | this.trigger_keydown('a', 'enter'); // Create cell above and enter edit mode. | |||
|
8 | this.validate_notebook_state('a, enter', 'edit', 0); | |||
|
9 | this.set_cell_text(0, 'abcd'); | |||
|
10 | this.set_cell_editor_cursor(0, 0, 2); | |||
|
11 | this.test.assertEquals(this.get_cell_text(0), 'abcd', 'Verify that cell 0 has the new contents.'); | |||
|
12 | this.trigger_keydown('ctrl-shift-subtract'); // Split | |||
|
13 | this.test.assertEquals(this.get_cell_text(0), 'ab', 'split; Verify that cell 0 has the first half.'); | |||
|
14 | this.test.assertEquals(this.get_cell_text(1), 'cd', 'split; Verify that cell 1 has the second half.'); | |||
|
15 | this.validate_notebook_state('split', 'edit', 1); | |||
|
16 | this.select_cell(0); // Move up to cell 0 | |||
|
17 | this.trigger_keydown('shift-m'); // Merge | |||
|
18 | this.validate_notebook_state('merge', 'command', 0); | |||
|
19 | this.test.assertEquals(this.get_cell_text(0), 'ab\ncd', 'merge; Verify that cell 0 has the merged contents.'); | |||
|
20 | }); | |||
|
21 | }); No newline at end of file |
@@ -0,0 +1,25 b'' | |||||
|
1 | ||||
|
2 | // Test | |||
|
3 | casper.notebook_test(function () { | |||
|
4 | var a = 'print("a")'; | |||
|
5 | var index = this.append_cell(a); | |||
|
6 | this.execute_cell_then(index); | |||
|
7 | ||||
|
8 | var b = 'print("b")'; | |||
|
9 | index = this.append_cell(b); | |||
|
10 | this.execute_cell_then(index); | |||
|
11 | ||||
|
12 | this.then(function () { | |||
|
13 | // Cell movement ( ctrl-(k or j) ) | |||
|
14 | this.select_cell(2); | |||
|
15 | this.test.assertEquals(this.get_cell_text(2), b, 'select 2; Cell 2 text is correct'); | |||
|
16 | this.trigger_keydown('ctrl-k'); // Move cell 2 up one | |||
|
17 | this.test.assertEquals(this.get_cell_text(1), b, 'ctrl-k; Cell 1 text is correct'); | |||
|
18 | this.test.assertEquals(this.get_cell_text(2), a, 'ctrl-k; Cell 2 text is correct'); | |||
|
19 | this.validate_notebook_state('ctrl-k', 'command', 1); | |||
|
20 | this.trigger_keydown('ctrl-j'); // Move cell 1 down one | |||
|
21 | this.test.assertEquals(this.get_cell_text(1), a, 'ctrl-j; Cell 1 text is correct'); | |||
|
22 | this.test.assertEquals(this.get_cell_text(2), b, 'ctrl-j; Cell 2 text is correct'); | |||
|
23 | this.validate_notebook_state('ctrl-j', 'command', 2); | |||
|
24 | }); | |||
|
25 | }); No newline at end of file |
@@ -128,15 +128,6 b' IPython.keyboard = (function (IPython) {' | |||||
128 | return shortcut; |
|
128 | return shortcut; | |
129 | }; |
|
129 | }; | |
130 |
|
130 | |||
131 | var trigger_keydown = function (shortcut, element) { |
|
|||
132 | // Trigger shortcut keydown on an element |
|
|||
133 | element = element || document; |
|
|||
134 | element = $(element); |
|
|||
135 | var event = shortcut_to_event(shortcut, 'keydown'); |
|
|||
136 | element.trigger(event); |
|
|||
137 | }; |
|
|||
138 |
|
||||
139 |
|
||||
140 | // Shortcut manager class |
|
131 | // Shortcut manager class | |
141 |
|
132 | |||
142 | var ShortcutManager = function (delay) { |
|
133 | var ShortcutManager = function (delay) { | |
@@ -262,8 +253,7 b' IPython.keyboard = (function (IPython) {' | |||||
262 | normalize_key : normalize_key, |
|
253 | normalize_key : normalize_key, | |
263 | normalize_shortcut : normalize_shortcut, |
|
254 | normalize_shortcut : normalize_shortcut, | |
264 | shortcut_to_event : shortcut_to_event, |
|
255 | shortcut_to_event : shortcut_to_event, | |
265 |
event_to_shortcut : event_to_shortcut |
|
256 | event_to_shortcut : event_to_shortcut | |
266 | trigger_keydown : trigger_keydown |
|
|||
267 | }; |
|
257 | }; | |
268 |
|
258 | |||
269 | }(IPython)); |
|
259 | }(IPython)); |
@@ -10,12 +10,12 b' casper.notebook_test(function () {' | |||||
10 | for (i = 0; i < ncells; i++) { |
|
10 | for (i = 0; i < ncells; i++) { | |
11 | IPython.notebook.delete_cell(); |
|
11 | IPython.notebook.delete_cell(); | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | // Simulate the "up arrow" and "down arrow" keys. |
|
|||
15 | // |
|
|||
16 | IPython.keyboard.trigger_keydown('up'); |
|
|||
17 | IPython.keyboard.trigger_keydown('down'); |
|
|||
18 | return true; |
|
14 | return true; | |
19 | }); |
|
15 | }); | |
|
16 | ||||
|
17 | // Simulate the "up arrow" and "down arrow" keys. | |||
|
18 | this.trigger_keydown('up'); | |||
|
19 | this.trigger_keydown('down'); | |||
20 | this.test.assertTrue(result, 'Up/down arrow okay in empty notebook.'); |
|
20 | this.test.assertTrue(result, 'Up/down arrow okay in empty notebook.'); | |
21 | }); |
|
21 | }); |
@@ -22,7 +22,11 b' casper.notebook_test(function () {' | |||||
22 | var cell = IPython.notebook.get_cell(0); |
|
22 | var cell = IPython.notebook.get_cell(0); | |
23 | cell.set_text('a=11; print(a)'); |
|
23 | cell.set_text('a=11; print(a)'); | |
24 | cell.clear_output(); |
|
24 | cell.clear_output(); | |
25 | IPython.keyboard.trigger_keydown('shift-enter'); |
|
25 | }); | |
|
26 | ||||
|
27 | this.then(function(){ | |||
|
28 | ||||
|
29 | this.trigger_keydown('shift-enter'); | |||
26 | }); |
|
30 | }); | |
27 |
|
31 | |||
28 | this.wait_for_output(0); |
|
32 | this.wait_for_output(0); | |
@@ -41,7 +45,10 b' casper.notebook_test(function () {' | |||||
41 | var cell = IPython.notebook.get_cell(0); |
|
45 | var cell = IPython.notebook.get_cell(0); | |
42 | cell.set_text('a=12; print(a)'); |
|
46 | cell.set_text('a=12; print(a)'); | |
43 | cell.clear_output(); |
|
47 | cell.clear_output(); | |
44 | IPython.keyboard.trigger_keydown('ctrl-enter'); |
|
48 | }); | |
|
49 | ||||
|
50 | this.then(function(){ | |||
|
51 | this.trigger_keydown('ctrl-enter'); | |||
45 | }); |
|
52 | }); | |
46 |
|
53 | |||
47 | this.wait_for_output(0); |
|
54 | this.wait_for_output(0); |
@@ -31,8 +31,8 b' casper.notebook_test(function () {' | |||||
31 | }); |
|
31 | }); | |
32 |
|
32 | |||
33 | // interrupt using Ctrl-M I keyboard shortcut |
|
33 | // interrupt using Ctrl-M I keyboard shortcut | |
34 |
this.then |
|
34 | this.then(function(){ | |
35 |
|
|
35 | this.trigger_keydown('i'); | |
36 | }); |
|
36 | }); | |
37 |
|
37 | |||
38 | this.wait_for_output(0); |
|
38 | this.wait_for_output(0); |
@@ -2,37 +2,42 b'' | |||||
2 | // Test merging two notebook cells. |
|
2 | // Test merging two notebook cells. | |
3 | // |
|
3 | // | |
4 | casper.notebook_test(function() { |
|
4 | casper.notebook_test(function() { | |
5 | var output = this.evaluate(function () { |
|
5 | var that = this; | |
6 | // Fill in test data. |
|
6 | var set_cells_text = function () { | |
7 | IPython.notebook.command_mode(); |
|
7 | that.evaluate(function() { | |
8 | var set_cell_text = function () { |
|
|||
9 | var cell_one = IPython.notebook.get_selected_cell(); |
|
8 | var cell_one = IPython.notebook.get_selected_cell(); | |
10 | cell_one.set_text('a = 5'); |
|
9 | cell_one.set_text('a = 5'); | |
11 |
|
|
10 | }); | |
12 | IPython.keyboard.trigger_keydown('b'); |
|
11 | ||
|
12 | that.trigger_keydown('b'); | |||
|
13 | ||||
|
14 | that.evaluate(function() { | |||
13 | var cell_two = IPython.notebook.get_selected_cell(); |
|
15 | var cell_two = IPython.notebook.get_selected_cell(); | |
14 | cell_two.set_text('print(a)'); |
|
16 | cell_two.set_text('print(a)'); | |
15 | }; |
|
17 | }); | |
|
18 | }; | |||
|
19 | ||||
|
20 | this.evaluate(function () { | |||
|
21 | IPython.notebook.command_mode(); | |||
|
22 | }); | |||
16 |
|
23 | |||
17 |
|
|
24 | // merge_cell_above() | |
18 |
|
|
25 | set_cells_text(); | |
|
26 | var output_above = this.evaluate(function () { | |||
19 | IPython.notebook.merge_cell_above(); |
|
27 | IPython.notebook.merge_cell_above(); | |
20 |
|
|
28 | return IPython.notebook.get_selected_cell().get_text(); | |
|
29 | }); | |||
21 |
|
30 | |||
22 |
|
|
31 | // merge_cell_below() | |
23 |
|
|
32 | set_cells_text(); | |
|
33 | var output_below = this.evaluate(function() { | |||
24 | IPython.notebook.select(0); |
|
34 | IPython.notebook.select(0); | |
25 | IPython.notebook.merge_cell_below(); |
|
35 | IPython.notebook.merge_cell_below(); | |
26 |
|
|
36 | return IPython.notebook.get_selected_cell().get_text(); | |
27 |
|
||||
28 | return { |
|
|||
29 | above: merged_above.get_text(), |
|
|||
30 | below: merged_below.get_text() |
|
|||
31 | }; |
|
|||
32 | }); |
|
37 | }); | |
33 |
|
38 | |||
34 |
this.test.assertEquals(output |
|
39 | this.test.assertEquals(output_above, 'a = 5\nprint(a)', | |
35 | 'Successful merge_cell_above().'); |
|
40 | 'Successful merge_cell_above().'); | |
36 |
this.test.assertEquals(output |
|
41 | this.test.assertEquals(output_below, 'a = 5\nprint(a)', | |
37 | 'Successful merge_cell_below().'); |
|
42 | 'Successful merge_cell_below().'); | |
38 | }); |
|
43 | }); |
@@ -2,15 +2,15 b'' | |||||
2 | // Utility functions for the HTML notebook's CasperJS tests. |
|
2 | // Utility functions for the HTML notebook's CasperJS tests. | |
3 | // |
|
3 | // | |
4 |
|
4 | |||
5 | // Get the URL of a notebook server on which to run tests. |
|
|||
6 | casper.get_notebook_server = function () { |
|
5 | casper.get_notebook_server = function () { | |
7 | port = casper.cli.get("port") |
|
6 | // Get the URL of a notebook server on which to run tests. | |
|
7 | port = casper.cli.get("port"); | |||
8 | port = (typeof port === 'undefined') ? '8888' : port; |
|
8 | port = (typeof port === 'undefined') ? '8888' : port; | |
9 | return 'http://127.0.0.1:' + port |
|
9 | return 'http://127.0.0.1:' + port; | |
10 | }; |
|
10 | }; | |
11 |
|
11 | |||
12 | // Create and open a new notebook. |
|
|||
13 | casper.open_new_notebook = function () { |
|
12 | casper.open_new_notebook = function () { | |
|
13 | // Create and open a new notebook. | |||
14 | var baseUrl = this.get_notebook_server(); |
|
14 | var baseUrl = this.get_notebook_server(); | |
15 | this.start(baseUrl); |
|
15 | this.start(baseUrl); | |
16 | this.thenClick('button#new_notebook'); |
|
16 | this.thenClick('button#new_notebook'); | |
@@ -34,15 +34,15 b' casper.open_new_notebook = function () {' | |||||
34 | }); |
|
34 | }); | |
35 | }; |
|
35 | }; | |
36 |
|
36 | |||
37 | // Return whether or not the kernel is running. |
|
|||
38 | casper.kernel_running = function kernel_running() { |
|
37 | casper.kernel_running = function kernel_running() { | |
|
38 | // Return whether or not the kernel is running. | |||
39 | return this.evaluate(function kernel_running() { |
|
39 | return this.evaluate(function kernel_running() { | |
40 | return IPython.notebook.kernel.running; |
|
40 | return IPython.notebook.kernel.running; | |
41 | }); |
|
41 | }); | |
42 | }; |
|
42 | }; | |
43 |
|
43 | |||
44 | // Shut down the current notebook's kernel. |
|
|||
45 | casper.shutdown_current_kernel = function () { |
|
44 | casper.shutdown_current_kernel = function () { | |
|
45 | // Shut down the current notebook's kernel. | |||
46 | this.thenEvaluate(function() { |
|
46 | this.thenEvaluate(function() { | |
47 | IPython.notebook.kernel.kill(); |
|
47 | IPython.notebook.kernel.kill(); | |
48 | }); |
|
48 | }); | |
@@ -50,8 +50,9 b' casper.shutdown_current_kernel = function () {' | |||||
50 | this.wait(1000); |
|
50 | this.wait(1000); | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | // Delete created notebook. |
|
|||
54 | casper.delete_current_notebook = function () { |
|
53 | casper.delete_current_notebook = function () { | |
|
54 | // Delete created notebook. | |||
|
55 | ||||
55 | // For some unknown reason, this doesn't work?!? |
|
56 | // For some unknown reason, this doesn't work?!? | |
56 | this.thenEvaluate(function() { |
|
57 | this.thenEvaluate(function() { | |
57 | IPython.notebook.delete(); |
|
58 | IPython.notebook.delete(); | |
@@ -59,6 +60,7 b' casper.delete_current_notebook = function () {' | |||||
59 | }; |
|
60 | }; | |
60 |
|
61 | |||
61 | casper.wait_for_busy = function () { |
|
62 | casper.wait_for_busy = function () { | |
|
63 | // Waits for the notebook to enter a busy state. | |||
62 | this.waitFor(function () { |
|
64 | this.waitFor(function () { | |
63 | return this.evaluate(function () { |
|
65 | return this.evaluate(function () { | |
64 | return IPython._status == 'busy'; |
|
66 | return IPython._status == 'busy'; | |
@@ -67,6 +69,7 b' casper.wait_for_busy = function () {' | |||||
67 | }; |
|
69 | }; | |
68 |
|
70 | |||
69 | casper.wait_for_idle = function () { |
|
71 | casper.wait_for_idle = function () { | |
|
72 | // Waits for the notebook to idle. | |||
70 | this.waitFor(function () { |
|
73 | this.waitFor(function () { | |
71 | return this.evaluate(function () { |
|
74 | return this.evaluate(function () { | |
72 | return IPython._status == 'idle'; |
|
75 | return IPython._status == 'idle'; | |
@@ -74,8 +77,8 b' casper.wait_for_idle = function () {' | |||||
74 | }); |
|
77 | }); | |
75 | }; |
|
78 | }; | |
76 |
|
79 | |||
77 | // wait for the nth output in a given cell |
|
|||
78 | casper.wait_for_output = function (cell_num, out_num) { |
|
80 | casper.wait_for_output = function (cell_num, out_num) { | |
|
81 | // wait for the nth output in a given cell | |||
79 | this.wait_for_idle(); |
|
82 | this.wait_for_idle(); | |
80 | out_num = out_num || 0; |
|
83 | out_num = out_num || 0; | |
81 | this.then(function() { |
|
84 | this.then(function() { | |
@@ -94,29 +97,29 b' casper.wait_for_output = function (cell_num, out_num) {' | |||||
94 | }); |
|
97 | }); | |
95 | }; |
|
98 | }; | |
96 |
|
99 | |||
97 | // wait for a widget msg que to reach 0 |
|
|||
98 | // |
|
|||
99 | // Parameters |
|
|||
100 | // ---------- |
|
|||
101 | // widget_info : object |
|
|||
102 | // Object which contains info related to the widget. The model_id property |
|
|||
103 | // is used to identify the widget. |
|
|||
104 | casper.wait_for_widget = function (widget_info) { |
|
100 | casper.wait_for_widget = function (widget_info) { | |
|
101 | // wait for a widget msg que to reach 0 | |||
|
102 | // | |||
|
103 | // Parameters | |||
|
104 | // ---------- | |||
|
105 | // widget_info : object | |||
|
106 | // Object which contains info related to the widget. The model_id property | |||
|
107 | // is used to identify the widget. | |||
105 | this.waitFor(function () { |
|
108 | this.waitFor(function () { | |
106 | var pending = this.evaluate(function (m) { |
|
109 | var pending = this.evaluate(function (m) { | |
107 | return IPython.notebook.kernel.widget_manager.get_model(m).pending_msgs; |
|
110 | return IPython.notebook.kernel.widget_manager.get_model(m).pending_msgs; | |
108 | }, {m: widget_info.model_id}); |
|
111 | }, {m: widget_info.model_id}); | |
109 |
|
112 | |||
110 | if (pending == 0) { |
|
113 | if (pending === 0) { | |
111 | return true; |
|
114 | return true; | |
112 | } else { |
|
115 | } else { | |
113 | return false; |
|
116 | return false; | |
114 | } |
|
117 | } | |
115 | }); |
|
118 | }); | |
116 | } |
|
119 | }; | |
117 |
|
120 | |||
118 | // return an output of a given cell |
|
|||
119 | casper.get_output_cell = function (cell_num, out_num) { |
|
121 | casper.get_output_cell = function (cell_num, out_num) { | |
|
122 | // return an output of a given cell | |||
120 | out_num = out_num || 0; |
|
123 | out_num = out_num || 0; | |
121 | var result = casper.evaluate(function (c, o) { |
|
124 | var result = casper.evaluate(function (c, o) { | |
122 | var cell = IPython.notebook.get_cell(c); |
|
125 | var cell = IPython.notebook.get_cell(c); | |
@@ -137,25 +140,33 b' casper.get_output_cell = function (cell_num, out_num) {' | |||||
137 | } |
|
140 | } | |
138 | }; |
|
141 | }; | |
139 |
|
142 | |||
140 | // return the number of cells in the notebook |
|
|||
141 | casper.get_cells_length = function () { |
|
143 | casper.get_cells_length = function () { | |
|
144 | // return the number of cells in the notebook | |||
142 | var result = casper.evaluate(function () { |
|
145 | var result = casper.evaluate(function () { | |
143 | return IPython.notebook.get_cells().length; |
|
146 | return IPython.notebook.get_cells().length; | |
144 | }) |
|
147 | }); | |
145 | return result; |
|
148 | return result; | |
146 | }; |
|
149 | }; | |
147 |
|
150 | |||
148 | // Set the text content of a cell. |
|
|||
149 | casper.set_cell_text = function(index, text){ |
|
151 | casper.set_cell_text = function(index, text){ | |
|
152 | // Set the text content of a cell. | |||
150 | this.evaluate(function (index, text) { |
|
153 | this.evaluate(function (index, text) { | |
151 | var cell = IPython.notebook.get_cell(index); |
|
154 | var cell = IPython.notebook.get_cell(index); | |
152 | cell.set_text(text); |
|
155 | cell.set_text(text); | |
153 | }, index, text); |
|
156 | }, index, text); | |
154 | }; |
|
157 | }; | |
155 |
|
158 | |||
156 | // Inserts a cell at the bottom of the notebook |
|
159 | casper.get_cell_text = function(index){ | |
157 | // Returns the new cell's index. |
|
160 | // Get the text content of a cell. | |
|
161 | return this.evaluate(function (index) { | |||
|
162 | var cell = IPython.notebook.get_cell(index); | |||
|
163 | return cell.get_text(); | |||
|
164 | }, index); | |||
|
165 | }; | |||
|
166 | ||||
158 | casper.insert_cell_at_bottom = function(cell_type){ |
|
167 | casper.insert_cell_at_bottom = function(cell_type){ | |
|
168 | // Inserts a cell at the bottom of the notebook | |||
|
169 | // Returns the new cell's index. | |||
159 | cell_type = cell_type || 'code'; |
|
170 | cell_type = cell_type || 'code'; | |
160 |
|
171 | |||
161 | return this.evaluate(function (cell_type) { |
|
172 | return this.evaluate(function (cell_type) { | |
@@ -164,9 +175,9 b' casper.insert_cell_at_bottom = function(cell_type){' | |||||
164 | }, cell_type); |
|
175 | }, cell_type); | |
165 | }; |
|
176 | }; | |
166 |
|
177 | |||
167 | // Insert a cell at the bottom of the notebook and set the cells text. |
|
|||
168 | // Returns the new cell's index. |
|
|||
169 | casper.append_cell = function(text, cell_type) { |
|
178 | casper.append_cell = function(text, cell_type) { | |
|
179 | // Insert a cell at the bottom of the notebook and set the cells text. | |||
|
180 | // Returns the new cell's index. | |||
170 | var index = this.insert_cell_at_bottom(cell_type); |
|
181 | var index = this.insert_cell_at_bottom(cell_type); | |
171 | if (text !== undefined) { |
|
182 | if (text !== undefined) { | |
172 | this.set_cell_text(index, text); |
|
183 | this.set_cell_text(index, text); | |
@@ -174,9 +185,9 b' casper.append_cell = function(text, cell_type) {' | |||||
174 | return index; |
|
185 | return index; | |
175 | }; |
|
186 | }; | |
176 |
|
187 | |||
177 | // Asynchronously executes a cell by index. |
|
|||
178 | // Returns the cell's index. |
|
|||
179 | casper.execute_cell = function(index){ |
|
188 | casper.execute_cell = function(index){ | |
|
189 | // Asynchronously executes a cell by index. | |||
|
190 | // Returns the cell's index. | |||
180 | var that = this; |
|
191 | var that = this; | |
181 | this.then(function(){ |
|
192 | this.then(function(){ | |
182 | that.evaluate(function (index) { |
|
193 | that.evaluate(function (index) { | |
@@ -187,11 +198,11 b' casper.execute_cell = function(index){' | |||||
187 | return index; |
|
198 | return index; | |
188 | }; |
|
199 | }; | |
189 |
|
200 | |||
190 | // Synchronously executes a cell by index. |
|
|||
191 | // Optionally accepts a then_callback parameter. then_callback will get called |
|
|||
192 | // when the cell has finished executing. |
|
|||
193 | // Returns the cell's index. |
|
|||
194 | casper.execute_cell_then = function(index, then_callback) { |
|
201 | casper.execute_cell_then = function(index, then_callback) { | |
|
202 | // Synchronously executes a cell by index. | |||
|
203 | // Optionally accepts a then_callback parameter. then_callback will get called | |||
|
204 | // when the cell has finished executing. | |||
|
205 | // Returns the cell's index. | |||
195 | var return_val = this.execute_cell(index); |
|
206 | var return_val = this.execute_cell(index); | |
196 |
|
207 | |||
197 | this.wait_for_idle(); |
|
208 | this.wait_for_idle(); | |
@@ -206,18 +217,18 b' casper.execute_cell_then = function(index, then_callback) {' | |||||
206 | return return_val; |
|
217 | return return_val; | |
207 | }; |
|
218 | }; | |
208 |
|
219 | |||
209 | // Utility function that allows us to easily check if an element exists |
|
|||
210 | // within a cell. Uses JQuery selector to look for the element. |
|
|||
211 | casper.cell_element_exists = function(index, selector){ |
|
220 | casper.cell_element_exists = function(index, selector){ | |
|
221 | // Utility function that allows us to easily check if an element exists | |||
|
222 | // within a cell. Uses JQuery selector to look for the element. | |||
212 | return casper.evaluate(function (index, selector) { |
|
223 | return casper.evaluate(function (index, selector) { | |
213 | var $cell = IPython.notebook.get_cell(index).element; |
|
224 | var $cell = IPython.notebook.get_cell(index).element; | |
214 | return $cell.find(selector).length > 0; |
|
225 | return $cell.find(selector).length > 0; | |
215 | }, index, selector); |
|
226 | }, index, selector); | |
216 | }; |
|
227 | }; | |
217 |
|
228 | |||
218 | // Utility function that allows us to execute a jQuery function on an |
|
|||
219 | // element within a cell. |
|
|||
220 | casper.cell_element_function = function(index, selector, function_name, function_args){ |
|
229 | casper.cell_element_function = function(index, selector, function_name, function_args){ | |
|
230 | // Utility function that allows us to execute a jQuery function on an | |||
|
231 | // element within a cell. | |||
221 | return casper.evaluate(function (index, selector, function_name, function_args) { |
|
232 | return casper.evaluate(function (index, selector, function_name, function_args) { | |
222 | var $cell = IPython.notebook.get_cell(index).element; |
|
233 | var $cell = IPython.notebook.get_cell(index).element; | |
223 | var $el = $cell.find(selector); |
|
234 | var $el = $cell.find(selector); | |
@@ -225,8 +236,183 b' casper.cell_element_function = function(index, selector, function_name, function' | |||||
225 | }, index, selector, function_name, function_args); |
|
236 | }, index, selector, function_name, function_args); | |
226 | }; |
|
237 | }; | |
227 |
|
238 | |||
228 | // Wrap a notebook test to reduce boilerplate. |
|
239 | casper.validate_notebook_state = function(message, mode, cell_index) { | |
|
240 | // Validate the entire dual mode state of the notebook. Make sure no more than | |||
|
241 | // one cell is selected, focused, in edit mode, etc... | |||
|
242 | ||||
|
243 | // General tests. | |||
|
244 | this.test.assertEquals(this.get_keyboard_mode(), this.get_notebook_mode(), | |||
|
245 | message + '; keyboard and notebook modes match'); | |||
|
246 | // Is the selected cell the only cell that is selected? | |||
|
247 | if (cell_index!==undefined) { | |||
|
248 | this.test.assert(this.is_only_cell_selected(cell_index), | |||
|
249 | message + '; cell ' + cell_index + ' is the only cell selected'); | |||
|
250 | } | |||
|
251 | ||||
|
252 | // Mode specific tests. | |||
|
253 | if (mode==='command') { | |||
|
254 | // Are the notebook and keyboard manager in command mode? | |||
|
255 | this.test.assertEquals(this.get_keyboard_mode(), 'command', | |||
|
256 | message + '; in command mode'); | |||
|
257 | // Make sure there isn't a single cell in edit mode. | |||
|
258 | this.test.assert(this.is_only_cell_edit(null), | |||
|
259 | message + '; all cells in command mode'); | |||
|
260 | this.test.assert(this.is_cell_editor_focused(null), | |||
|
261 | message + '; no cell editors are focused while in command mode'); | |||
|
262 | ||||
|
263 | } else if (mode==='edit') { | |||
|
264 | // Are the notebook and keyboard manager in edit mode? | |||
|
265 | this.test.assertEquals(this.get_keyboard_mode(), 'edit', | |||
|
266 | message + '; in edit mode'); | |||
|
267 | if (cell_index!==undefined) { | |||
|
268 | // Is the specified cell the only cell in edit mode? | |||
|
269 | this.test.assert(this.is_only_cell_edit(cell_index), | |||
|
270 | message + '; cell ' + cell_index + ' is the only cell in edit mode'); | |||
|
271 | // Is the specified cell the only cell with a focused code mirror? | |||
|
272 | this.test.assert(this.is_cell_editor_focused(cell_index), | |||
|
273 | message + '; cell ' + cell_index + '\'s editor is appropriately focused'); | |||
|
274 | } | |||
|
275 | ||||
|
276 | } else { | |||
|
277 | this.test.assert(false, message + '; ' + mode + ' is an unknown mode'); | |||
|
278 | } | |||
|
279 | }; | |||
|
280 | ||||
|
281 | casper.select_cell = function(index) { | |||
|
282 | // Select a cell in the notebook. | |||
|
283 | this.evaluate(function (i) { | |||
|
284 | IPython.notebook.select(i); | |||
|
285 | }, {i: index}); | |||
|
286 | }; | |||
|
287 | ||||
|
288 | casper.click_cell_editor = function(index) { | |||
|
289 | // Emulate a click on a cell's editor. | |||
|
290 | ||||
|
291 | // Code Mirror does not play nicely with emulated brower events. | |||
|
292 | // Instead of trying to emulate a click, here we run code similar to | |||
|
293 | // the code used in Code Mirror that handles the mousedown event on a | |||
|
294 | // region of codemirror that the user can focus. | |||
|
295 | this.evaluate(function (i) { | |||
|
296 | var cm = IPython.notebook.get_cell(i).code_mirror; | |||
|
297 | if (cm.options.readOnly != "nocursor" && (document.activeElement != cm.display.input)) | |||
|
298 | cm.display.input.focus(); | |||
|
299 | }, {i: index}); | |||
|
300 | }; | |||
|
301 | ||||
|
302 | casper.set_cell_editor_cursor = function(index, line_index, char_index) { | |||
|
303 | // Set the Code Mirror instance cursor's location. | |||
|
304 | this.evaluate(function (i, l, c) { | |||
|
305 | IPython.notebook.get_cell(i).code_mirror.setCursor(l, c); | |||
|
306 | }, {i: index, l: line_index, c: char_index}); | |||
|
307 | }; | |||
|
308 | ||||
|
309 | casper.focus_notebook = function() { | |||
|
310 | // Focus the notebook div. | |||
|
311 | this.evaluate(function (){ | |||
|
312 | $('#notebook').focus(); | |||
|
313 | }, {}); | |||
|
314 | }; | |||
|
315 | ||||
|
316 | casper.trigger_keydown = function() { | |||
|
317 | // Emulate a keydown in the notebook. | |||
|
318 | for (var i = 0; i < arguments.length; i++) { | |||
|
319 | this.evaluate(function (k) { | |||
|
320 | var element = $(document); | |||
|
321 | var event = IPython.keyboard.shortcut_to_event(k, 'keydown'); | |||
|
322 | element.trigger(event); | |||
|
323 | }, {k: arguments[i]}); | |||
|
324 | } | |||
|
325 | }; | |||
|
326 | ||||
|
327 | casper.get_keyboard_mode = function() { | |||
|
328 | // Get the mode of the keyboard manager. | |||
|
329 | return this.evaluate(function() { | |||
|
330 | return IPython.keyboard_manager.mode; | |||
|
331 | }, {}); | |||
|
332 | }; | |||
|
333 | ||||
|
334 | casper.get_notebook_mode = function() { | |||
|
335 | // Get the mode of the notebook. | |||
|
336 | return this.evaluate(function() { | |||
|
337 | return IPython.notebook.mode; | |||
|
338 | }, {}); | |||
|
339 | }; | |||
|
340 | ||||
|
341 | casper.get_cell = function(index) { | |||
|
342 | // Get a single cell. | |||
|
343 | // | |||
|
344 | // Note: Handles to DOM elements stored in the cell will be useless once in | |||
|
345 | // CasperJS context. | |||
|
346 | return this.evaluate(function(i) { | |||
|
347 | var cell = IPython.notebook.get_cell(i); | |||
|
348 | if (cell) { | |||
|
349 | return cell; | |||
|
350 | } | |||
|
351 | return null; | |||
|
352 | }, {i : index}); | |||
|
353 | }; | |||
|
354 | ||||
|
355 | casper.is_cell_editor_focused = function(index) { | |||
|
356 | // Make sure a cell's editor is the only editor focused on the page. | |||
|
357 | return this.evaluate(function(i) { | |||
|
358 | var focused_textarea = $('#notebook .CodeMirror-focused textarea'); | |||
|
359 | if (focused_textarea.length > 1) { throw 'More than one Code Mirror editor is focused at once!'; } | |||
|
360 | if (i === null) { | |||
|
361 | return focused_textarea.length === 0; | |||
|
362 | } else { | |||
|
363 | var cell = IPython.notebook.get_cell(i); | |||
|
364 | if (cell) { | |||
|
365 | return cell.code_mirror.getInputField() == focused_textarea[0]; | |||
|
366 | } | |||
|
367 | } | |||
|
368 | return false; | |||
|
369 | }, {i : index}); | |||
|
370 | }; | |||
|
371 | ||||
|
372 | casper.is_only_cell_selected = function(index) { | |||
|
373 | // Check if a cell is the only cell selected. | |||
|
374 | // Pass null as the index to check if no cells are selected. | |||
|
375 | return this.is_only_cell_on(index, 'selected', 'unselected'); | |||
|
376 | }; | |||
|
377 | ||||
|
378 | casper.is_only_cell_edit = function(index) { | |||
|
379 | // Check if a cell is the only cell in edit mode. | |||
|
380 | // Pass null as the index to check if all of the cells are in command mode. | |||
|
381 | return this.is_only_cell_on(index, 'edit_mode', 'command_mode'); | |||
|
382 | }; | |||
|
383 | ||||
|
384 | casper.is_only_cell_on = function(i, on_class, off_class) { | |||
|
385 | // Check if a cell is the only cell with the `on_class` DOM class applied to it. | |||
|
386 | // All of the other cells are checked for the `off_class` DOM class. | |||
|
387 | // Pass null as the index to check if all of the cells have the `off_class`. | |||
|
388 | var cells_length = this.get_cells_length(); | |||
|
389 | for (var j = 0; j < cells_length; j++) { | |||
|
390 | if (j === i) { | |||
|
391 | if (this.cell_has_class(j, off_class) || !this.cell_has_class(j, on_class)) { | |||
|
392 | return false; | |||
|
393 | } | |||
|
394 | } else { | |||
|
395 | if (!this.cell_has_class(j, off_class) || this.cell_has_class(j, on_class)) { | |||
|
396 | return false; | |||
|
397 | } | |||
|
398 | } | |||
|
399 | } | |||
|
400 | return true; | |||
|
401 | }; | |||
|
402 | ||||
|
403 | casper.cell_has_class = function(index, classes) { | |||
|
404 | // Check if a cell has a class. | |||
|
405 | return this.evaluate(function(i, c) { | |||
|
406 | var cell = IPython.notebook.get_cell(i); | |||
|
407 | if (cell) { | |||
|
408 | return cell.element.hasClass(c); | |||
|
409 | } | |||
|
410 | return false; | |||
|
411 | }, {i : index, c: classes}); | |||
|
412 | }; | |||
|
413 | ||||
229 | casper.notebook_test = function(test) { |
|
414 | casper.notebook_test = function(test) { | |
|
415 | // Wrap a notebook test to reduce boilerplate. | |||
230 | this.open_new_notebook(); |
|
416 | this.open_new_notebook(); | |
231 | this.then(test); |
|
417 | this.then(test); | |
232 |
|
418 | |||
@@ -253,14 +439,14 b' casper.notebook_test = function(test) {' | |||||
253 | casper.wait_for_dashboard = function () { |
|
439 | casper.wait_for_dashboard = function () { | |
254 | // Wait for the dashboard list to load. |
|
440 | // Wait for the dashboard list to load. | |
255 | casper.waitForSelector('.list_item'); |
|
441 | casper.waitForSelector('.list_item'); | |
256 | } |
|
442 | }; | |
257 |
|
443 | |||
258 | casper.open_dashboard = function () { |
|
444 | casper.open_dashboard = function () { | |
259 | // Start casper by opening the dashboard page. |
|
445 | // Start casper by opening the dashboard page. | |
260 | var baseUrl = this.get_notebook_server(); |
|
446 | var baseUrl = this.get_notebook_server(); | |
261 | this.start(baseUrl); |
|
447 | this.start(baseUrl); | |
262 | this.wait_for_dashboard(); |
|
448 | this.wait_for_dashboard(); | |
263 | } |
|
449 | }; | |
264 |
|
450 | |||
265 | casper.dashboard_test = function (test) { |
|
451 | casper.dashboard_test = function (test) { | |
266 | // Open the dashboard page and run a test. |
|
452 | // Open the dashboard page and run a test. | |
@@ -276,16 +462,16 b' casper.dashboard_test = function (test) {' | |||||
276 | this.run(function() { |
|
462 | this.run(function() { | |
277 | this.test.done(); |
|
463 | this.test.done(); | |
278 | }); |
|
464 | }); | |
279 | } |
|
465 | }; | |
280 |
|
466 | |||
281 | casper.options.waitTimeout=10000 |
|
467 | casper.options.waitTimeout=10000; | |
282 | casper.on('waitFor.timeout', function onWaitForTimeout(timeout) { |
|
468 | casper.on('waitFor.timeout', function onWaitForTimeout(timeout) { | |
283 | this.echo("Timeout for " + casper.get_notebook_server()); |
|
469 | this.echo("Timeout for " + casper.get_notebook_server()); | |
284 | this.echo("Is the notebook server running?"); |
|
470 | this.echo("Is the notebook server running?"); | |
285 | }); |
|
471 | }); | |
286 |
|
472 | |||
287 | // Pass `console.log` calls from page JS to casper. |
|
473 | casper.print_log = function () { | |
288 | casper.printLog = function () { |
|
474 | // Pass `console.log` calls from page JS to casper. | |
289 | this.on('remote.message', function(msg) { |
|
475 | this.on('remote.message', function(msg) { | |
290 | this.echo('Remote message caught: ' + msg); |
|
476 | this.echo('Remote message caught: ' + msg); | |
291 | }); |
|
477 | }); |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now