Show More
@@ -23,9 +23,9 b' casper.notebook_test(function () {' | |||||
23 | this.validate_state('esc', 'command', 1); |
|
23 | this.validate_state('esc', 'command', 1); | |
24 | this.trigger_keydown('j'); |
|
24 | this.trigger_keydown('j'); | |
25 | this.validate_state('j in command mode', 'command', 2); |
|
25 | this.validate_state('j in command mode', 'command', 2); | |
26 | this.click_cell(0); |
|
26 | this.click_cell_editor(0); | |
27 | this.validate_state('click cell 0', 'edit', 0); |
|
27 | this.validate_state('click cell 0', 'edit', 0); | |
28 | this.click_cell(3); |
|
28 | this.click_cell_editor(3); | |
29 | this.validate_state('click cell 3', 'edit', 3); |
|
29 | this.validate_state('click cell 3', 'edit', 3); | |
30 | this.trigger_keydown('esc'); |
|
30 | this.trigger_keydown('esc'); | |
31 | this.validate_state('esc', 'command', 3); |
|
31 | this.validate_state('esc', 'command', 3); | |
@@ -45,15 +45,15 b' casper.notebook_test(function () {' | |||||
45 |
|
45 | |||
46 | this.trigger_keydown('k'); |
|
46 | this.trigger_keydown('k'); | |
47 | this.validate_state('k in command mode', 'command', 2); |
|
47 | this.validate_state('k in command mode', 'command', 2); | |
48 | this.click_cell(0); |
|
48 | this.click_cell_editor(0); | |
49 | this.validate_state('click cell 0', 'edit', 0); |
|
49 | this.validate_state('click cell 0', 'edit', 0); | |
50 | this.focus_notebook(); |
|
50 | this.focus_notebook(); | |
51 | this.validate_state('focus #notebook', 'command', 0); |
|
51 | this.validate_state('focus #notebook', 'command', 0); | |
52 | this.click_cell(0); |
|
52 | this.click_cell_editor(0); | |
53 | this.validate_state('click cell 0', 'edit', 0); |
|
53 | this.validate_state('click cell 0', 'edit', 0); | |
54 | this.focus_notebook(); |
|
54 | this.focus_notebook(); | |
55 | this.validate_state('focus #notebook', 'command', 0); |
|
55 | this.validate_state('focus #notebook', 'command', 0); | |
56 | this.click_cell(3); |
|
56 | this.click_cell_editor(3); | |
57 | this.validate_state('click cell 3', 'edit', 3); |
|
57 | this.validate_state('click cell 3', 'edit', 3); | |
58 |
|
58 | |||
59 | // shift+enter tests. |
|
59 | // shift+enter tests. | |
@@ -62,7 +62,7 b' casper.notebook_test(function () {' | |||||
62 | this.trigger_keydown('shift+enter'); // Creates one cell |
|
62 | this.trigger_keydown('shift+enter'); // Creates one cell | |
63 | this.validate_state('shift+enter (no cell below)', 'edit', base_index + 1); |
|
63 | this.validate_state('shift+enter (no cell below)', 'edit', base_index + 1); | |
64 | // not last cell in notebook & starts in edit mode |
|
64 | // not last cell in notebook & starts in edit mode | |
65 | this.click_cell(base_index); |
|
65 | this.click_cell_editor(base_index); | |
66 | this.validate_state('click cell ' + base_index, 'edit', base_index); |
|
66 | this.validate_state('click cell ' + base_index, 'edit', base_index); | |
67 | this.trigger_keydown('shift+enter'); |
|
67 | this.trigger_keydown('shift+enter'); | |
68 | this.validate_state('shift+enter (cell exists below)', 'command', base_index + 1); |
|
68 | this.validate_state('shift+enter (cell exists below)', 'command', base_index + 1); | |
@@ -78,7 +78,7 b' casper.notebook_test(function () {' | |||||
78 | this.trigger_keydown('ctrl+enter'); |
|
78 | this.trigger_keydown('ctrl+enter'); | |
79 | this.validate_state('ctrl+enter (no cell below)', 'command', base_index); |
|
79 | this.validate_state('ctrl+enter (no cell below)', 'command', base_index); | |
80 | // not last cell in notebook & starts in edit mode |
|
80 | // not last cell in notebook & starts in edit mode | |
81 | this.click_cell(base_index-1); |
|
81 | this.click_cell_editor(base_index-1); | |
82 | this.validate_state('click cell ' + (base_index-1), 'edit', base_index-1); |
|
82 | this.validate_state('click cell ' + (base_index-1), 'edit', base_index-1); | |
83 | this.trigger_keydown('ctrl+enter'); |
|
83 | this.trigger_keydown('ctrl+enter'); | |
84 | this.validate_state('ctrl+enter (cell exists below)', 'command', base_index-1); |
|
84 | this.validate_state('ctrl+enter (cell exists below)', 'command', base_index-1); | |
@@ -93,21 +93,19 b' casper.notebook_test(function () {' | |||||
93 | this.trigger_keydown('alt+enter'); // Creates one cell |
|
93 | this.trigger_keydown('alt+enter'); // Creates one cell | |
94 | this.validate_state('alt+enter (no cell below)', 'edit', base_index + 1); |
|
94 | this.validate_state('alt+enter (no cell below)', 'edit', base_index + 1); | |
95 | // not last cell in notebook & starts in edit mode |
|
95 | // not last cell in notebook & starts in edit mode | |
96 | this.click_cell(base_index); |
|
96 | this.click_cell_editor(base_index); | |
97 | this.validate_state('click cell ' + base_index, 'edit', base_index); |
|
97 | this.validate_state('click cell ' + base_index, 'edit', base_index); | |
98 | this.trigger_keydown('alt+enter'); // Creates one cell |
|
98 | this.trigger_keydown('alt+enter'); // Creates one cell | |
99 | this.validate_state('alt+enter (cell exists below)', 'edit', base_index + 1); |
|
99 | this.validate_state('alt+enter (cell exists below)', 'edit', base_index + 1); | |
100 | // starts in command mode |
|
100 | // starts in command mode | |
101 | this.trigger_keydown('esc'); |
|
101 | this.trigger_keydown('esc', 'k'); | |
102 | this.trigger_keydown('k'); |
|
|||
103 | this.validate_state('k in comand mode', 'command', base_index); |
|
102 | this.validate_state('k in comand mode', 'command', base_index); | |
104 | this.trigger_keydown('alt+enter'); // Creates one cell |
|
103 | this.trigger_keydown('alt+enter'); // Creates one cell | |
105 | this.validate_state('alt+enter (start in command mode)', 'edit', base_index + 1); |
|
104 | this.validate_state('alt+enter (start in command mode)', 'edit', base_index + 1); | |
106 |
|
105 | |||
107 | // Notebook will now have 8 cells, the index of the last cell will be 7. |
|
106 | // Notebook will now have 8 cells, the index of the last cell will be 7. | |
108 | this.test.assertEquals(this.get_cells().length, 8, '*-enter commands added cells where needed.'); |
|
107 | this.test.assertEquals(this.get_cells().length, 8, '*-enter commands added cells where needed.'); | |
109 |
this. |
|
108 | this.select_cell(7); | |
110 | this.trigger_keydown('esc'); |
|
|||
111 | this.validate_state('click cell ' + 7 + ' and esc', 'command', 7); |
|
109 | this.validate_state('click cell ' + 7 + ' and esc', 'command', 7); | |
112 |
|
110 | |||
113 | this.trigger_keydown('r'); |
|
111 | this.trigger_keydown('r'); | |
@@ -130,8 +128,7 b' casper.notebook_test(function () {' | |||||
130 | this.trigger_keydown('y'); |
|
128 | this.trigger_keydown('y'); | |
131 | this.test.assertEquals(this.get_cell(7).cell_type, 'code', 'y; cell is code'); |
|
129 | this.test.assertEquals(this.get_cell(7).cell_type, 'code', 'y; cell is code'); | |
132 |
|
130 | |||
133 | this.trigger_keydown('d'); |
|
131 | this.trigger_keydown('d', 'd'); | |
134 | this.trigger_keydown('d'); |
|
|||
135 | this.test.assertEquals(this.get_cells().length, 7, 'dd actually deletes a cell'); |
|
132 | this.test.assertEquals(this.get_cells().length, 7, 'dd actually deletes a cell'); | |
136 | this.validate_state('dd', 'command', 6); |
|
133 | this.validate_state('dd', 'command', 6); | |
137 |
|
134 | |||
@@ -144,6 +141,63 b' casper.notebook_test(function () {' | |||||
144 |
|
141 | |||
145 | this.test.assertEquals(this.get_cells().length, 7, "d, 1 second wait, d doesn't delete a cell"); |
|
142 | this.test.assertEquals(this.get_cells().length, 7, "d, 1 second wait, d doesn't delete a cell"); | |
146 | this.validate_state('d, 1 second wait, d', 'command', 6); |
|
143 | this.validate_state('d, 1 second wait, d', 'command', 6); | |
|
144 | this.trigger_keydown('j'); | |||
|
145 | this.validate_state('j at end of notebook', 'command', 6); | |||
|
146 | this.trigger_keydown('down'); | |||
|
147 | this.validate_state('down at end of notebook', 'command', 6); | |||
|
148 | this.trigger_keydown('up'); | |||
|
149 | this.validate_state('up', 'command', 5); | |||
|
150 | this.select_cell(0); | |||
|
151 | this.validate_state('select 0', 'command', 0); | |||
|
152 | this.trigger_keydown('k'); | |||
|
153 | this.validate_state('k at top of notebook', 'command', 0); | |||
|
154 | this.trigger_keydown('up'); | |||
|
155 | this.validate_state('up at top of notebook', 'command', 0); | |||
|
156 | this.trigger_keydown('down'); | |||
|
157 | this.validate_state('down', 'command', 1); | |||
|
158 | ||||
|
159 | this.click_cell_editor(6); | |||
|
160 | this.validate_state('click cell 6', 'edit', 6); | |||
|
161 | this.trigger_keydown('down'); | |||
|
162 | this.validate_state('down at end of notebook', 'edit', 6); | |||
|
163 | this.trigger_keydown('up'); | |||
|
164 | this.validate_state('up', 'edit', 5); | |||
|
165 | this.click_cell_editor(0); | |||
|
166 | this.validate_state('click 0', 'edit', 0); | |||
|
167 | this.trigger_keydown('up'); | |||
|
168 | this.validate_state('up at top of notebook', 'edit', 0); | |||
|
169 | this.trigger_keydown('down'); | |||
|
170 | this.validate_state('down', 'edit', 1); | |||
|
171 | ||||
|
172 | this.select_cell(6); | |||
|
173 | this.validate_state('select 6', 'command', 6); | |||
|
174 | this.trigger_keydown('m'); | |||
|
175 | this.test.assertEquals(this.get_cell(6).cell_type, 'markdown', 'm; cell is markdown'); | |||
|
176 | this.test.assertEquals(this.get_cell(6).rendered, true, 'm; cell is rendered'); | |||
|
177 | this.trigger_keydown('enter'); | |||
|
178 | this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); | |||
|
179 | this.validate_state('enter', 'edit', 6); | |||
|
180 | this.trigger_keydown('ctrl+enter'); | |||
|
181 | this.test.assertEquals(this.get_cell(6).rendered, true, 'enter; cell is rendered'); | |||
|
182 | this.validate_state('enter', 'command', 6); | |||
|
183 | this.trigger_keydown('enter'); | |||
|
184 | this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); | |||
|
185 | this.select_cell(5); | |||
|
186 | this.test.assertEquals(this.get_cell(6).rendered, false, 'select 5; cell 6 is still unrendered'); | |||
|
187 | this.validate_state('select 5', 'command', 5); | |||
|
188 | this.select_cell(6); | |||
|
189 | this.validate_state('select 6', 'command', 5); | |||
|
190 | this.trigger_keydown('ctrl+enter'); | |||
|
191 | this.test.assertEquals(this.get_cell(6).rendered, true, 'enter; cell is rendered'); | |||
|
192 | this.select_cell(5); | |||
|
193 | this.validate_state('select 5', 'command', 5); | |||
|
194 | this.trigger_keydown('shift+enter'); | |||
|
195 | this.validate_state('shift+enter', 'command', 6); | |||
|
196 | this.test.assertEquals(this.get_cell(6).rendered, true, 'enter; cell is rendered'); | |||
|
197 | this.trigger_keydown('shift+enter'); // Creates one cell | |||
|
198 | this.validate_state('shift+enter', 'edit', 7); | |||
|
199 | this.test.assertEquals(this.get_cell(6).rendered, true, 'enter; cell is rendered'); | |||
|
200 | ||||
147 |
|
201 | |||
148 | }); |
|
202 | }); | |
149 |
|
203 | |||
@@ -210,8 +264,13 b' casper.notebook_test(function () {' | |||||
210 | /* TODO: MOVE EVERYTHING BELOW THIS LINE INTO THE BASE (utils.js) */ |
|
264 | /* TODO: MOVE EVERYTHING BELOW THIS LINE INTO THE BASE (utils.js) */ | |
211 |
|
265 | |||
212 |
|
266 | |||
|
267 | this.select_cell = function (index) { | |||
|
268 | this.evaluate(function (i) { | |||
|
269 | IPython.notebook.select(i); | |||
|
270 | }, {i: index}); | |||
|
271 | }; | |||
213 |
|
272 | |||
214 | this.click_cell = function(index) { |
|
273 | this.click_cell_editor = function(index) { | |
215 | // Code Mirror does not play nicely with emulated brower events. |
|
274 | // Code Mirror does not play nicely with emulated brower events. | |
216 | // Instead of trying to emulate a click, here we run code similar to |
|
275 | // Instead of trying to emulate a click, here we run code similar to | |
217 | // the code used in Code Mirror that handles the mousedown event on a |
|
276 | // the code used in Code Mirror that handles the mousedown event on a | |
@@ -229,10 +288,12 b' casper.notebook_test(function () {' | |||||
229 | }, {}); |
|
288 | }, {}); | |
230 | }; |
|
289 | }; | |
231 |
|
290 | |||
232 |
this.trigger_keydown = function( |
|
291 | this.trigger_keydown = function() { | |
233 | this.evaluate(function (k) { |
|
292 | for (var i = 0; i < arguments.length; i++) { | |
234 | IPython.keyboard.trigger_keydown(k); |
|
293 | this.evaluate(function (k) { | |
235 | }, {k: key}); |
|
294 | IPython.keyboard.trigger_keydown(k); | |
|
295 | }, {k: arguments[i]}); | |||
|
296 | } | |||
236 | }; |
|
297 | }; | |
237 |
|
298 | |||
238 | this.get_keyboard_mode = function() { |
|
299 | this.get_keyboard_mode = function() { |
General Comments 0
You need to be logged in to leave comments.
Login now