##// END OF EJS Templates
Added int range and int widget tests.
Jonathan Frederic -
Show More
@@ -1,480 +1,614 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 var int_text_query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
480
481 var intrange_index = this.append_cell(
482 'intrange = widgets.IntRangeWidget()\n' +
483 'display(intrange, view_name="IntTextView")\n' +
484 'intrange.add_class("my-second-num-test-text")\n' +
485 'display(intrange)\n' +
486 'print("Success")\n');
487 this.execute_cell_then(intrange_index, function(index){
488
489 this.test.assert(this.get_output_cell(index).text == 'Success\n',
490 'Create int range cell executed with correct output.');
491
492 this.test.assert(this.cell_element_exists(index,
493 '.widget-area .widget-subarea'),
494 'Widget subarea exists.');
495
496 this.test.assert(this.cell_element_exists(index, slider_query),
497 'Widget slider exists.');
498
499 this.test.assert(this.cell_element_exists(index, int_text_query),
500 'Widget int textbox exists.');
501 });
502
503 index = this.append_cell(
504 'intrange.max = 50\n' +
505 'intrange.min = -50\n' +
506 'intrange.value = 25\n' +
507 'print("Success")\n');
508 this.execute_cell_then(index, function(index){
509
510 this.test.assert(this.get_output_cell(index).text == 'Success\n',
511 'Int range properties cell executed with correct output.');
512
513 this.test.assert(this.cell_element_exists(intrange_index, slider_query),
514 'Widget slider exists.');
515
516 this.test.assert(this.cell_element_function(intrange_index, slider_query,
517 'slider', ['value']) == 25,
518 'Slider set to Python value.');
519
520 this.test.assert(this.cell_element_function(intrange_index, int_text_query,
521 'val') == 25, 'Int textbox set to Python value.');
522
523 // Clear the int textbox value and then set it to 1 by emulating
524 // keyboard presses.
525 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
526 this.sendKeys(int_text_query, '1');
527 });
528
529 this.wait(500); // Wait for change to execute in kernel
530
531 index = this.append_cell('print(intrange.value)\n');
532 this.execute_cell_then(index, function(index){
533 this.test.assert(this.get_output_cell(index).text == '1\n',
534 'Int textbox set int range value');
535
536 // Clear the int textbox value and then set it to 120 by emulating
537 // keyboard presses.
538 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
539 this.sendKeys(int_text_query, '120');
540 });
541
542 this.wait(500); // Wait for change to execute in kernel
479 543
544 index = this.append_cell('print(intrange.value)\n');
545 this.execute_cell_then(index, function(index){
546 this.test.assert(this.get_output_cell(index).text == '50\n',
547 'Int textbox value bound');
548
549 // Clear the int textbox value and then set it to 'hello world' by
550 // emulating keyboard presses. 'hello world' should get filtered...
551 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
552 this.sendKeys(int_text_query, 'hello world');
553 });
554
555 this.wait(500); // Wait for change to execute in kernel
556
557 index = this.append_cell('print(intrange.value)\n');
558 this.execute_cell_then(index, function(index){
559 this.test.assert(this.get_output_cell(index).text == '50\n',
560 'Invalid int textbox characters ignored');
561 });
562
563 // Test int widget ///////////////////////////////////////////////////////
564 var int_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
565
566 var int_index = this.append_cell(
567 'int_widget = widgets.IntWidget()\n' +
568 'display(int_widget)\n' +
569 'int_widget.add_class("my-second-int-text")\n' +
570 'print("Success")\n');
571 this.execute_cell_then(int_index, function(index){
572
573 this.test.assert(this.get_output_cell(index).text == 'Success\n',
574 'Create int cell executed with correct output.');
575
576 this.test.assert(this.cell_element_exists(index,
577 '.widget-area .widget-subarea'),
578 'Widget subarea exists.');
480 579
580 this.test.assert(this.cell_element_exists(index, int_text_query_2),
581 'Widget int textbox exists.');
582
583 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
584 this.sendKeys(int_text_query_2, '1.05');
585 });
586
587 this.wait(500); // Wait for change to execute in kernel
588
589 index = this.append_cell('print(int_widget.value)\n');
590 this.execute_cell_then(index, function(index){
591 this.test.assert(this.get_output_cell(index).text == '1\n',
592 'Int textbox value set.');
593 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
594 this.sendKeys(int_text_query_2, '123456789');
595 });
596
597 this.wait(500); // Wait for change to execute in kernel
598
599 index = this.append_cell('print(int_widget.value)\n');
600 this.execute_cell_then(index, function(index){
601 this.test.assert(this.get_output_cell(index).text == '123456789\n',
602 'Long int textbox value set (probably triggers throttling).');
603 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
604 this.sendKeys(int_text_query_2, '12hello');
605 });
606
607 this.wait(500); // Wait for change to execute in kernel
608
609 index = this.append_cell('print(int_widget.value)\n');
610 this.execute_cell_then(index, function(index){
611 this.test.assert(this.get_output_cell(index).text == '12\n',
612 'Invald int textbox value caught and filtered.');
613 });
614 });
General Comments 0
You need to be logged in to leave comments. Login now