##// END OF EJS Templates
Add comments
Jonathan Frederic -
Show More
@@ -233,6 +233,8 b' casper.cell_element_function = function(index, selector, function_name, function'
233 }, index, selector, function_name, function_args);
233 }, index, selector, function_name, function_args);
234 };
234 };
235
235
236 // Validate the entire dual mode state of the notebook. Make sure no more than
237 // one cell is selected, focused, in edit mode, etc...
236 casper.validate_notebook_state = function(message, mode, cell_index) {
238 casper.validate_notebook_state = function(message, mode, cell_index) {
237 // General tests.
239 // General tests.
238 this.test.assertEquals(this.get_keyboard_mode(), this.get_notebook_mode(),
240 this.test.assertEquals(this.get_keyboard_mode(), this.get_notebook_mode(),
@@ -272,12 +274,14 b' casper.validate_notebook_state = function(message, mode, cell_index) {'
272 }
274 }
273 };
275 };
274
276
277 // Select a cell in the notebook.
275 casper.select_cell = function(index) {
278 casper.select_cell = function(index) {
276 this.evaluate(function (i) {
279 this.evaluate(function (i) {
277 IPython.notebook.select(i);
280 IPython.notebook.select(i);
278 }, {i: index});
281 }, {i: index});
279 };
282 };
280
283
284 // Emulate a click on a cell's editor.
281 casper.click_cell_editor = function(index) {
285 casper.click_cell_editor = function(index) {
282 // Code Mirror does not play nicely with emulated brower events.
286 // Code Mirror does not play nicely with emulated brower events.
283 // Instead of trying to emulate a click, here we run code similar to
287 // Instead of trying to emulate a click, here we run code similar to
@@ -290,19 +294,21 b' casper.click_cell_editor = function(index) {'
290 }, {i: index});
294 }, {i: index});
291 };
295 };
292
296
297 // Set the Code Mirror instance cursor's location.
293 casper.set_cell_editor_cursor = function(index, line_index, char_index) {
298 casper.set_cell_editor_cursor = function(index, line_index, char_index) {
294 // Set the Code Mirror instance cursor's location.
295 this.evaluate(function (i, l, c) {
299 this.evaluate(function (i, l, c) {
296 IPython.notebook.get_cell(i).code_mirror.setCursor(l, c);
300 IPython.notebook.get_cell(i).code_mirror.setCursor(l, c);
297 }, {i: index, l: line_index, c: char_index});
301 }, {i: index, l: line_index, c: char_index});
298 };
302 };
299
303
304 // Focus the notebook div.
300 casper.focus_notebook = function() {
305 casper.focus_notebook = function() {
301 this.evaluate(function (){
306 this.evaluate(function (){
302 $('#notebook').focus();
307 $('#notebook').focus();
303 }, {});
308 }, {});
304 };
309 };
305
310
311 // Emulate a keydown in the notebook.
306 casper.trigger_keydown = function() {
312 casper.trigger_keydown = function() {
307 for (var i = 0; i < arguments.length; i++) {
313 for (var i = 0; i < arguments.length; i++) {
308 this.evaluate(function (k) {
314 this.evaluate(function (k) {
@@ -313,18 +319,24 b' casper.trigger_keydown = function() {'
313 }
319 }
314 };
320 };
315
321
322 // Get the mode of the keyboard manager.
316 casper.get_keyboard_mode = function() {
323 casper.get_keyboard_mode = function() {
317 return this.evaluate(function() {
324 return this.evaluate(function() {
318 return IPython.keyboard_manager.mode;
325 return IPython.keyboard_manager.mode;
319 }, {});
326 }, {});
320 };
327 };
321
328
329 // Get the mode of the notebook.
322 casper.get_notebook_mode = function() {
330 casper.get_notebook_mode = function() {
323 return this.evaluate(function() {
331 return this.evaluate(function() {
324 return IPython.notebook.mode;
332 return IPython.notebook.mode;
325 }, {});
333 }, {});
326 };
334 };
327
335
336 // Get a single cell.
337 //
338 // Note: Handles to DOM elements stored in the cell will be useless once in
339 // CasperJS context.
328 casper.get_cell = function(index) {
340 casper.get_cell = function(index) {
329 return this.evaluate(function(i) {
341 return this.evaluate(function(i) {
330 var cell = IPython.notebook.get_cell(i);
342 var cell = IPython.notebook.get_cell(i);
@@ -335,8 +347,8 b' casper.get_cell = function(index) {'
335 }, {i : index});
347 }, {i : index});
336 };
348 };
337
349
350 // Make sure a cell's editor is the only editor focused on the page.
338 casper.is_cell_editor_focused = function(index) {
351 casper.is_cell_editor_focused = function(index) {
339 // Make sure a cell's editor is the only editor focused on the page.
340 return this.evaluate(function(i) {
352 return this.evaluate(function(i) {
341 var focused_textarea = $('#notebook .CodeMirror-focused textarea');
353 var focused_textarea = $('#notebook .CodeMirror-focused textarea');
342 if (focused_textarea.length > 1) { throw 'More than one Code Mirror editor is focused at once!'; }
354 if (focused_textarea.length > 1) { throw 'More than one Code Mirror editor is focused at once!'; }
@@ -352,14 +364,21 b' casper.is_cell_editor_focused = function(index) {'
352 }, {i : index});
364 }, {i : index});
353 };
365 };
354
366
367 // Check if a cell is the only cell selected.
368 // Pass null as the index to check if no cells are selected.
355 casper.is_only_cell_selected = function(index) {
369 casper.is_only_cell_selected = function(index) {
356 return this.is_only_cell_on(index, 'selected', 'unselected');
370 return this.is_only_cell_on(index, 'selected', 'unselected');
357 };
371 };
358
372
373 // Check if a cell is the only cell in edit mode.
374 // Pass null as the index to check if all of the cells are in command mode.
359 casper.is_only_cell_edit = function(index) {
375 casper.is_only_cell_edit = function(index) {
360 return this.is_only_cell_on(index, 'edit_mode', 'command_mode');
376 return this.is_only_cell_on(index, 'edit_mode', 'command_mode');
361 };
377 };
362
378
379 // Check if a cell is the only cell with the `on_class` DOM class applied to it.
380 // All of the other cells are checked for the `off_class` DOM class.
381 // Pass null as the index to check if all of the cells have the `off_class`.
363 casper.is_only_cell_on = function(i, on_class, off_class) {
382 casper.is_only_cell_on = function(i, on_class, off_class) {
364 var cells_length = this.get_cells_length();
383 var cells_length = this.get_cells_length();
365 for (var j = 0; j < cells_length; j++) {
384 for (var j = 0; j < cells_length; j++) {
@@ -376,6 +395,7 b' casper.is_only_cell_on = function(i, on_class, off_class) {'
376 return true;
395 return true;
377 };
396 };
378
397
398 // Check if a cell has a class.
379 casper.cell_has_class = function(index, classes) {
399 casper.cell_has_class = function(index, classes) {
380 return this.evaluate(function(i, c) {
400 return this.evaluate(function(i, c) {
381 var cell = IPython.notebook.get_cell(i);
401 var cell = IPython.notebook.get_cell(i);
General Comments 0
You need to be logged in to leave comments. Login now