widget_int.js
176 lines
| 6.7 KiB
| application/javascript
|
JavascriptLexer
Jonathan Frederic
|
r14464 | // Test widget int class | |
casper.notebook_test(function () { | |||
Jonathan Frederic
|
r17472 | var int_text = {}; | |
Jonathan Frederic
|
r17731 | int_text.query = '.widget-area .widget-subarea .my-second-int-text input'; | |
Jonathan Frederic
|
r14970 | int_text.index = this.append_cell( | |
Jonathan Frederic
|
r18910 | 'from IPython.html import widgets\n' + | |
'from IPython.display import display, clear_output\n' + | |||
Jonathan Frederic
|
r17598 | 'int_widget = widgets.IntText()\n' + | |
Jonathan Frederic
|
r14464 | 'display(int_widget)\n' + | |
Jonathan Frederic
|
r17721 | 'int_widget._dom_classes = ["my-second-int-text"]\n' + | |
Jonathan Frederic
|
r14970 | 'print(int_widget.model_id)\n'); | |
this.execute_cell_then(int_text.index, function(index){ | |||
int_text.model_id = this.get_output_cell(index).text.trim(); | |||
Jonathan Frederic
|
r18910 | }); | |
// Wait for the widget to actually display. | |||
this.wait_for_element(int_text.index, int_text.query); | |||
// Continue with the tests. | |||
this.then(function() { | |||
this.test.assert(this.cell_element_exists(int_text.index, | |||
Jonathan Frederic
|
r14464 | '.widget-area .widget-subarea'), | |
'Widget subarea exists.'); | |||
Jonathan Frederic
|
r18910 | this.test.assert(this.cell_element_exists(int_text.index, int_text.query), | |
Jonathan Frederic
|
r14464 | 'Widget int textbox exists.'); | |
Jonathan Frederic
|
r14970 | this.cell_element_function(int_text.index, int_text.query, 'val', ['']); | |
this.sendKeys(int_text.query, '1.05'); | |||
Jonathan Frederic
|
r14464 | }); | |
Jonathan Frederic
|
r14970 | this.wait_for_widget(int_text); | |
Jonathan Frederic
|
r14464 | ||
index = this.append_cell('print(int_widget.value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
MinRK
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '1\n', | |
Jonathan Frederic
|
r14464 | 'Int textbox value set.'); | |
Jonathan Frederic
|
r14970 | this.cell_element_function(int_text.index, int_text.query, 'val', ['']); | |
this.sendKeys(int_text.query, '123456789'); | |||
Jonathan Frederic
|
r14464 | }); | |
Jonathan Frederic
|
r14970 | this.wait_for_widget(int_text); | |
Jonathan Frederic
|
r14464 | ||
index = this.append_cell('print(int_widget.value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
MinRK
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '123456789\n', | |
Jonathan Frederic
|
r14464 | 'Long int textbox value set (probably triggers throttling).'); | |
Jonathan Frederic
|
r14970 | this.cell_element_function(int_text.index, int_text.query, 'val', ['']); | |
this.sendKeys(int_text.query, '12hello'); | |||
Jonathan Frederic
|
r14464 | }); | |
Jonathan Frederic
|
r14970 | this.wait_for_widget(int_text); | |
Jonathan Frederic
|
r14464 | ||
index = this.append_cell('print(int_widget.value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
MinRK
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '12\n', | |
Jonathan Frederic
|
r14464 | 'Invald int textbox value caught and filtered.'); | |
}); | |||
Jonathan Frederic
|
r14674 | ||
Jonathan Frederic
|
r17731 | var slider_query = '.widget-area .widget-subarea .slider'; | |
Jonathan Frederic
|
r14970 | var int_text2 = {}; | |
Jonathan Frederic
|
r17731 | int_text2.query = '.widget-area .widget-subarea .my-second-num-test-text input'; | |
Jonathan Frederic
|
r14970 | int_text2.index = this.append_cell( | |
Jonathan Frederic
|
r14674 | 'intrange = [widgets.BoundedIntTextWidget(),\n' + | |
' widgets.IntSliderWidget()]\n' + | |||
'[display(intrange[i]) for i in range(2)]\n' + | |||
Jonathan Frederic
|
r17721 | 'intrange[0]._dom_classes = ["my-second-num-test-text"]\n' + | |
Jonathan Frederic
|
r14970 | 'print(intrange[0].model_id)\n'); | |
this.execute_cell_then(int_text2.index, function(index){ | |||
int_text2.model_id = this.get_output_cell(index).text.trim(); | |||
Jonathan Frederic
|
r18910 | }); | |
// Wait for the widgets to actually display. | |||
this.wait_for_element(int_text2.index, int_text2.query); | |||
this.wait_for_element(int_text2.index, slider_query); | |||
Jonathan Frederic
|
r14674 | ||
Jonathan Frederic
|
r18910 | // Continue with the tests. | |
this.then(function(){ | |||
this.test.assert(this.cell_element_exists(int_text2.index, | |||
Jonathan Frederic
|
r14674 | '.widget-area .widget-subarea'), | |
'Widget subarea exists.'); | |||
Jonathan Frederic
|
r18910 | this.test.assert(this.cell_element_exists(int_text2.index, slider_query), | |
Jonathan Frederic
|
r14674 | 'Widget slider exists.'); | |
Jonathan Frederic
|
r18910 | this.test.assert(this.cell_element_exists(int_text2.index, int_text2.query), | |
Jonathan Frederic
|
r14674 | 'Widget int textbox exists.'); | |
}); | |||
index = this.append_cell( | |||
'for widget in intrange:\n' + | |||
' widget.max = 50\n' + | |||
' widget.min = -50\n' + | |||
' widget.value = 25\n' + | |||
'print("Success")\n'); | |||
this.execute_cell_then(index, function(index){ | |||
MinRK
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
Jonathan Frederic
|
r14674 | 'Int range properties cell executed with correct output.'); | |
Jonathan Frederic
|
r14970 | this.test.assert(this.cell_element_exists(int_text2.index, slider_query), | |
Jonathan Frederic
|
r14674 | 'Widget slider exists.'); | |
Jonathan Frederic
|
r14970 | this.test.assert(this.cell_element_function(int_text2.index, slider_query, | |
Jonathan Frederic
|
r14674 | 'slider', ['value']) == 25, | |
'Slider set to Python value.'); | |||
Jonathan Frederic
|
r14970 | this.test.assert(this.cell_element_function(int_text2.index, int_text2.query, | |
Jonathan Frederic
|
r14674 | 'val') == 25, 'Int textbox set to Python value.'); | |
// Clear the int textbox value and then set it to 1 by emulating | |||
// keyboard presses. | |||
Jonathan Frederic
|
r16832 | this.evaluate(function(q){ | |
var textbox = IPython.notebook.element.find(q); | |||
textbox.val('1'); | |||
textbox.trigger('keyup'); | |||
}, {q: int_text2.query}); | |||
Jonathan Frederic
|
r14674 | }); | |
Jonathan Frederic
|
r14970 | this.wait_for_widget(int_text2); | |
Jonathan Frederic
|
r14674 | ||
index = this.append_cell('print(intrange[0].value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
MinRK
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '1\n', | |
Jonathan Frederic
|
r14674 | 'Int textbox set int range value'); | |
// Clear the int textbox value and then set it to 120 by emulating | |||
// keyboard presses. | |||
Jonathan Frederic
|
r16832 | this.evaluate(function(q){ | |
var textbox = IPython.notebook.element.find(q); | |||
textbox.val('120'); | |||
textbox.trigger('keyup'); | |||
}, {q: int_text2.query}); | |||
Jonathan Frederic
|
r14674 | }); | |
Jonathan Frederic
|
r14970 | this.wait_for_widget(int_text2); | |
Jonathan Frederic
|
r14674 | ||
index = this.append_cell('print(intrange[0].value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
MinRK
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '50\n', | |
Jonathan Frederic
|
r14674 | 'Int textbox value bound'); | |
// Clear the int textbox value and then set it to 'hello world' by | |||
// emulating keyboard presses. 'hello world' should get filtered... | |||
Jonathan Frederic
|
r16832 | this.evaluate(function(q){ | |
var textbox = IPython.notebook.element.find(q); | |||
textbox.val('hello world'); | |||
textbox.trigger('keyup'); | |||
}, {q: int_text2.query}); | |||
Jonathan Frederic
|
r14674 | }); | |
Jonathan Frederic
|
r14970 | this.wait_for_widget(int_text2); | |
Jonathan Frederic
|
r14674 | ||
index = this.append_cell('print(intrange[0].value)\n'); | |||
this.execute_cell_then(index, function(index){ | |||
MinRK
|
r14797 | this.test.assertEquals(this.get_output_cell(index).text, '50\n', | |
Jonathan Frederic
|
r14674 | 'Invalid int textbox characters ignored'); | |
}); | |||
Jonathan Frederic
|
r17938 | ||
index = this.append_cell( | |||
'a = widgets.IntSlider()\n' + | |||
'display(a)\n' + | |||
'a.max = -1\n' + | |||
'print("Success")\n'); | |||
this.execute_cell_then(index, function(index){ | |||
Jonathan Frederic
|
r17967 | this.test.assertEquals(0, 0, 'Invalid int range max bound does not cause crash.'); | |
Jonathan Frederic
|
r18189 | }, true); | |
Jonathan Frederic
|
r17938 | ||
index = this.append_cell( | |||
'a = widgets.IntSlider()\n' + | |||
'display(a)\n' + | |||
'a.min = 101\n' + | |||
'print("Success")\n'); | |||
this.execute_cell_then(index, function(index){ | |||
Jonathan Frederic
|
r17967 | this.test.assertEquals(0, 0, 'Invalid int range min bound does not cause crash.'); | |
Jonathan Frederic
|
r18189 | }, true); | |
Jonathan Frederic
|
r14464 | }); |