widget_float.js
108 lines
| 4.3 KiB
| application/javascript
|
JavascriptLexer
|
r14464 | // Test widget float class | |
casper.notebook_test(function () { | |||
|
r14970 | var float_text = {}; | |
|
r17731 | float_text.query = '.widget-area .widget-subarea .my-second-float-text input'; | |
|
r14970 | float_text.index = this.append_cell( | |
|
r18910 | 'from IPython.html import widgets\n' + | |
'from IPython.display import display, clear_output\n' + | |||
|
r17598 | 'float_widget = widgets.FloatText()\n' + | |
|
r14464 | 'display(float_widget)\n' + | |
|
r17721 | 'float_widget._dom_classes = ["my-second-float-text"]\n' + | |
|
r14970 | 'print(float_widget.model_id)\n'); | |
this.execute_cell_then(float_text.index, function(index){ | |||
float_text.model_id = this.get_output_cell(index).text.trim(); | |||
|
r18910 | }); | |
// Wait for the widget to actually display. | |||
this.wait_for_element(float_text.index, float_text.query); | |||
// Continue with the tests | |||
this.then(function(){ | |||
this.test.assert(this.cell_element_exists(float_text.index, | |||
|
r14464 | '.widget-area .widget-subarea'), | |
'Widget subarea exists.'); | |||
|
r18910 | this.test.assert(this.cell_element_exists(float_text.index, float_text.query), | |
|
r14464 | 'Widget float textbox exists.'); | |
|
r14970 | this.cell_element_function(float_text.index, float_text.query, 'val', ['']); | |
|
r18910 | console.log('send keys'); | |
|
r14970 | this.sendKeys(float_text.query, '1.05'); | |
|
r18910 | console.log('send keys done'); | |
|
r14464 | }); | |
|
r14970 | this.wait_for_widget(float_text); | |
|
r14464 | ||
index = this.append_cell('print(float_widget.value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '1.05\n', | |
|
r14464 | 'Float textbox value set.'); | |
|
r14970 | this.cell_element_function(float_text.index, float_text.query, 'val', ['']); | |
this.sendKeys(float_text.query, '123456789.0'); | |||
|
r14464 | }); | |
|
r14970 | this.wait_for_widget(float_text); | |
|
r14464 | index = this.append_cell('print(float_widget.value)\n'); | |
this.execute_cell_then(index, function(index){ | |||
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '123456789.0\n', | |
|
r14464 | 'Long float textbox value set (probably triggers throttling).'); | |
|
r14970 | this.cell_element_function(float_text.index, float_text.query, 'val', ['']); | |
this.sendKeys(float_text.query, '12hello'); | |||
|
r14464 | }); | |
|
r14970 | this.wait_for_widget(float_text); | |
|
r14464 | ||
index = this.append_cell('print(float_widget.value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '12.0\n', | |
|
r14464 | 'Invald float textbox value caught and filtered.'); | |
}); | |||
|
r14674 | ||
|
r17731 | var float_text_query = '.widget-area .widget-subarea .widget-numeric-text'; | |
|
r14970 | var slider = {}; | |
|
r17731 | slider.query = '.widget-area .widget-subarea .slider'; | |
|
r14970 | slider.index = this.append_cell( | |
|
r17598 | 'floatrange = [widgets.BoundedFloatText(), \n' + | |
' widgets.FloatSlider()]\n' + | |||
|
r14674 | '[display(floatrange[i]) for i in range(2)]\n' + | |
'print("Success")\n'); | |||
|
r14970 | this.execute_cell_then(slider.index, function(index){ | |
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
|
r14674 | 'Create float range cell executed with correct output.'); | |
|
r18910 | }); | |
// Wait for the widgets to actually display. | |||
this.wait_for_element(slider.index, slider.query); | |||
this.wait_for_element(slider.index, float_text_query); | |||
|
r14674 | ||
|
r18910 | this.then(function(){ | |
this.test.assert(this.cell_element_exists(slider.index, | |||
|
r14674 | '.widget-area .widget-subarea'), | |
'Widget subarea exists.'); | |||
|
r18910 | this.test.assert(this.cell_element_exists(slider.index, slider.query), | |
|
r14674 | 'Widget slider exists.'); | |
|
r18910 | this.test.assert(this.cell_element_exists(slider.index, float_text_query), | |
|
r14674 | 'Widget float textbox exists.'); | |
}); | |||
index = this.append_cell( | |||
'for widget in floatrange:\n' + | |||
' widget.max = 50.0\n' + | |||
' widget.min = -50.0\n' + | |||
|
r14690 | ' widget.value = 25.0\n' + | |
|
r14674 | 'print("Success")\n'); | |
this.execute_cell_then(index, function(index){ | |||
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
|
r14674 | 'Float range properties cell executed with correct output.'); | |
|
r14970 | this.test.assert(this.cell_element_exists(slider.index, slider.query), | |
|
r14674 | 'Widget slider exists.'); | |
|
r14970 | this.test.assert(this.cell_element_function(slider.index, slider.query, | |
|
r14690 | 'slider', ['value']) == 25.0, | |
|
r14674 | 'Slider set to Python value.'); | |
}); | |||
|
r14464 | }); |