##// END OF EJS Templates
Make notebook tests play nicely with SlimerJS...
Jonathan Frederic -
Show More
@@ -1,39 +1,43 b''
1
1
2 // Test
2 // Test
3 casper.notebook_test(function () {
3 casper.notebook_test(function () {
4 this.is_rendered = function(i) {
5 return this.evaluate(function(i) {
6 return !!IPython.notebook.get_cell(i).rendered;
7 }, {i:i});
8 };
9
4 var a = 'print("a")';
10 var a = 'print("a")';
5 var index = this.append_cell(a);
11 var index = this.append_cell(a);
6 this.execute_cell_then(index);
12 this.execute_cell_then(index, function(index) {
7
8 this.then(function () {
9 // Markdown rendering / unredering
13 // Markdown rendering / unredering
10 this.select_cell(1);
14 this.select_cell(index);
11 this.validate_notebook_state('select 1', 'command', 1);
15 this.validate_notebook_state('select ' + index, 'command', index);
12 this.trigger_keydown('m');
16 this.trigger_keydown('m');
13 this.test.assertEquals(this.get_cell(1).cell_type, 'markdown', 'm; cell is markdown');
17 this.test.assertEquals(this.get_cell(index).cell_type, 'markdown', 'm; cell is markdown');
14 this.test.assertEquals(this.get_cell(1).rendered, false, 'm; cell is rendered');
18 this.test.assert(!this.is_rendered(index), 'm; cell is unrendered');
15 this.trigger_keydown('enter');
19 this.trigger_keydown('enter');
16 this.test.assertEquals(this.get_cell(1).rendered, false, 'enter; cell is unrendered');
20 this.test.assert(!this.is_rendered(index), 'enter; cell is unrendered');
17 this.validate_notebook_state('enter', 'edit', 1);
21 this.validate_notebook_state('enter', 'edit', index);
18 this.trigger_keydown('ctrl-enter');
22 this.trigger_keydown('ctrl-enter');
19 this.test.assertEquals(this.get_cell(1).rendered, true, 'ctrl-enter; cell is rendered');
23 this.test.assert(this.is_rendered(index), 'ctrl-enter; cell is rendered');
20 this.validate_notebook_state('enter', 'command', 1);
24 this.validate_notebook_state('enter', 'command', index);
21 this.trigger_keydown('enter');
25 this.trigger_keydown('enter');
22 this.test.assertEquals(this.get_cell(1).rendered, false, 'enter; cell is unrendered');
26 this.test.assert(!this.is_rendered(index), 'enter; cell is unrendered');
23 this.select_cell(0);
27 this.select_cell(index-1);
24 this.test.assertEquals(this.get_cell(1).rendered, false, 'select 0; cell 1 is still unrendered');
28 this.test.assert(!this.is_rendered(index), 'select ' + (index-1) + '; cell ' + index + ' is still unrendered');
25 this.validate_notebook_state('select 0', 'command', 0);
29 this.validate_notebook_state('select ' + (index-1), 'command', index-1);
26 this.select_cell(1);
30 this.select_cell(index);
27 this.validate_notebook_state('select 1', 'command', 1);
31 this.validate_notebook_state('select ' + index, 'command', index);
28 this.trigger_keydown('ctrl-enter');
32 this.trigger_keydown('ctrl-enter');
29 this.test.assertEquals(this.get_cell(1).rendered, true, 'ctrl-enter; cell is rendered');
33 this.test.assert(this.is_rendered(index), 'ctrl-enter; cell is rendered');
30 this.select_cell(0);
34 this.select_cell(index-1);
31 this.validate_notebook_state('select 0', 'command', 0);
35 this.validate_notebook_state('select ' + (index-1), 'command', index-1);
32 this.trigger_keydown('shift-enter');
36 this.trigger_keydown('shift-enter');
33 this.validate_notebook_state('shift-enter', 'command', 1);
37 this.validate_notebook_state('shift-enter', 'command', index);
34 this.test.assertEquals(this.get_cell(1).rendered, true, 'shift-enter; cell is rendered');
38 this.test.assert(this.is_rendered(index), 'shift-enter; cell is rendered');
35 this.trigger_keydown('shift-enter'); // Creates one cell
39 this.trigger_keydown('shift-enter'); // Creates one cell
36 this.validate_notebook_state('shift-enter', 'edit', 2);
40 this.validate_notebook_state('shift-enter', 'edit', index+1);
37 this.test.assertEquals(this.get_cell(1).rendered, true, 'shift-enter; cell is rendered');
41 this.test.assert(this.is_rendered(index), 'shift-enter; cell is rendered');
38 });
42 });
39 }); No newline at end of file
43 });
@@ -25,7 +25,7 b' casper.notebook_test(function () {'
25 this.then(function () {
25 this.then(function () {
26 var output = this.get_output_cell(0);
26 var output = this.get_output_cell(0);
27 this.test.assert(messages.length > 0, "Captured log message");
27 this.test.assert(messages.length > 0, "Captured log message");
28 this.test.assertEquals(messages[messages.length-1], "Invalid type for image/png 5", "Logged Invalid type message");
28 this.test.assertEquals(messages[messages.length-1].substr(0,26), "Invalid type for image/png", "Logged Invalid type message");
29 this.test.assertEquals(output['image/png'], undefined, "Non-string png data was stripped");
29 this.test.assertEquals(output['image/png'], undefined, "Non-string png data was stripped");
30 this.test.assertEquals(output['text/plain'], '5', "text data is fine");
30 this.test.assertEquals(output['text/plain'], '5', "text data is fine");
31 });
31 });
General Comments 0
You need to be logged in to leave comments. Login now