Show More
@@ -1,823 +1,885 b'' | |||
|
1 | 1 | // Test the widget framework. |
|
2 | 2 | casper.notebook_test(function () { |
|
3 | 3 | var index; |
|
4 | 4 | |
|
5 | 5 | // Test widget dependencies //////////////////////////////////////////////// |
|
6 | 6 | this.then(function () { |
|
7 | 7 | |
|
8 | 8 | // Check if the WidgetManager class is defined. |
|
9 | 9 | this.test.assert(this.evaluate(function() { |
|
10 | 10 | return IPython.WidgetManager != undefined; |
|
11 | 11 | }), 'WidgetManager class is defined'); |
|
12 | 12 | }); |
|
13 | 13 | |
|
14 | 14 | index = this.append_cell( |
|
15 | 15 | 'from IPython.html import widgets\n' + |
|
16 | 16 | 'from IPython.display import display, clear_output\n' + |
|
17 | 17 | 'print("Success")'); |
|
18 | 18 | this.execute_cell_then(index); |
|
19 | 19 | |
|
20 | 20 | this.wait(500); // Wait for require.js async callbacks to load dependencies. |
|
21 | 21 | |
|
22 | 22 | this.then(function () { |
|
23 | 23 | // Check if the widget manager has been instanciated. |
|
24 | 24 | this.test.assert(this.evaluate(function() { |
|
25 | 25 | return IPython.widget_manager != undefined; |
|
26 | 26 | }), 'Notebook widget manager instanciated'); |
|
27 | 27 | }); |
|
28 | 28 | |
|
29 | 29 | // Check widget mapping //////////////////////////////////////////////////// |
|
30 | 30 | index = this.append_cell( |
|
31 | 31 | 'names = [name for name in dir(widgets)' + |
|
32 | 32 | ' if name.endswith("Widget") and name!= "Widget"]\n' + |
|
33 | 33 | 'for name in names:\n' + |
|
34 | 34 | ' print(name)\n'); |
|
35 | 35 | this.execute_cell_then(index, function(index){ |
|
36 | 36 | |
|
37 | 37 | // Get the widget names that are registered with the widget manager. Assume |
|
38 | 38 | // a 1 to 1 mapping of model and widgets names (model names just have 'model' |
|
39 | 39 | // suffixed). |
|
40 | 40 | var javascript_names = this.evaluate(function () { |
|
41 | 41 | names = []; |
|
42 | 42 | for (var name in IPython.widget_manager.widget_model_types) { |
|
43 | 43 | names.push(name.replace('Model','')); |
|
44 | 44 | } |
|
45 | 45 | return names; |
|
46 | 46 | }); |
|
47 | 47 | |
|
48 | 48 | // Get the widget names registered in python. |
|
49 | 49 | var python_names = this.get_output_cell(index).text.split('\n'); |
|
50 | 50 | |
|
51 | 51 | // Make sure the two lists have the same items. |
|
52 | 52 | for (var i in javascript_names) { |
|
53 | 53 | var javascript_name = javascript_names[i]; |
|
54 | 54 | var found = false; |
|
55 | 55 | for (var j in python_names) { |
|
56 | 56 | var python_name = python_names[j]; |
|
57 | 57 | if (python_name==javascript_name) { |
|
58 | 58 | found = true; |
|
59 | 59 | break; |
|
60 | 60 | } |
|
61 | 61 | } |
|
62 | 62 | this.test.assert(found, javascript_name + ' exists in python'); |
|
63 | 63 | } |
|
64 | 64 | for (var i in python_names) { |
|
65 | 65 | var python_name = python_names[i]; |
|
66 | 66 | if (python_name.length > 0) { |
|
67 | 67 | var found = false; |
|
68 | 68 | for (var j in javascript_names) { |
|
69 | 69 | var javascript_name = javascript_names[j]; |
|
70 | 70 | if (python_name==javascript_name) { |
|
71 | 71 | found = true; |
|
72 | 72 | break; |
|
73 | 73 | } |
|
74 | 74 | } |
|
75 | 75 | this.test.assert(found, python_name + ' exists in javascript'); |
|
76 | 76 | } |
|
77 | 77 | } |
|
78 | 78 | }); |
|
79 | 79 | |
|
80 | 80 | |
|
81 | 81 | // Test bool widget //////////////////////////////////////////////////////// |
|
82 | 82 | var bool_index = this.append_cell( |
|
83 | 83 | 'bool_widget = widgets.BoolWidget(description="Title", value=True)\n' + |
|
84 | 84 | 'display(bool_widget)\n'+ |
|
85 | 85 | 'display(bool_widget, view_name="ToggleButtonView")\n' + |
|
86 | 86 | 'print("Success")'); |
|
87 | 87 | this.execute_cell_then(bool_index, function(index){ |
|
88 | 88 | |
|
89 | 89 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
90 | 90 | 'Create bool widget cell executed with correct output.'); |
|
91 | 91 | |
|
92 | 92 | this.test.assert(this.cell_element_exists(index, |
|
93 | 93 | '.widget-area .widget-subarea'), |
|
94 | 94 | 'Widget subarea exists.'); |
|
95 | 95 | |
|
96 | 96 | this.test.assert(this.cell_element_exists(index, |
|
97 | 97 | '.widget-area .widget-subarea .widget-hbox-single input'), |
|
98 | 98 | 'Checkbox exists.'); |
|
99 | 99 | |
|
100 | 100 | this.test.assert(this.cell_element_function(index, |
|
101 | 101 | '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), |
|
102 | 102 | 'Checkbox is checked.'); |
|
103 | 103 | |
|
104 | 104 | this.test.assert(this.cell_element_exists(index, |
|
105 | 105 | '.widget-area .widget-subarea .widget-hbox-single .widget-hlabel'), |
|
106 | 106 | 'Checkbox label exists.'); |
|
107 | 107 | |
|
108 | 108 | this.test.assert(this.cell_element_function(index, |
|
109 | 109 | '.widget-area .widget-subarea .widget-hbox-single .widget-hlabel', 'html')=="Title", |
|
110 | 110 | 'Checkbox labeled correctly.'); |
|
111 | 111 | |
|
112 | 112 | this.test.assert(this.cell_element_exists(index, |
|
113 | 113 | '.widget-area .widget-subarea div button'), |
|
114 | 114 | 'Toggle button exists.'); |
|
115 | 115 | |
|
116 | 116 | this.test.assert(this.cell_element_function(index, |
|
117 | 117 | '.widget-area .widget-subarea div button', 'html')=="Title", |
|
118 | 118 | 'Toggle button labeled correctly.'); |
|
119 | 119 | |
|
120 | 120 | this.test.assert(this.cell_element_function(index, |
|
121 | 121 | '.widget-area .widget-subarea div button', 'hasClass', ['active']), |
|
122 | 122 | 'Toggle button is toggled.'); |
|
123 | 123 | |
|
124 | 124 | }); |
|
125 | 125 | |
|
126 | 126 | index = this.append_cell( |
|
127 | 127 | 'bool_widget.value = False\n' + |
|
128 | 128 | 'print("Success")'); |
|
129 | 129 | this.execute_cell_then(index, function(index){ |
|
130 | 130 | |
|
131 | 131 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
132 | 132 | 'Change bool widget value cell executed with correct output.'); |
|
133 | 133 | |
|
134 | 134 | this.test.assert(! this.cell_element_function(bool_index, |
|
135 | 135 | '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), |
|
136 | 136 | 'Checkbox is not checked. (1)'); |
|
137 | 137 | |
|
138 | 138 | this.test.assert(! this.cell_element_function(bool_index, |
|
139 | 139 | '.widget-area .widget-subarea div button', 'hasClass', ['active']), |
|
140 | 140 | 'Toggle button is not toggled. (1)'); |
|
141 | 141 | |
|
142 | 142 | // Try toggling the bool by clicking on the toggle button. |
|
143 | 143 | this.cell_element_function(bool_index, '.widget-area .widget-subarea div button', 'click'); |
|
144 | 144 | |
|
145 | 145 | this.test.assert(this.cell_element_function(bool_index, |
|
146 | 146 | '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), |
|
147 | 147 | 'Checkbox is checked. (2)'); |
|
148 | 148 | |
|
149 | 149 | this.test.assert(this.cell_element_function(bool_index, |
|
150 | 150 | '.widget-area .widget-subarea div button', 'hasClass', ['active']), |
|
151 | 151 | 'Toggle button is toggled. (2)'); |
|
152 | 152 | |
|
153 | 153 | // Try toggling the bool by clicking on the checkbox. |
|
154 | 154 | this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click'); |
|
155 | 155 | |
|
156 | 156 | this.test.assert(! this.cell_element_function(bool_index, |
|
157 | 157 | '.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), |
|
158 | 158 | 'Checkbox is not checked. (3)'); |
|
159 | 159 | |
|
160 | 160 | this.test.assert(! this.cell_element_function(bool_index, |
|
161 | 161 | '.widget-area .widget-subarea div button', 'hasClass', ['active']), |
|
162 | 162 | 'Toggle button is not toggled. (3)'); |
|
163 | 163 | |
|
164 | 164 | }); |
|
165 | 165 | |
|
166 | 166 | // Test button widget ////////////////////////////////////////////////////// |
|
167 | 167 | |
|
168 | 168 | var button_index = this.append_cell( |
|
169 | 169 | 'button = widgets.ButtonWidget(description="Title")\n' + |
|
170 | 170 | 'display(button)\n'+ |
|
171 | 171 | 'print("Success")\n' + |
|
172 | 172 | 'def handle_click(sender):\n' + |
|
173 | 173 | ' print("Clicked")\n' + |
|
174 | 174 | 'button.on_click(handle_click)'); |
|
175 | 175 | this.execute_cell_then(button_index, function(index){ |
|
176 | 176 | |
|
177 | 177 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
178 | 178 | 'Create button cell executed with correct output.'); |
|
179 | 179 | |
|
180 | 180 | this.test.assert(this.cell_element_exists(index, |
|
181 | 181 | '.widget-area .widget-subarea'), |
|
182 | 182 | 'Widget subarea exists.'); |
|
183 | 183 | |
|
184 | 184 | this.test.assert(this.cell_element_exists(index, |
|
185 | 185 | '.widget-area .widget-subarea button'), |
|
186 | 186 | 'Widget button exists.'); |
|
187 | 187 | |
|
188 | 188 | this.test.assert(this.cell_element_function(index, |
|
189 | 189 | '.widget-area .widget-subarea button', 'html')=='Title', |
|
190 | 190 | 'Set button description.'); |
|
191 | 191 | |
|
192 | 192 | this.cell_element_function(index, |
|
193 | 193 | '.widget-area .widget-subarea button', 'click'); |
|
194 | 194 | }); |
|
195 | 195 | |
|
196 | 196 | this.wait(500); // Wait for click to execute in kernel and write output |
|
197 | 197 | |
|
198 | 198 | this.then(function () { |
|
199 | 199 | this.test.assert(this.get_output_cell(button_index, 1).text == 'Clicked\n', |
|
200 | 200 | 'Button click event fires.'); |
|
201 | 201 | }); |
|
202 | 202 | |
|
203 | 203 | // Close the button widget asynchronisly. |
|
204 | 204 | index = this.append_cell('button.close()\n'); |
|
205 | 205 | this.execute_cell(index); |
|
206 | 206 | |
|
207 | 207 | this.wait(500); // Wait for the button to close. |
|
208 | 208 | |
|
209 | 209 | this.then(function(){ |
|
210 | 210 | this.test.assert(! this.cell_element_exists(button_index, |
|
211 | 211 | '.widget-area .widget-subarea button'), |
|
212 | 212 | 'Widget button doesn\'t exists.'); |
|
213 | 213 | }); |
|
214 | 214 | |
|
215 | 215 | // Test container widget /////////////////////////////////////////////////// |
|
216 | 216 | var container_index = this.append_cell( |
|
217 | 217 | 'container = widgets.ContainerWidget()\n' + |
|
218 | 218 | 'button = widgets.ButtonWidget(parent=container)\n'+ |
|
219 | 219 | 'display(container)\n'+ |
|
220 | 220 | 'container.add_class("my-test-class")\n'+ |
|
221 | 221 | 'print("Success")\n'); |
|
222 | 222 | this.execute_cell_then(container_index, function(index){ |
|
223 | 223 | |
|
224 | 224 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
225 | 225 | 'Create container cell executed with correct output.'); |
|
226 | 226 | |
|
227 | 227 | this.test.assert(this.cell_element_exists(index, |
|
228 | 228 | '.widget-area .widget-subarea'), |
|
229 | 229 | 'Widget subarea exists.'); |
|
230 | 230 | |
|
231 | 231 | this.test.assert(this.cell_element_exists(index, |
|
232 | 232 | '.widget-area .widget-subarea .widget-container'), |
|
233 | 233 | 'Widget container exists.'); |
|
234 | 234 | |
|
235 | 235 | this.test.assert(this.cell_element_exists(index, |
|
236 | 236 | '.widget-area .widget-subarea .my-test-class'), |
|
237 | 237 | 'add_class works.'); |
|
238 | 238 | |
|
239 | 239 | this.test.assert(this.cell_element_exists(index, |
|
240 | 240 | '.widget-area .widget-subarea .my-test-class button'), |
|
241 | 241 | 'Container parent/child relationship works.'); |
|
242 | 242 | }); |
|
243 | 243 | |
|
244 | 244 | index = this.append_cell( |
|
245 | 245 | 'container.set_css("display", "none")\n'+ |
|
246 | 246 | 'print("Success")\n'); |
|
247 | 247 | this.execute_cell_then(index, function(index){ |
|
248 | 248 | |
|
249 | 249 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
250 | 250 | 'Set container class CSS cell executed with correct output.'); |
|
251 | 251 | |
|
252 | 252 | this.test.assert(this.cell_element_function(container_index, |
|
253 | 253 | '.widget-area .widget-subarea .my-test-class', 'css', ['display'])=='none', |
|
254 | 254 | 'set_css works.'); |
|
255 | 255 | }); |
|
256 | 256 | |
|
257 | 257 | index = this.append_cell( |
|
258 | 258 | 'container.remove_class("my-test-class")\n'+ |
|
259 | 259 | 'print("Success")\n'); |
|
260 | 260 | this.execute_cell_then(index, function(index){ |
|
261 | 261 | |
|
262 | 262 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
263 | 263 | 'Remove container class cell executed with correct output.'); |
|
264 | 264 | |
|
265 | 265 | this.test.assert(! this.cell_element_exists(container_index, |
|
266 | 266 | '.widget-area .widget-subarea .my-test-class'), |
|
267 | 267 | 'remove_class works.'); |
|
268 | 268 | }); |
|
269 | 269 | |
|
270 | 270 | index = this.append_cell( |
|
271 | 271 | 'display(button)\n'+ |
|
272 | 272 | 'print("Success")\n'); |
|
273 | 273 | this.execute_cell_then(index, function(index){ |
|
274 | 274 | |
|
275 | 275 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
276 | 276 | 'Display container child executed with correct output.'); |
|
277 | 277 | |
|
278 | 278 | this.test.assert(! this.cell_element_exists(index, |
|
279 | 279 | '.widget-area .widget-subarea .widget-container'), |
|
280 | 280 | 'Parent container not displayed.'); |
|
281 | 281 | |
|
282 | 282 | this.test.assert(this.cell_element_exists(index, |
|
283 | 283 | '.widget-area .widget-subarea button'), |
|
284 | 284 | 'Child displayed.'); |
|
285 | 285 | }); |
|
286 | 286 | |
|
287 | 287 | // Test float range widget ///////////////////////////////////////////////// |
|
288 | 288 | var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider'; |
|
289 | 289 | var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text'; |
|
290 | 290 | |
|
291 | 291 | var floatrange_index = this.append_cell( |
|
292 | 292 | 'floatrange = widgets.FloatRangeWidget()\n' + |
|
293 | 293 | 'display(floatrange)\n' + |
|
294 | 294 | 'display(floatrange, view_name="FloatTextView")\n' + |
|
295 | 295 | 'print("Success")\n'); |
|
296 | 296 | this.execute_cell_then(floatrange_index, function(index){ |
|
297 | 297 | |
|
298 | 298 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
299 | 299 | 'Create float range cell executed with correct output.'); |
|
300 | 300 | |
|
301 | 301 | this.test.assert(this.cell_element_exists(index, |
|
302 | 302 | '.widget-area .widget-subarea'), |
|
303 | 303 | 'Widget subarea exists.'); |
|
304 | 304 | |
|
305 | 305 | this.test.assert(this.cell_element_exists(index, slider_query), |
|
306 | 306 | 'Widget slider exists.'); |
|
307 | 307 | |
|
308 | 308 | this.test.assert(this.cell_element_exists(index, float_text_query), |
|
309 | 309 | 'Widget float textbox exists.'); |
|
310 | 310 | }); |
|
311 | 311 | |
|
312 | 312 | index = this.append_cell( |
|
313 | 313 | 'floatrange.max = 50.0\n' + |
|
314 | 314 | 'floatrange.min = -50.0\n' + |
|
315 | 315 | 'floatrange.value = 25.0\n' + |
|
316 | 316 | 'print("Success")\n'); |
|
317 | 317 | this.execute_cell_then(index, function(index){ |
|
318 | 318 | |
|
319 | 319 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
320 | 320 | 'Float range properties cell executed with correct output.'); |
|
321 | 321 | |
|
322 | 322 | this.test.assert(this.cell_element_exists(floatrange_index, slider_query), |
|
323 | 323 | 'Widget slider exists.'); |
|
324 | 324 | |
|
325 | 325 | this.test.assert(this.cell_element_function(floatrange_index, slider_query, |
|
326 | 326 | 'slider', ['value']) == 25.0, |
|
327 | 327 | 'Slider set to Python value.'); |
|
328 | 328 | |
|
329 | 329 | this.test.assert(this.cell_element_function(floatrange_index, float_text_query, |
|
330 | 330 | 'val') == 25.0, 'Float textbox set to Python value.'); |
|
331 | 331 | |
|
332 | 332 | // Clear the float textbox value and then set it to 1 by emulating |
|
333 | 333 | // keyboard presses. |
|
334 | 334 | this.cell_element_function(floatrange_index, float_text_query, 'val', ['']); |
|
335 | 335 | this.sendKeys(float_text_query, '1'); |
|
336 | 336 | }); |
|
337 | 337 | |
|
338 | 338 | this.wait(500); // Wait for change to execute in kernel |
|
339 | 339 | |
|
340 | 340 | index = this.append_cell('print(floatrange.value)\n'); |
|
341 | 341 | this.execute_cell_then(index, function(index){ |
|
342 | 342 | this.test.assert(this.get_output_cell(index).text == '1.0\n', |
|
343 | 343 | 'Float textbox set float range value'); |
|
344 | 344 | |
|
345 | 345 | // Clear the float textbox value and then set it to 120 by emulating |
|
346 | 346 | // keyboard presses. |
|
347 | 347 | this.cell_element_function(floatrange_index, float_text_query, 'val', ['']); |
|
348 | 348 | this.sendKeys(float_text_query, '120'); |
|
349 | 349 | }); |
|
350 | 350 | |
|
351 | 351 | this.wait(500); // Wait for change to execute in kernel |
|
352 | 352 | |
|
353 | 353 | index = this.append_cell('print(floatrange.value)\n'); |
|
354 | 354 | this.execute_cell_then(index, function(index){ |
|
355 | 355 | this.test.assert(this.get_output_cell(index).text == '50.0\n', |
|
356 | 356 | 'Float textbox value bound'); |
|
357 | 357 | |
|
358 | 358 | // Clear the float textbox value and then set it to 'hello world' by |
|
359 | 359 | // emulating keyboard presses. 'hello world' should get filtered... |
|
360 | 360 | this.cell_element_function(floatrange_index, float_text_query, 'val', ['']); |
|
361 | 361 | this.sendKeys(float_text_query, 'hello world'); |
|
362 | 362 | }); |
|
363 | 363 | |
|
364 | 364 | this.wait(500); // Wait for change to execute in kernel |
|
365 | 365 | |
|
366 | 366 | index = this.append_cell('print(floatrange.value)\n'); |
|
367 | 367 | this.execute_cell_then(index, function(index){ |
|
368 | 368 | this.test.assert(this.get_output_cell(index).text == '50.0\n', |
|
369 | 369 | 'Invalid float textbox characters ignored'); |
|
370 | 370 | }); |
|
371 | 371 | |
|
372 | 372 | // Test float widget /////////////////////////////////////////////////////// |
|
373 | 373 | var float_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text'; |
|
374 | 374 | |
|
375 | 375 | var float_index = this.append_cell( |
|
376 | 376 | 'float_widget = widgets.FloatWidget()\n' + |
|
377 | 377 | 'display(float_widget)\n' + |
|
378 | 378 | 'float_widget.add_class("my-second-float-text")\n' + |
|
379 | 379 | 'print("Success")\n'); |
|
380 | 380 | this.execute_cell_then(float_index, function(index){ |
|
381 | 381 | |
|
382 | 382 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
383 | 383 | 'Create float cell executed with correct output.'); |
|
384 | 384 | |
|
385 | 385 | this.test.assert(this.cell_element_exists(index, |
|
386 | 386 | '.widget-area .widget-subarea'), |
|
387 | 387 | 'Widget subarea exists.'); |
|
388 | 388 | |
|
389 | 389 | this.test.assert(this.cell_element_exists(index, float_text_query_2), |
|
390 | 390 | 'Widget float textbox exists.'); |
|
391 | 391 | |
|
392 | 392 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); |
|
393 | 393 | this.sendKeys(float_text_query_2, '1.05'); |
|
394 | 394 | }); |
|
395 | 395 | |
|
396 | 396 | this.wait(500); // Wait for change to execute in kernel |
|
397 | 397 | |
|
398 | 398 | index = this.append_cell('print(float_widget.value)\n'); |
|
399 | 399 | this.execute_cell_then(index, function(index){ |
|
400 | 400 | this.test.assert(this.get_output_cell(index).text == '1.05\n', |
|
401 | 401 | 'Float textbox value set.'); |
|
402 | 402 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); |
|
403 | 403 | this.sendKeys(float_text_query_2, '123456789.0'); |
|
404 | 404 | }); |
|
405 | 405 | |
|
406 | 406 | this.wait(500); // Wait for change to execute in kernel |
|
407 | 407 | |
|
408 | 408 | index = this.append_cell('print(float_widget.value)\n'); |
|
409 | 409 | this.execute_cell_then(index, function(index){ |
|
410 | 410 | this.test.assert(this.get_output_cell(index).text == '123456789.0\n', |
|
411 | 411 | 'Long float textbox value set (probably triggers throttling).'); |
|
412 | 412 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); |
|
413 | 413 | this.sendKeys(float_text_query_2, '12hello'); |
|
414 | 414 | }); |
|
415 | 415 | |
|
416 | 416 | this.wait(500); // Wait for change to execute in kernel |
|
417 | 417 | |
|
418 | 418 | index = this.append_cell('print(float_widget.value)\n'); |
|
419 | 419 | this.execute_cell_then(index, function(index){ |
|
420 | 420 | this.test.assert(this.get_output_cell(index).text == '12.0\n', |
|
421 | 421 | 'Invald float textbox value caught and filtered.'); |
|
422 | 422 | }); |
|
423 | 423 | |
|
424 | 424 | // Test image widget /////////////////////////////////////////////////////// |
|
425 | 425 | |
|
426 | 426 | // Get the temporary directory that the test server is running in. |
|
427 | 427 | var cwd = ''; |
|
428 | 428 | index = this.append_cell('!echo $(pwd)'); |
|
429 | 429 | this.execute_cell_then(index, function(index){ |
|
430 | 430 | cwd = this.get_output_cell(index).text.trim(); |
|
431 | 431 | }); |
|
432 | 432 | |
|
433 | 433 | test_jpg = '/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDACAWGBwYFCAcGhwkIiAmMFA0MCwsMGJGSjpQdGZ6eHJmcG6AkLicgIiuim5woNqirr7EztDOfJri8uDI8LjKzsb/2wBDASIkJDAqMF40NF7GhHCExsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsb/wgARCAABAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAAA//EABUBAQEAAAAAAAAAAAAAAAAAAAME/9oADAMBAAIQAxAAAAECv//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAQUCf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEABj8Cf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hf//aAAwDAQACAAMAAAAQn//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8Qf//Z'; |
|
434 | 434 | test_results = '/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAyADIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDi6KKK+ZP3EKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA//Z'; |
|
435 | 435 | |
|
436 | 436 | var image_index = this.append_cell( |
|
437 | 437 | 'import base64\n' + |
|
438 | 438 | 'data = base64.b64decode("' + test_jpg + '")\n' + |
|
439 | 439 | 'image = widgets.ImageWidget()\n' + |
|
440 | 440 | 'image.image_format = "jpeg"\n' + |
|
441 | 441 | 'image.value = data\n' + |
|
442 | 442 | 'image.width = "50px"\n' + |
|
443 | 443 | 'image.height = "50px"\n' + |
|
444 | 444 | // Set css that will make the image render within the PhantomJS visible |
|
445 | 445 | // window. If we don't do this, the captured image will be black. |
|
446 | 446 | 'image.set_css({"background": "blue", "z-index": "9999", "position": "fixed", "top": "0px", "left": "0px"})\n' + |
|
447 | 447 | 'display(image)\n' + |
|
448 | 448 | 'image.add_class("my-test-image")\n' + |
|
449 | 449 | 'print("Success")\n'); |
|
450 | 450 | this.execute_cell_then(image_index, function(index){ |
|
451 | 451 | |
|
452 | 452 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
453 | 453 | 'Create image executed with correct output.'); |
|
454 | 454 | |
|
455 | 455 | this.test.assert(this.cell_element_exists(index, |
|
456 | 456 | '.widget-area .widget-subarea'), |
|
457 | 457 | 'Widget subarea exists.'); |
|
458 | 458 | |
|
459 | 459 | this.test.assert(this.cell_element_exists(index, |
|
460 | 460 | '.widget-area .widget-subarea img'), |
|
461 | 461 | 'Image exists.'); |
|
462 | 462 | |
|
463 | 463 | // Capture a screenshot of the img element as a base64 string. |
|
464 | 464 | var fs = require('fs'); |
|
465 | 465 | capture_filename = cwd + fs.separator + 'captured.jpg'; |
|
466 | 466 | this.captureSelector(capture_filename, '.my-test-image'); |
|
467 | 467 | var stream = fs.open(capture_filename, 'rb'); |
|
468 | 468 | var captured = btoa(stream.read()); |
|
469 | 469 | stream.close() |
|
470 | 470 | fs.remove(capture_filename); |
|
471 | 471 | |
|
472 | 472 | // Uncomment line below to output captured image data to a text file. |
|
473 | 473 | // fs.write('./captured.txt', captured, 'w'); |
|
474 | 474 | |
|
475 | 475 | this.test.assert(test_results==captured, "Red image data displayed correctly."); |
|
476 | 476 | }); |
|
477 | 477 | |
|
478 | 478 | // Test int range widget ///////////////////////////////////////////////// |
|
479 | 479 | var int_text_query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text'; |
|
480 | 480 | |
|
481 | 481 | var intrange_index = this.append_cell( |
|
482 | 482 | 'intrange = widgets.IntRangeWidget()\n' + |
|
483 | 483 | 'display(intrange, view_name="IntTextView")\n' + |
|
484 | 484 | 'intrange.add_class("my-second-num-test-text")\n' + |
|
485 | 485 | 'display(intrange)\n' + |
|
486 | 486 | 'print("Success")\n'); |
|
487 | 487 | this.execute_cell_then(intrange_index, function(index){ |
|
488 | 488 | |
|
489 | 489 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
490 | 490 | 'Create int range cell executed with correct output.'); |
|
491 | 491 | |
|
492 | 492 | this.test.assert(this.cell_element_exists(index, |
|
493 | 493 | '.widget-area .widget-subarea'), |
|
494 | 494 | 'Widget subarea exists.'); |
|
495 | 495 | |
|
496 | 496 | this.test.assert(this.cell_element_exists(index, slider_query), |
|
497 | 497 | 'Widget slider exists.'); |
|
498 | 498 | |
|
499 | 499 | this.test.assert(this.cell_element_exists(index, int_text_query), |
|
500 | 500 | 'Widget int textbox exists.'); |
|
501 | 501 | }); |
|
502 | 502 | |
|
503 | 503 | index = this.append_cell( |
|
504 | 504 | 'intrange.max = 50\n' + |
|
505 | 505 | 'intrange.min = -50\n' + |
|
506 | 506 | 'intrange.value = 25\n' + |
|
507 | 507 | 'print("Success")\n'); |
|
508 | 508 | this.execute_cell_then(index, function(index){ |
|
509 | 509 | |
|
510 | 510 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
511 | 511 | 'Int range properties cell executed with correct output.'); |
|
512 | 512 | |
|
513 | 513 | this.test.assert(this.cell_element_exists(intrange_index, slider_query), |
|
514 | 514 | 'Widget slider exists.'); |
|
515 | 515 | |
|
516 | 516 | this.test.assert(this.cell_element_function(intrange_index, slider_query, |
|
517 | 517 | 'slider', ['value']) == 25, |
|
518 | 518 | 'Slider set to Python value.'); |
|
519 | 519 | |
|
520 | 520 | this.test.assert(this.cell_element_function(intrange_index, int_text_query, |
|
521 | 521 | 'val') == 25, 'Int textbox set to Python value.'); |
|
522 | 522 | |
|
523 | 523 | // Clear the int textbox value and then set it to 1 by emulating |
|
524 | 524 | // keyboard presses. |
|
525 | 525 | this.cell_element_function(intrange_index, int_text_query, 'val', ['']); |
|
526 | 526 | this.sendKeys(int_text_query, '1'); |
|
527 | 527 | }); |
|
528 | 528 | |
|
529 | 529 | this.wait(500); // Wait for change to execute in kernel |
|
530 | 530 | |
|
531 | 531 | index = this.append_cell('print(intrange.value)\n'); |
|
532 | 532 | this.execute_cell_then(index, function(index){ |
|
533 | 533 | this.test.assert(this.get_output_cell(index).text == '1\n', |
|
534 | 534 | 'Int textbox set int range value'); |
|
535 | 535 | |
|
536 | 536 | // Clear the int textbox value and then set it to 120 by emulating |
|
537 | 537 | // keyboard presses. |
|
538 | 538 | this.cell_element_function(intrange_index, int_text_query, 'val', ['']); |
|
539 | 539 | this.sendKeys(int_text_query, '120'); |
|
540 | 540 | }); |
|
541 | 541 | |
|
542 | 542 | this.wait(500); // Wait for change to execute in kernel |
|
543 | 543 | |
|
544 | 544 | index = this.append_cell('print(intrange.value)\n'); |
|
545 | 545 | this.execute_cell_then(index, function(index){ |
|
546 | 546 | this.test.assert(this.get_output_cell(index).text == '50\n', |
|
547 | 547 | 'Int textbox value bound'); |
|
548 | 548 | |
|
549 | 549 | // Clear the int textbox value and then set it to 'hello world' by |
|
550 | 550 | // emulating keyboard presses. 'hello world' should get filtered... |
|
551 | 551 | this.cell_element_function(intrange_index, int_text_query, 'val', ['']); |
|
552 | 552 | this.sendKeys(int_text_query, 'hello world'); |
|
553 | 553 | }); |
|
554 | 554 | |
|
555 | 555 | this.wait(500); // Wait for change to execute in kernel |
|
556 | 556 | |
|
557 | 557 | index = this.append_cell('print(intrange.value)\n'); |
|
558 | 558 | this.execute_cell_then(index, function(index){ |
|
559 | 559 | this.test.assert(this.get_output_cell(index).text == '50\n', |
|
560 | 560 | 'Invalid int textbox characters ignored'); |
|
561 | 561 | }); |
|
562 | 562 | |
|
563 | 563 | // Test int widget /////////////////////////////////////////////////////// |
|
564 | 564 | var int_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text'; |
|
565 | 565 | |
|
566 | 566 | var int_index = this.append_cell( |
|
567 | 567 | 'int_widget = widgets.IntWidget()\n' + |
|
568 | 568 | 'display(int_widget)\n' + |
|
569 | 569 | 'int_widget.add_class("my-second-int-text")\n' + |
|
570 | 570 | 'print("Success")\n'); |
|
571 | 571 | this.execute_cell_then(int_index, function(index){ |
|
572 | 572 | |
|
573 | 573 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
574 | 574 | 'Create int cell executed with correct output.'); |
|
575 | 575 | |
|
576 | 576 | this.test.assert(this.cell_element_exists(index, |
|
577 | 577 | '.widget-area .widget-subarea'), |
|
578 | 578 | 'Widget subarea exists.'); |
|
579 | 579 | |
|
580 | 580 | this.test.assert(this.cell_element_exists(index, int_text_query_2), |
|
581 | 581 | 'Widget int textbox exists.'); |
|
582 | 582 | |
|
583 | 583 | this.cell_element_function(int_index, int_text_query_2, 'val', ['']); |
|
584 | 584 | this.sendKeys(int_text_query_2, '1.05'); |
|
585 | 585 | }); |
|
586 | 586 | |
|
587 | 587 | this.wait(500); // Wait for change to execute in kernel |
|
588 | 588 | |
|
589 | 589 | index = this.append_cell('print(int_widget.value)\n'); |
|
590 | 590 | this.execute_cell_then(index, function(index){ |
|
591 | 591 | this.test.assert(this.get_output_cell(index).text == '1\n', |
|
592 | 592 | 'Int textbox value set.'); |
|
593 | 593 | this.cell_element_function(int_index, int_text_query_2, 'val', ['']); |
|
594 | 594 | this.sendKeys(int_text_query_2, '123456789'); |
|
595 | 595 | }); |
|
596 | 596 | |
|
597 | 597 | this.wait(500); // Wait for change to execute in kernel |
|
598 | 598 | |
|
599 | 599 | index = this.append_cell('print(int_widget.value)\n'); |
|
600 | 600 | this.execute_cell_then(index, function(index){ |
|
601 | 601 | this.test.assert(this.get_output_cell(index).text == '123456789\n', |
|
602 | 602 | 'Long int textbox value set (probably triggers throttling).'); |
|
603 | 603 | this.cell_element_function(int_index, int_text_query_2, 'val', ['']); |
|
604 | 604 | this.sendKeys(int_text_query_2, '12hello'); |
|
605 | 605 | }); |
|
606 | 606 | |
|
607 | 607 | this.wait(500); // Wait for change to execute in kernel |
|
608 | 608 | |
|
609 | 609 | index = this.append_cell('print(int_widget.value)\n'); |
|
610 | 610 | this.execute_cell_then(index, function(index){ |
|
611 | 611 | this.test.assert(this.get_output_cell(index).text == '12\n', |
|
612 | 612 | 'Invald int textbox value caught and filtered.'); |
|
613 | 613 | }); |
|
614 | 614 | |
|
615 | 615 | |
|
616 | 616 | // Test multicontainer widget //////////////////////////////////////////// |
|
617 | 617 | |
|
618 | 618 | // Test tab view |
|
619 | 619 | var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs'; |
|
620 | 620 | var multicontainer1_index = this.append_cell( |
|
621 | 621 | 'multicontainer = widgets.MulticontainerWidget()\n' + |
|
622 | 622 | 'page1 = widgets.StringWidget(parent=multicontainer)\n' + |
|
623 | 623 | 'page2 = widgets.StringWidget(parent=multicontainer)\n' + |
|
624 | 624 | 'page3 = widgets.StringWidget(parent=multicontainer)\n' + |
|
625 | 625 | 'display(multicontainer)\n' + |
|
626 | 626 | 'multicontainer.selected_index = 0\n' + |
|
627 | 627 | 'print("Success")\n'); |
|
628 | 628 | this.execute_cell_then(multicontainer1_index, function(index){ |
|
629 | 629 | |
|
630 | 630 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
631 | 631 | 'Create multicontainer cell executed with correct output. (1)'); |
|
632 | 632 | |
|
633 | 633 | this.test.assert(this.cell_element_exists(index, |
|
634 | 634 | '.widget-area .widget-subarea'), |
|
635 | 635 | 'Widget subarea exists.'); |
|
636 | 636 | |
|
637 | 637 | this.test.assert(this.cell_element_exists(index, multicontainer1_query), |
|
638 | 638 | 'Widget tab list exists.'); |
|
639 | 639 | |
|
640 | 640 | this.test.assert(this.cell_element_exists(index, multicontainer1_query), |
|
641 | 641 | 'First widget tab list exists.'); |
|
642 | 642 | |
|
643 | 643 | // JQuery selector is 1 based |
|
644 | 644 | this.click(multicontainer1_query + ' li:nth-child(2) a') |
|
645 | 645 | }); |
|
646 | 646 | |
|
647 | 647 | this.wait(500); // Wait for change to execute in kernel |
|
648 | 648 | |
|
649 | 649 | index = this.append_cell( |
|
650 | 650 | 'print(multicontainer.selected_index)\n' + |
|
651 | 651 | 'multicontainer.selected_index = 2'); // 0 based |
|
652 | 652 | this.execute_cell_then(index, function(index){ |
|
653 | 653 | this.test.assert(this.get_output_cell(index).text == '1\n', // 0 based |
|
654 | 654 | 'selected_index property updated with tab change.'); |
|
655 | 655 | |
|
656 | 656 | // JQuery selector is 1 based |
|
657 | 657 | this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(1)', 'hasClass', ['active']), |
|
658 | 658 | "Tab 1 is not selected.") |
|
659 | 659 | this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(2)', 'hasClass', ['active']), |
|
660 | 660 | "Tab 2 is not selected.") |
|
661 | 661 | this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(3)', 'hasClass', ['active']), |
|
662 | 662 | "Tab 3 is selected.") |
|
663 | 663 | }); |
|
664 | 664 | |
|
665 | 665 | index = this.append_cell('multicontainer.set_title(1, "hello")\nprint("Success")'); // 0 based |
|
666 | 666 | this.execute_cell_then(index, function(index){ |
|
667 | 667 | this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + |
|
668 | 668 | ' li:nth-child(2) a', 'html') == 'hello', |
|
669 | 669 | 'Tab page title set (after display).'); |
|
670 | 670 | }); |
|
671 | 671 | |
|
672 | 672 | // Test accordion view |
|
673 | 673 | var multicontainer2_query = '.widget-area .widget-subarea .accordion'; |
|
674 | 674 | var multicontainer2_index = this.append_cell( |
|
675 | 675 | 'multicontainer = widgets.MulticontainerWidget()\n' + |
|
676 | 676 | 'page1 = widgets.StringWidget(parent=multicontainer)\n' + |
|
677 | 677 | 'page2 = widgets.StringWidget(parent=multicontainer)\n' + |
|
678 | 678 | 'page3 = widgets.StringWidget(parent=multicontainer)\n' + |
|
679 | 679 | 'multicontainer.set_title(2, "good")\n' + |
|
680 | 680 | 'display(multicontainer, view_name="AccordionView")\n' + |
|
681 | 681 | 'multicontainer.selected_index = 0\n' + |
|
682 | 682 | 'print("Success")\n'); |
|
683 | 683 | this.execute_cell_then(multicontainer2_index, function(index){ |
|
684 | 684 | |
|
685 | 685 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
686 | 686 | 'Create multicontainer cell executed with correct output. (2)'); |
|
687 | 687 | |
|
688 | 688 | this.test.assert(this.cell_element_exists(index, |
|
689 | 689 | '.widget-area .widget-subarea'), |
|
690 | 690 | 'Widget subarea exists.'); |
|
691 | 691 | |
|
692 | 692 | this.test.assert(this.cell_element_exists(index, multicontainer2_query), |
|
693 | 693 | 'Widget accordion exists.'); |
|
694 | 694 | |
|
695 | 695 | this.test.assert(this.cell_element_exists(index, multicontainer2_query + |
|
696 | 696 | ' .accordion-group:nth-child(1) .accordion-body'), |
|
697 | 697 | 'First accordion page exists.'); |
|
698 | 698 | |
|
699 | 699 | // JQuery selector is 1 based |
|
700 | 700 | this.test.assert(this.cell_element_function(index, multicontainer2_query + |
|
701 | 701 | ' .accordion-group:nth-child(3) .accordion-heading .accordion-toggle', |
|
702 | 702 | 'html')=='good', 'Accordion page title set (before display).'); |
|
703 | 703 | |
|
704 | 704 | // JQuery selector is 1 based |
|
705 | 705 | this.click(multicontainer2_query + ' .accordion-group:nth-child(2) .accordion-heading .accordion-toggle'); |
|
706 | 706 | }); |
|
707 | 707 | |
|
708 | 708 | this.wait(500); // Wait for change to execute in kernel |
|
709 | 709 | |
|
710 | 710 | index = this.append_cell('print(multicontainer.selected_index)'); // 0 based |
|
711 | 711 | this.execute_cell_then(index, function(index){ |
|
712 | 712 | this.test.assert(this.get_output_cell(index).text == '1\n', // 0 based |
|
713 | 713 | 'selected_index property updated with tab change.'); |
|
714 | 714 | }); |
|
715 | 715 | |
|
716 | 716 | // Test selection widget ///////////////////////////////////////////////// |
|
717 | 717 | var combo_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group .widget-combo-btn' |
|
718 | 718 | var multibtn_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group[data-toggle="buttons-radio"]' |
|
719 | 719 | var radio_selector = '.widget-area .widget-subarea .widget-hbox .vbox' |
|
720 | 720 | var list_selector = '.widget-area .widget-subarea .widget-hbox .widget-listbox' |
|
721 | 721 | |
|
722 | 722 | var selection_index; |
|
723 | 723 | var selection_values = 'abcd'; |
|
724 | 724 | var check_state = function(context, index, state){ |
|
725 | 725 | if (0 <= index && index < selection_values.length) { |
|
726 | 726 | var multibtn_state = context.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(' + (index + 1) + ')', 'hasClass', ['active']); |
|
727 | 727 | var radio_state = context.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(' + (index + 1) + ') input', 'prop', ['checked']); |
|
728 | 728 | var list_val = context.cell_element_function(selection_index, list_selector, 'val'); |
|
729 | 729 | var combo_val = context.cell_element_function(selection_index, combo_selector, 'html'); |
|
730 | 730 | |
|
731 | 731 | var val = selection_values.charAt(index); |
|
732 | 732 | var list_state = (val == list_val); |
|
733 | 733 | var combo_state = (val == combo_val); |
|
734 | 734 | |
|
735 | 735 | return multibtn_state == state && |
|
736 | 736 | radio_state == state && |
|
737 | 737 | list_state == state && |
|
738 | 738 | combo_state == state; |
|
739 | 739 | } |
|
740 | 740 | return true; |
|
741 | 741 | } |
|
742 | 742 | |
|
743 | 743 | var verify_selection = function(context, index){ |
|
744 | 744 | for (var i = 0; i < selection_values.length; i++) { |
|
745 | 745 | if (!check_state(context, i, i==index)) { |
|
746 | 746 | return false; |
|
747 | 747 | } |
|
748 | 748 | } |
|
749 | 749 | return true; |
|
750 | 750 | } |
|
751 | 751 | |
|
752 | 752 | selection_index = this.append_cell( |
|
753 | 753 | 'selection = widgets.SelectionWidget(values=["' + selection_values + '"[i] for i in range(4)])\n' + |
|
754 | 754 | 'display(selection)\n' + |
|
755 | 755 | 'display(selection, view_name="ToggleButtonsView")\n' + |
|
756 | 756 | 'display(selection, view_name="RadioButtonsView")\n' + |
|
757 | 757 | 'display(selection, view_name="ListBoxView")\n' + |
|
758 | 758 | 'print("Success")\n'); |
|
759 | 759 | this.execute_cell_then(selection_index, function(index){ |
|
760 | 760 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
761 | 761 | 'Create selection cell executed with correct output.'); |
|
762 | 762 | |
|
763 | 763 | this.test.assert(this.cell_element_exists(index, |
|
764 | 764 | '.widget-area .widget-subarea'), |
|
765 | 765 | 'Widget subarea exists.'); |
|
766 | 766 | |
|
767 | 767 | this.test.assert(this.cell_element_exists(index, combo_selector), |
|
768 | 768 | 'Widget combobox exists.'); |
|
769 | 769 | |
|
770 | 770 | this.test.assert(this.cell_element_exists(index, multibtn_selector), |
|
771 | 771 | 'Widget multibutton exists.'); |
|
772 | 772 | |
|
773 | 773 | this.test.assert(this.cell_element_exists(index, radio_selector), |
|
774 | 774 | 'Widget radio buttons exists.'); |
|
775 | 775 | |
|
776 | 776 | this.test.assert(this.cell_element_exists(index, list_selector), |
|
777 | 777 | 'Widget list exists.'); |
|
778 | 778 | |
|
779 | 779 | // Verify that no items are selected. |
|
780 | 780 | this.test.assert(verify_selection(this, -1), 'No items selected.'); |
|
781 | 781 | }); |
|
782 | 782 | |
|
783 | 783 | index = this.append_cell( |
|
784 | 784 | 'selection.value = "a"\n' + |
|
785 | 785 | 'print("Success")\n'); |
|
786 | 786 | this.execute_cell_then(index, function(index){ |
|
787 | 787 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
788 | 788 | 'Python select item executed with correct output.'); |
|
789 | 789 | |
|
790 | 790 | // Verify that the first item is selected. |
|
791 | 791 | this.test.assert(verify_selection(this, 0), 'Python selected'); |
|
792 | 792 | |
|
793 | 793 | // Verify that selecting a radio button updates all of the others. |
|
794 | 794 | this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click'); |
|
795 | 795 | this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.'); |
|
796 | 796 | |
|
797 | 797 | // Verify that selecting a list option updates all of the others. |
|
798 | 798 | this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click'); |
|
799 | 799 | this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.'); |
|
800 | 800 | |
|
801 | 801 | // Verify that selecting a multibutton option updates all of the others. |
|
802 | 802 | this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click'); |
|
803 | 803 | this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.'); |
|
804 | 804 | |
|
805 | 805 | // Verify that selecting a combobox option updates all of the others. |
|
806 | 806 | this.cell_element_function(selection_index, '.widget-area .widget-subarea .widget-hbox-single .btn-group ul.dropdown-menu li:nth-child(3) a', 'click'); |
|
807 | 807 | this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.'); |
|
808 | 808 | }); |
|
809 | 809 | |
|
810 | 810 | this.wait(500); // Wait for change to execute in kernel |
|
811 | 811 | |
|
812 | 812 | index = this.append_cell( |
|
813 | 813 | 'print(selection.value)\n' + |
|
814 | 814 | 'selection.values.append("z")\n' + |
|
815 | 815 | 'selection.send_state()\n' + |
|
816 | 816 | 'selection.value = "z"'); |
|
817 | 817 | this.execute_cell_then(index, function(index){ |
|
818 | 818 | |
|
819 | 819 | // Verify that selecting a combobox option updates all of the others. |
|
820 | 820 | this.test.assert(verify_selection(this, 4), 'Item added to selection widget.'); |
|
821 | 821 | }); |
|
822 | 822 | |
|
823 | // Test string widget ////////////////////////////////////////////////////// | |
|
824 | var string_index = this.append_cell( | |
|
825 | 'string_widget = widgets.StringWidget()\n' + | |
|
826 | 'display(string_widget)\n'+ | |
|
827 | 'display(string_widget, view_name="TextAreaView")\n' + | |
|
828 | 'display(string_widget, view_name="HTMLView")\n' + | |
|
829 | 'display(string_widget, view_name="LatexView")\n' + | |
|
830 | 'string_widget.value = "xyz"\n' + | |
|
831 | 'print("Success")'); | |
|
832 | this.execute_cell_then(string_index, function(index){ | |
|
833 | ||
|
834 | this.test.assert(this.get_output_cell(index).text == 'Success\n', | |
|
835 | 'Create string widget cell executed with correct output.'); | |
|
836 | ||
|
837 | this.test.assert(this.cell_element_exists(index, | |
|
838 | '.widget-area .widget-subarea'), | |
|
839 | 'Widget subarea exists.'); | |
|
840 | ||
|
841 | this.test.assert(this.cell_element_exists(index, | |
|
842 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]'), | |
|
843 | 'Textbox exists.'); | |
|
844 | ||
|
845 | this.test.assert(this.cell_element_exists(index, | |
|
846 | '.widget-area .widget-subarea .widget-hbox textarea'), | |
|
847 | 'Textarea exists.'); | |
|
848 | ||
|
849 | this.test.assert(this.cell_element_function(index, | |
|
850 | '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='xyz', | |
|
851 | 'Python set textarea value.'); | |
|
852 | ||
|
853 | this.test.assert(this.cell_element_function(index, | |
|
854 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='xyz', | |
|
855 | 'Python set textbox value.'); | |
|
856 | ||
|
857 | this.cell_element_function(index, | |
|
858 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val', ['']) | |
|
859 | this.sendKeys('.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'abc'); | |
|
860 | ||
|
861 | this.test.assert(this.cell_element_function(index, | |
|
862 | '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='abc', | |
|
863 | 'Textarea updated to textbox contents.'); | |
|
864 | ||
|
865 | this.cell_element_function(index, | |
|
866 | '.widget-area .widget-subarea .widget-hbox textarea', 'val', ['']); | |
|
867 | this.sendKeys('.widget-area .widget-subarea .widget-hbox textarea', '$\\LaTeX{}$'); | |
|
868 | ||
|
869 | this.test.assert(this.cell_element_function(index, | |
|
870 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='$\\LaTeX{}$', | |
|
871 | 'Textbox updated to textarea contents.'); | |
|
872 | }); | |
|
873 | ||
|
874 | this.wait(500); // Wait for change to execute in kernel | |
|
875 | ||
|
876 | index = this.append_cell('print(string_widget.value)'); | |
|
877 | this.execute_cell_then(index, function(index){ | |
|
878 | this.test.assert(this.get_output_cell(index).text == '$\\LaTeX{}$\n', | |
|
879 | 'Python updated with correct string widget value.'); | |
|
880 | ||
|
881 | this.test.assert(this.cell_element_exists(string_index, | |
|
882 | '.widget-area .widget-subarea div span.MathJax_Preview'), | |
|
883 | 'MathJax parsed the LaTeX successfully.'); | |
|
884 | }); | |
|
823 | 885 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now