Show More
@@ -15,25 +15,26 b' casper.notebook_test(function () {' | |||||
15 | this.execute_cell_then(index); |
|
15 | this.execute_cell_then(index); | |
16 |
|
16 | |||
17 | this.then(function () { |
|
17 | this.then(function () { | |
18 | this.validate_state('initial state', 'edit', 0); |
|
18 | this.print_log(); | |
|
19 | this.validate_notebook_state('initial state', 'edit', 0); | |||
19 | this.trigger_keydown('esc'); |
|
20 | this.trigger_keydown('esc'); | |
20 | this.validate_state('esc', 'command', 0); |
|
21 | this.validate_notebook_state('esc', 'command', 0); | |
21 | this.trigger_keydown('down'); |
|
22 | this.trigger_keydown('down'); | |
22 | this.validate_state('down', 'command', 1); |
|
23 | this.validate_notebook_state('down', 'command', 1); | |
23 | this.trigger_keydown('enter'); |
|
24 | this.trigger_keydown('enter'); | |
24 | this.validate_state('enter', 'edit', 1); |
|
25 | this.validate_notebook_state('enter', 'edit', 1); | |
25 | this.trigger_keydown('j'); |
|
26 | this.trigger_keydown('j'); | |
26 | this.validate_state('j in edit mode', 'edit', 1); |
|
27 | this.validate_notebook_state('j in edit mode', 'edit', 1); | |
27 | this.trigger_keydown('esc'); |
|
28 | this.trigger_keydown('esc'); | |
28 | this.validate_state('esc', 'command', 1); |
|
29 | this.validate_notebook_state('esc', 'command', 1); | |
29 | this.trigger_keydown('j'); |
|
30 | this.trigger_keydown('j'); | |
30 | this.validate_state('j in command mode', 'command', 2); |
|
31 | this.validate_notebook_state('j in command mode', 'command', 2); | |
31 | this.click_cell_editor(0); |
|
32 | this.click_cell_editor(0); | |
32 | this.validate_state('click cell 0', 'edit', 0); |
|
33 | this.validate_notebook_state('click cell 0', 'edit', 0); | |
33 | this.click_cell_editor(3); |
|
34 | this.click_cell_editor(3); | |
34 | this.validate_state('click cell 3', 'edit', 3); |
|
35 | this.validate_notebook_state('click cell 3', 'edit', 3); | |
35 | this.trigger_keydown('esc'); |
|
36 | this.trigger_keydown('esc'); | |
36 | this.validate_state('esc', 'command', 3); |
|
37 | this.validate_notebook_state('esc', 'command', 3); | |
37 |
|
38 | |||
38 | // Open keyboard help |
|
39 | // Open keyboard help | |
39 | this.evaluate(function(){ |
|
40 | this.evaluate(function(){ | |
@@ -41,7 +42,7 b' casper.notebook_test(function () {' | |||||
41 | }, {}); |
|
42 | }, {}); | |
42 |
|
43 | |||
43 | this.trigger_keydown('k'); |
|
44 | this.trigger_keydown('k'); | |
44 | this.validate_state('k in command mode while keyboard help is up', 'command', 3); |
|
45 | this.validate_notebook_state('k in command mode while keyboard help is up', 'command', 3); | |
45 |
|
46 | |||
46 | // Close keyboard help |
|
47 | // Close keyboard help | |
47 | this.evaluate(function(){ |
|
48 | this.evaluate(function(){ | |
@@ -49,69 +50,69 b' casper.notebook_test(function () {' | |||||
49 | }, {}); |
|
50 | }, {}); | |
50 |
|
51 | |||
51 | this.trigger_keydown('k'); |
|
52 | this.trigger_keydown('k'); | |
52 | this.validate_state('k in command mode', 'command', 2); |
|
53 | this.validate_notebook_state('k in command mode', 'command', 2); | |
53 | this.click_cell_editor(0); |
|
54 | this.click_cell_editor(0); | |
54 | this.validate_state('click cell 0', 'edit', 0); |
|
55 | this.validate_notebook_state('click cell 0', 'edit', 0); | |
55 | this.focus_notebook(); |
|
56 | this.focus_notebook(); | |
56 | this.validate_state('focus #notebook', 'command', 0); |
|
57 | this.validate_notebook_state('focus #notebook', 'command', 0); | |
57 | this.click_cell_editor(0); |
|
58 | this.click_cell_editor(0); | |
58 | this.validate_state('click cell 0', 'edit', 0); |
|
59 | this.validate_notebook_state('click cell 0', 'edit', 0); | |
59 | this.focus_notebook(); |
|
60 | this.focus_notebook(); | |
60 | this.validate_state('focus #notebook', 'command', 0); |
|
61 | this.validate_notebook_state('focus #notebook', 'command', 0); | |
61 | this.click_cell_editor(3); |
|
62 | this.click_cell_editor(3); | |
62 | this.validate_state('click cell 3', 'edit', 3); |
|
63 | this.validate_notebook_state('click cell 3', 'edit', 3); | |
63 |
|
64 | |||
64 | // shift+enter |
|
65 | // shift+enter | |
65 | // last cell in notebook |
|
66 | // last cell in notebook | |
66 | var base_index = 3; |
|
67 | var base_index = 3; | |
67 | this.trigger_keydown('shift+enter'); // Creates one cell |
|
68 | this.trigger_keydown('shift+enter'); // Creates one cell | |
68 | this.validate_state('shift+enter (no cell below)', 'edit', base_index + 1); |
|
69 | this.validate_notebook_state('shift+enter (no cell below)', 'edit', base_index + 1); | |
69 | // not last cell in notebook & starts in edit mode |
|
70 | // not last cell in notebook & starts in edit mode | |
70 | this.click_cell_editor(base_index); |
|
71 | this.click_cell_editor(base_index); | |
71 | this.validate_state('click cell ' + base_index, 'edit', base_index); |
|
72 | this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); | |
72 | this.trigger_keydown('shift+enter'); |
|
73 | this.trigger_keydown('shift+enter'); | |
73 | this.validate_state('shift+enter (cell exists below)', 'command', base_index + 1); |
|
74 | this.validate_notebook_state('shift+enter (cell exists below)', 'command', base_index + 1); | |
74 | // starts in command mode |
|
75 | // starts in command mode | |
75 | this.trigger_keydown('k'); |
|
76 | this.trigger_keydown('k'); | |
76 | this.validate_state('k in comand mode', 'command', base_index); |
|
77 | this.validate_notebook_state('k in comand mode', 'command', base_index); | |
77 | this.trigger_keydown('shift+enter'); |
|
78 | this.trigger_keydown('shift+enter'); | |
78 | this.validate_state('shift+enter (start in command mode)', 'command', base_index + 1); |
|
79 | this.validate_notebook_state('shift+enter (start in command mode)', 'command', base_index + 1); | |
79 |
|
80 | |||
80 | // ctrl+enter |
|
81 | // ctrl+enter | |
81 | // last cell in notebook |
|
82 | // last cell in notebook | |
82 | base_index++; |
|
83 | base_index++; | |
83 | this.trigger_keydown('ctrl+enter'); |
|
84 | this.trigger_keydown('ctrl+enter'); | |
84 | this.validate_state('ctrl+enter (no cell below)', 'command', base_index); |
|
85 | this.validate_notebook_state('ctrl+enter (no cell below)', 'command', base_index); | |
85 | // not last cell in notebook & starts in edit mode |
|
86 | // not last cell in notebook & starts in edit mode | |
86 | this.click_cell_editor(base_index-1); |
|
87 | this.click_cell_editor(base_index-1); | |
87 | this.validate_state('click cell ' + (base_index-1), 'edit', base_index-1); |
|
88 | this.validate_notebook_state('click cell ' + (base_index-1), 'edit', base_index-1); | |
88 | this.trigger_keydown('ctrl+enter'); |
|
89 | this.trigger_keydown('ctrl+enter'); | |
89 | this.validate_state('ctrl+enter (cell exists below)', 'command', base_index-1); |
|
90 | this.validate_notebook_state('ctrl+enter (cell exists below)', 'command', base_index-1); | |
90 | // starts in command mode |
|
91 | // starts in command mode | |
91 | this.trigger_keydown('j'); |
|
92 | this.trigger_keydown('j'); | |
92 | this.validate_state('j in comand mode', 'command', base_index); |
|
93 | this.validate_notebook_state('j in comand mode', 'command', base_index); | |
93 | this.trigger_keydown('ctrl+enter'); |
|
94 | this.trigger_keydown('ctrl+enter'); | |
94 | this.validate_state('ctrl+enter (start in command mode)', 'command', base_index); |
|
95 | this.validate_notebook_state('ctrl+enter (start in command mode)', 'command', base_index); | |
95 |
|
96 | |||
96 | // alt+enter |
|
97 | // alt+enter | |
97 | // last cell in notebook |
|
98 | // last cell in notebook | |
98 | this.trigger_keydown('alt+enter'); // Creates one cell |
|
99 | this.trigger_keydown('alt+enter'); // Creates one cell | |
99 | this.validate_state('alt+enter (no cell below)', 'edit', base_index + 1); |
|
100 | this.validate_notebook_state('alt+enter (no cell below)', 'edit', base_index + 1); | |
100 | // not last cell in notebook & starts in edit mode |
|
101 | // not last cell in notebook & starts in edit mode | |
101 | this.click_cell_editor(base_index); |
|
102 | this.click_cell_editor(base_index); | |
102 | this.validate_state('click cell ' + base_index, 'edit', base_index); |
|
103 | this.validate_notebook_state('click cell ' + base_index, 'edit', base_index); | |
103 | this.trigger_keydown('alt+enter'); // Creates one cell |
|
104 | this.trigger_keydown('alt+enter'); // Creates one cell | |
104 | this.validate_state('alt+enter (cell exists below)', 'edit', base_index + 1); |
|
105 | this.validate_notebook_state('alt+enter (cell exists below)', 'edit', base_index + 1); | |
105 | // starts in command mode |
|
106 | // starts in command mode | |
106 | this.trigger_keydown('esc', 'k'); |
|
107 | this.trigger_keydown('esc', 'k'); | |
107 | this.validate_state('k in comand mode', 'command', base_index); |
|
108 | this.validate_notebook_state('k in comand mode', 'command', base_index); | |
108 | this.trigger_keydown('alt+enter'); // Creates one cell |
|
109 | this.trigger_keydown('alt+enter'); // Creates one cell | |
109 | this.validate_state('alt+enter (start in command mode)', 'edit', base_index + 1); |
|
110 | this.validate_notebook_state('alt+enter (start in command mode)', 'edit', base_index + 1); | |
110 |
|
111 | |||
111 | // Notebook will now have 8 cells, the index of the last cell will be 7. |
|
112 | // Notebook will now have 8 cells, the index of the last cell will be 7. | |
112 | this.test.assertEquals(this.get_cells_length(), 8, '*-enter commands added cells where needed.'); |
|
113 | this.test.assertEquals(this.get_cells_length(), 8, '*-enter commands added cells where needed.'); | |
113 | this.select_cell(7); |
|
114 | this.select_cell(7); | |
114 | this.validate_state('click cell ' + 7 + ' and esc', 'command', 7); |
|
115 | this.validate_notebook_state('click cell ' + 7 + ' and esc', 'command', 7); | |
115 |
|
116 | |||
116 | // Cell mode change |
|
117 | // Cell mode change | |
117 | this.trigger_keydown('r'); |
|
118 | this.trigger_keydown('r'); | |
@@ -137,7 +138,7 b' casper.notebook_test(function () {' | |||||
137 | // Cell deletion |
|
138 | // Cell deletion | |
138 | this.trigger_keydown('d', 'd'); |
|
139 | this.trigger_keydown('d', 'd'); | |
139 | this.test.assertEquals(this.get_cells_length(), 7, 'dd actually deletes a cell'); |
|
140 | this.test.assertEquals(this.get_cells_length(), 7, 'dd actually deletes a cell'); | |
140 | this.validate_state('dd', 'command', 6); |
|
141 | this.validate_notebook_state('dd', 'command', 6); | |
141 |
|
142 | |||
142 | // Make sure that if the time between d presses is too long, nothing gets removed. |
|
143 | // Make sure that if the time between d presses is too long, nothing gets removed. | |
143 | this.trigger_keydown('d'); |
|
144 | this.trigger_keydown('d'); | |
@@ -146,66 +147,66 b' casper.notebook_test(function () {' | |||||
146 | this.then(function () { |
|
147 | this.then(function () { | |
147 | this.trigger_keydown('d'); |
|
148 | this.trigger_keydown('d'); | |
148 | this.test.assertEquals(this.get_cells_length(), 7, "d, 1 second wait, d doesn't delete a cell"); |
|
149 | this.test.assertEquals(this.get_cells_length(), 7, "d, 1 second wait, d doesn't delete a cell"); | |
149 | this.validate_state('d, 1 second wait, d', 'command', 6); |
|
150 | this.validate_notebook_state('d, 1 second wait, d', 'command', 6); | |
150 |
|
151 | |||
151 | // Up and down in command mode |
|
152 | // Up and down in command mode | |
152 | this.trigger_keydown('j'); |
|
153 | this.trigger_keydown('j'); | |
153 | this.validate_state('j at end of notebook', 'command', 6); |
|
154 | this.validate_notebook_state('j at end of notebook', 'command', 6); | |
154 | this.trigger_keydown('down'); |
|
155 | this.trigger_keydown('down'); | |
155 | this.validate_state('down at end of notebook', 'command', 6); |
|
156 | this.validate_notebook_state('down at end of notebook', 'command', 6); | |
156 | this.trigger_keydown('up'); |
|
157 | this.trigger_keydown('up'); | |
157 | this.validate_state('up', 'command', 5); |
|
158 | this.validate_notebook_state('up', 'command', 5); | |
158 | this.select_cell(0); |
|
159 | this.select_cell(0); | |
159 | this.validate_state('select 0', 'command', 0); |
|
160 | this.validate_notebook_state('select 0', 'command', 0); | |
160 | this.trigger_keydown('k'); |
|
161 | this.trigger_keydown('k'); | |
161 | this.validate_state('k at top of notebook', 'command', 0); |
|
162 | this.validate_notebook_state('k at top of notebook', 'command', 0); | |
162 | this.trigger_keydown('up'); |
|
163 | this.trigger_keydown('up'); | |
163 | this.validate_state('up at top of notebook', 'command', 0); |
|
164 | this.validate_notebook_state('up at top of notebook', 'command', 0); | |
164 | this.trigger_keydown('down'); |
|
165 | this.trigger_keydown('down'); | |
165 | this.validate_state('down', 'command', 1); |
|
166 | this.validate_notebook_state('down', 'command', 1); | |
166 |
|
167 | |||
167 | // Up and down in edit mode |
|
168 | // Up and down in edit mode | |
168 | this.click_cell_editor(6); |
|
169 | this.click_cell_editor(6); | |
169 | this.validate_state('click cell 6', 'edit', 6); |
|
170 | this.validate_notebook_state('click cell 6', 'edit', 6); | |
170 | this.trigger_keydown('down'); |
|
171 | this.trigger_keydown('down'); | |
171 | this.validate_state('down at end of notebook', 'edit', 6); |
|
172 | this.validate_notebook_state('down at end of notebook', 'edit', 6); | |
172 | this.trigger_keydown('up'); |
|
173 | this.trigger_keydown('up'); | |
173 | this.validate_state('up', 'edit', 5); |
|
174 | this.validate_notebook_state('up', 'edit', 5); | |
174 | this.click_cell_editor(0); |
|
175 | this.click_cell_editor(0); | |
175 | this.validate_state('click 0', 'edit', 0); |
|
176 | this.validate_notebook_state('click 0', 'edit', 0); | |
176 | this.trigger_keydown('up'); |
|
177 | this.trigger_keydown('up'); | |
177 | this.validate_state('up at top of notebook', 'edit', 0); |
|
178 | this.validate_notebook_state('up at top of notebook', 'edit', 0); | |
178 | this.trigger_keydown('down'); |
|
179 | this.trigger_keydown('down'); | |
179 | this.validate_state('down', 'edit', 1); |
|
180 | this.validate_notebook_state('down', 'edit', 1); | |
180 |
|
181 | |||
181 | // Markdown rendering / unredering |
|
182 | // Markdown rendering / unredering | |
182 | this.select_cell(6); |
|
183 | this.select_cell(6); | |
183 | this.validate_state('select 6', 'command', 6); |
|
184 | this.validate_notebook_state('select 6', 'command', 6); | |
184 | this.trigger_keydown('m'); |
|
185 | this.trigger_keydown('m'); | |
185 | this.test.assertEquals(this.get_cell(6).cell_type, 'markdown', 'm; cell is markdown'); |
|
186 | this.test.assertEquals(this.get_cell(6).cell_type, 'markdown', 'm; cell is markdown'); | |
186 | this.test.assertEquals(this.get_cell(6).rendered, false, 'm; cell is rendered'); |
|
187 | this.test.assertEquals(this.get_cell(6).rendered, false, 'm; cell is rendered'); | |
187 | this.trigger_keydown('enter'); |
|
188 | this.trigger_keydown('enter'); | |
188 | this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); |
|
189 | this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); | |
189 | this.validate_state('enter', 'edit', 6); |
|
190 | this.validate_notebook_state('enter', 'edit', 6); | |
190 | this.trigger_keydown('ctrl+enter'); |
|
191 | this.trigger_keydown('ctrl+enter'); | |
191 | this.test.assertEquals(this.get_cell(6).rendered, true, 'ctrl+enter; cell is rendered'); |
|
192 | this.test.assertEquals(this.get_cell(6).rendered, true, 'ctrl+enter; cell is rendered'); | |
192 | this.validate_state('enter', 'command', 6); |
|
193 | this.validate_notebook_state('enter', 'command', 6); | |
193 | this.trigger_keydown('enter'); |
|
194 | this.trigger_keydown('enter'); | |
194 | this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); |
|
195 | this.test.assertEquals(this.get_cell(6).rendered, false, 'enter; cell is unrendered'); | |
195 | this.select_cell(5); |
|
196 | this.select_cell(5); | |
196 | this.test.assertEquals(this.get_cell(6).rendered, false, 'select 5; cell 6 is still unrendered'); |
|
197 | this.test.assertEquals(this.get_cell(6).rendered, false, 'select 5; cell 6 is still unrendered'); | |
197 | this.validate_state('select 5', 'command', 5); |
|
198 | this.validate_notebook_state('select 5', 'command', 5); | |
198 | this.select_cell(6); |
|
199 | this.select_cell(6); | |
199 | this.validate_state('select 6', 'command', 6); |
|
200 | this.validate_notebook_state('select 6', 'command', 6); | |
200 | this.trigger_keydown('ctrl+enter'); |
|
201 | this.trigger_keydown('ctrl+enter'); | |
201 | this.test.assertEquals(this.get_cell(6).rendered, true, 'ctrl+enter; cell is rendered'); |
|
202 | this.test.assertEquals(this.get_cell(6).rendered, true, 'ctrl+enter; cell is rendered'); | |
202 | this.select_cell(5); |
|
203 | this.select_cell(5); | |
203 | this.validate_state('select 5', 'command', 5); |
|
204 | this.validate_notebook_state('select 5', 'command', 5); | |
204 | this.trigger_keydown('shift+enter'); |
|
205 | this.trigger_keydown('shift+enter'); | |
205 | this.validate_state('shift+enter', 'command', 6); |
|
206 | this.validate_notebook_state('shift+enter', 'command', 6); | |
206 | this.test.assertEquals(this.get_cell(6).rendered, true, 'shift+enter; cell is rendered'); |
|
207 | this.test.assertEquals(this.get_cell(6).rendered, true, 'shift+enter; cell is rendered'); | |
207 | this.trigger_keydown('shift+enter'); // Creates one cell |
|
208 | this.trigger_keydown('shift+enter'); // Creates one cell | |
208 | this.validate_state('shift+enter', 'edit', 7); |
|
209 | this.validate_notebook_state('shift+enter', 'edit', 7); | |
209 | this.test.assertEquals(this.get_cell(6).rendered, true, 'shift+enter; cell is rendered'); |
|
210 | this.test.assertEquals(this.get_cell(6).rendered, true, 'shift+enter; cell is rendered'); | |
210 |
|
211 | |||
211 | // Cell movement ( ctrl+(k or j) ) |
|
212 | // Cell movement ( ctrl+(k or j) ) | |
@@ -214,81 +215,79 b' casper.notebook_test(function () {' | |||||
214 | this.trigger_keydown('ctrl+k'); // Move cell 2 up one |
|
215 | this.trigger_keydown('ctrl+k'); // Move cell 2 up one | |
215 | this.test.assertEquals(this.get_cell_text(1), b, 'ctrl+k; Cell 1 text is correct'); |
|
216 | this.test.assertEquals(this.get_cell_text(1), b, 'ctrl+k; Cell 1 text is correct'); | |
216 | this.test.assertEquals(this.get_cell_text(2), a, 'ctrl+k; Cell 2 text is correct'); |
|
217 | this.test.assertEquals(this.get_cell_text(2), a, 'ctrl+k; Cell 2 text is correct'); | |
217 | this.validate_state('ctrl+k', 'command', 1); |
|
218 | this.validate_notebook_state('ctrl+k', 'command', 1); | |
218 | this.trigger_keydown('ctrl+j'); // Move cell 1 down one |
|
219 | this.trigger_keydown('ctrl+j'); // Move cell 1 down one | |
219 | this.test.assertEquals(this.get_cell_text(1), a, 'ctrl+j; Cell 1 text is correct'); |
|
220 | this.test.assertEquals(this.get_cell_text(1), a, 'ctrl+j; Cell 1 text is correct'); | |
220 | this.test.assertEquals(this.get_cell_text(2), b, 'ctrl+j; Cell 2 text is correct'); |
|
221 | this.test.assertEquals(this.get_cell_text(2), b, 'ctrl+j; Cell 2 text is correct'); | |
221 | this.validate_state('ctrl+j', 'command', 2); |
|
222 | this.validate_notebook_state('ctrl+j', 'command', 2); | |
222 |
|
223 | |||
223 | // Cell insertion |
|
224 | // Cell insertion | |
224 | this.trigger_keydown('a'); // Creates one cell |
|
225 | this.trigger_keydown('a'); // Creates one cell | |
225 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); |
|
226 | this.test.assertEquals(this.get_cell_text(2), '', 'a; New cell 2 text is empty'); | |
226 | this.validate_state('a', 'command', 2); |
|
227 | this.validate_notebook_state('a', 'command', 2); | |
227 | this.trigger_keydown('b'); // Creates one cell |
|
228 | this.trigger_keydown('b'); // Creates one cell | |
228 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); |
|
229 | this.test.assertEquals(this.get_cell_text(2), '', 'b; Cell 2 text is still empty'); | |
229 | this.test.assertEquals(this.get_cell_text(3), '', 'b; New cell 3 text is empty'); |
|
230 | this.test.assertEquals(this.get_cell_text(3), '', 'b; New cell 3 text is empty'); | |
230 | this.validate_state('b', 'command', 3); |
|
231 | this.validate_notebook_state('b', 'command', 3); | |
231 |
|
232 | |||
232 | // Copy/paste/cut |
|
233 | // Copy/paste/cut | |
233 | var num_cells = this.get_cells_length(); |
|
234 | var num_cells = this.get_cells_length(); | |
234 | this.test.assertEquals(this.get_cell_text(1), a, 'Verify that cell 1 is a'); |
|
235 | this.test.assertEquals(this.get_cell_text(1), a, 'Verify that cell 1 is a'); | |
235 | this.select_cell(1); |
|
236 | this.select_cell(1); | |
236 | this.trigger_keydown('x'); // Cut |
|
237 | this.trigger_keydown('x'); // Cut | |
237 | this.validate_state('x', 'command', 1); |
|
238 | this.validate_notebook_state('x', 'command', 1); | |
238 | this.test.assertEquals(this.get_cells_length(), num_cells-1, 'Verify that a cell was removed.'); |
|
239 | this.test.assertEquals(this.get_cells_length(), num_cells-1, 'Verify that a cell was removed.'); | |
239 | this.test.assertEquals(this.get_cell_text(1), '', 'Verify that cell 2 is now where cell 1 was.'); |
|
240 | this.test.assertEquals(this.get_cell_text(1), '', 'Verify that cell 2 is now where cell 1 was.'); | |
240 | this.select_cell(2); |
|
241 | this.select_cell(2); | |
241 | this.trigger_keydown('v'); // Paste |
|
242 | this.trigger_keydown('v'); // Paste | |
242 | this.validate_state('v', 'command', 3); // Selection should move to pasted cell, below current cell. |
|
243 | this.validate_notebook_state('v', 'command', 3); // Selection should move to pasted cell, below current cell. | |
243 | this.test.assertEquals(this.get_cell_text(3), a, 'Verify that cell 3 has the cut contents.'); |
|
244 | this.test.assertEquals(this.get_cell_text(3), a, 'Verify that cell 3 has the cut contents.'); | |
244 | this.test.assertEquals(this.get_cells_length(), num_cells, 'Verify a the cell was added.'); |
|
245 | this.test.assertEquals(this.get_cells_length(), num_cells, 'Verify a the cell was added.'); | |
245 | this.trigger_keydown('v'); // Paste |
|
246 | this.trigger_keydown('v'); // Paste | |
246 | this.validate_state('v', 'command', 4); // Selection should move to pasted cell, below current cell. |
|
247 | this.validate_notebook_state('v', 'command', 4); // Selection should move to pasted cell, below current cell. | |
247 | this.test.assertEquals(this.get_cell_text(4), a, 'Verify that cell 4 has the cut contents.'); |
|
248 | this.test.assertEquals(this.get_cell_text(4), a, 'Verify that cell 4 has the cut contents.'); | |
248 | this.test.assertEquals(this.get_cells_length(), num_cells+1, 'Verify a the cell was added.'); |
|
249 | this.test.assertEquals(this.get_cells_length(), num_cells+1, 'Verify a the cell was added.'); | |
249 | this.select_cell(5); |
|
250 | this.select_cell(5); | |
250 | this.trigger_keydown('c'); // Copy |
|
251 | this.trigger_keydown('c'); // Copy | |
251 | this.validate_state('c', 'command', 5); |
|
252 | this.validate_notebook_state('c', 'command', 5); | |
252 | this.test.assertEquals(this.get_cell_text(5), b, 'Verify that cell 5 is b'); |
|
253 | this.test.assertEquals(this.get_cell_text(5), b, 'Verify that cell 5 is b'); | |
253 | this.select_cell(6); |
|
254 | this.select_cell(6); | |
254 | this.trigger_keydown('c'); // Copy |
|
255 | this.trigger_keydown('c'); // Copy | |
255 | this.validate_state('c', 'command', 6); |
|
256 | this.validate_notebook_state('c', 'command', 6); | |
256 | this.test.assertEquals(this.get_cell_text(6), c, 'Verify that cell 6 is c'); |
|
257 | this.test.assertEquals(this.get_cell_text(6), c, 'Verify that cell 6 is c'); | |
257 | this.trigger_keydown('v'); // Paste |
|
258 | this.trigger_keydown('v'); // Paste | |
258 | this.validate_state('v', 'command', 7); |
|
259 | this.validate_notebook_state('v', 'command', 7); | |
259 | this.test.assertEquals(this.get_cell_text(6), c, 'Verify that cell 6 still has the copied contents.'); |
|
260 | this.test.assertEquals(this.get_cell_text(6), c, 'Verify that cell 6 still has the copied contents.'); | |
260 | this.test.assertEquals(this.get_cell_text(7), c, 'Verify that cell 7 has the copied contents.'); |
|
261 | this.test.assertEquals(this.get_cell_text(7), c, 'Verify that cell 7 has the copied contents.'); | |
261 | this.test.assertEquals(this.get_cells_length(), num_cells+2, 'Verify a the cell was added.'); |
|
262 | this.test.assertEquals(this.get_cells_length(), num_cells+2, 'Verify a the cell was added.'); | |
262 | this.select_cell(0); |
|
263 | this.select_cell(0); | |
263 | this.trigger_keydown('shift+v'); // Paste |
|
264 | this.trigger_keydown('shift+v'); // Paste | |
264 | this.validate_state('shift+v', 'command', 0); |
|
265 | this.validate_notebook_state('shift+v', 'command', 0); | |
265 | this.test.assertEquals(this.get_cell_text(0), c, 'Verify that cell 0 has the copied contents.'); |
|
266 | this.test.assertEquals(this.get_cell_text(0), c, 'Verify that cell 0 has the copied contents.'); | |
266 | this.test.assertEquals(this.get_cells_length(), num_cells+3, 'Verify a the cell was added.'); |
|
267 | this.test.assertEquals(this.get_cells_length(), num_cells+3, 'Verify a the cell was added.'); | |
267 |
|
268 | |||
268 | // Split and merge cells |
|
269 | // Split and merge cells | |
269 | this.select_cell(0); |
|
270 | this.select_cell(0); | |
270 | this.trigger_keydown('a', 'enter'); // Create cell above and enter edit mode. |
|
271 | this.trigger_keydown('a', 'enter'); // Create cell above and enter edit mode. | |
271 | this.validate_state('a, enter', 'edit', 0); |
|
272 | this.validate_notebook_state('a, enter', 'edit', 0); | |
272 | this.set_cell_text(0, 'abcd'); |
|
273 | this.set_cell_text(0, 'abcd'); | |
273 | this.set_cell_editor_cursor(0, 0, 2); |
|
274 | this.set_cell_editor_cursor(0, 0, 2); | |
274 | this.test.assertEquals(this.get_cell_text(0), 'abcd', 'Verify that cell 0 has the new contents.'); |
|
275 | this.test.assertEquals(this.get_cell_text(0), 'abcd', 'Verify that cell 0 has the new contents.'); | |
275 | this.trigger_keydown('alt+-'); // Split |
|
276 | this.trigger_keydown('alt+-'); // Split | |
276 | this.test.assertEquals(this.get_cell_text(0), 'ab', 'split; Verify that cell 0 has the first half.'); |
|
277 | this.test.assertEquals(this.get_cell_text(0), 'ab', 'split; Verify that cell 0 has the first half.'); | |
277 | this.test.assertEquals(this.get_cell_text(1), 'cd', 'split; Verify that cell 1 has the second half.'); |
|
278 | this.test.assertEquals(this.get_cell_text(1), 'cd', 'split; Verify that cell 1 has the second half.'); | |
278 | this.validate_state('split', 'edit', 1); |
|
279 | this.validate_notebook_state('split', 'edit', 1); | |
279 | this.select_cell(0); // Move up to cell 0 |
|
280 | this.select_cell(0); // Move up to cell 0 | |
280 | this.trigger_keydown('shift+m'); // Merge |
|
281 | this.trigger_keydown('shift+m'); // Merge | |
281 | this.validate_state('merge', 'command', 0); |
|
282 | this.validate_notebook_state('merge', 'command', 0); | |
282 | this.test.assertEquals(this.get_cell_text(0), 'ab\ncd', 'merge; Verify that cell 0 has the merged contents.'); |
|
283 | this.test.assertEquals(this.get_cell_text(0), 'ab\ncd', 'merge; Verify that cell 0 has the merged contents.'); | |
283 | }); |
|
284 | }); | |
284 |
|
285 | |||
285 | // Utility functions. |
|
286 | // Utility functions. | |
286 | this.validate_state = function(message, mode, cell_index) { |
|
287 | this.validate_notebook_state = function(message, mode, cell_index) { | |
287 | // General tests. |
|
288 | // General tests. | |
288 | this.test.assertEquals(this.get_keyboard_mode(), this.get_notebook_mode(), |
|
289 | this.test.assertEquals(this.get_keyboard_mode(), this.get_notebook_mode(), | |
289 | message + '; keyboard and notebook modes match'); |
|
290 | message + '; keyboard and notebook modes match'); | |
290 | // Is codemirror focused appropriately? |
|
|||
291 | this.test.assert(this.is_editor_focus_valid(), message + '; cell editor focused appropriately'); |
|
|||
292 | // Is the selected cell the only cell that is selected? |
|
291 | // Is the selected cell the only cell that is selected? | |
293 | if (cell_index!==undefined) { |
|
292 | if (cell_index!==undefined) { | |
294 | this.test.assert(this.is_only_cell_selected(cell_index), |
|
293 | this.test.assert(this.is_only_cell_selected(cell_index), | |
@@ -303,41 +302,24 b' casper.notebook_test(function () {' | |||||
303 | // Make sure there isn't a single cell in edit mode. |
|
302 | // Make sure there isn't a single cell in edit mode. | |
304 | this.test.assert(this.is_only_cell_edit(null), |
|
303 | this.test.assert(this.is_only_cell_edit(null), | |
305 | message + '; all cells in command mode'); |
|
304 | message + '; all cells in command mode'); | |
|
305 | this.test.assert(this.is_cell_editor_focused(null), | |||
|
306 | message + '; no cell editors are focused while in command mode'); | |||
306 |
|
307 | |||
307 | } else if (mode==='edit') { |
|
308 | } else if (mode==='edit') { | |
308 | // Are the notebook and keyboard manager in edit mode? |
|
309 | // Are the notebook and keyboard manager in edit mode? | |
309 | this.test.assertEquals(this.get_keyboard_mode(), 'edit', |
|
310 | this.test.assertEquals(this.get_keyboard_mode(), 'edit', | |
310 | message + '; in edit mode'); |
|
311 | message + '; in edit mode'); | |
311 | // Is the specified cell the only cell in edit mode? |
|
|||
312 | if (cell_index!==undefined) { |
|
312 | if (cell_index!==undefined) { | |
|
313 | // Is the specified cell the only cell in edit mode? | |||
313 | this.test.assert(this.is_only_cell_edit(cell_index), |
|
314 | this.test.assert(this.is_only_cell_edit(cell_index), | |
314 | message + '; cell ' + cell_index + ' is the only cell in edit mode'); |
|
315 | message + '; cell ' + cell_index + ' is the only cell in edit mode'); | |
|
316 | // Is the specified cell the only cell with a focused code mirror? | |||
|
317 | this.test.assert(this.is_cell_editor_focused(cell_index), | |||
|
318 | message + '; cell ' + cell_index + '\'s editor is appropriately focused'); | |||
315 | } |
|
319 | } | |
316 |
|
320 | |||
317 | } else { |
|
321 | } else { | |
318 | this.test.assert(false, message + '; ' + mode + ' is an unknown mode'); |
|
322 | this.test.assert(false, message + '; ' + mode + ' is an unknown mode'); | |
319 | } |
|
323 | } | |
320 | }; |
|
324 | }; | |
321 |
|
||||
322 | this.is_editor_focus_valid = function() { |
|
|||
323 | var cells_length = this.get_cells_length(); |
|
|||
324 | for (var i = 0; i < cells_length; i++) { |
|
|||
325 | if (!this.is_cell_editor_focus_valid(i)) { |
|
|||
326 | return false; |
|
|||
327 | } |
|
|||
328 | } |
|
|||
329 | return true; |
|
|||
330 | }; |
|
|||
331 |
|
||||
332 | this.is_cell_editor_focus_valid = function(index) { |
|
|||
333 | var cell = this.get_cell(index); |
|
|||
334 | if (cell) { |
|
|||
335 | if (cell.mode == 'edit') { |
|
|||
336 | return this.is_cell_editor_focused(index); |
|
|||
337 | } else { |
|
|||
338 | return !this.is_cell_editor_focused(index); |
|
|||
339 | } |
|
|||
340 | } |
|
|||
341 | return true; |
|
|||
342 | }; |
|
|||
343 | }); |
|
325 | }); |
@@ -296,10 +296,17 b' casper.get_cell = function(index) {' | |||||
296 | }; |
|
296 | }; | |
297 |
|
297 | |||
298 | casper.is_cell_editor_focused = function(index) { |
|
298 | casper.is_cell_editor_focused = function(index) { | |
|
299 | // Make sure a cell's editor is the only editor focused on the page. | |||
299 | return this.evaluate(function(i) { |
|
300 | return this.evaluate(function(i) { | |
300 | var cell = IPython.notebook.get_cell(i); |
|
301 | var focused_textarea = $('#notebook .CodeMirror-focused textarea'); | |
301 | if (cell) { |
|
302 | if (focused_textarea.length > 1) { throw 'More than one Code Mirror editor is focused at once!'; } | |
302 | return $(cell.code_mirror.getInputField()).is('.CodeMirror-focused *'); |
|
303 | if (i === null) { | |
|
304 | return focused_textarea.length === 0; | |||
|
305 | } else { | |||
|
306 | var cell = IPython.notebook.get_cell(i); | |||
|
307 | if (cell) { | |||
|
308 | return cell.code_mirror.getInputField() == focused_textarea[0]; | |||
|
309 | } | |||
303 | } |
|
310 | } | |
304 | return false; |
|
311 | return false; | |
305 | }, {i : index}); |
|
312 | }, {i : index}); | |
@@ -399,7 +406,7 b" casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {" | |||||
399 | }); |
|
406 | }); | |
400 |
|
407 | |||
401 | // Pass `console.log` calls from page JS to casper. |
|
408 | // Pass `console.log` calls from page JS to casper. | |
402 |
casper.print |
|
409 | casper.print_log = function () { | |
403 | this.on('remote.message', function(msg) { |
|
410 | this.on('remote.message', function(msg) { | |
404 | this.echo('Remote message caught: ' + msg); |
|
411 | this.echo('Remote message caught: ' + msg); | |
405 | }); |
|
412 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now