widget_button.js
47 lines
| 1.9 KiB
| application/javascript
|
JavascriptLexer
|
r14464 | // Test widget button class | ||
casper.notebook_test(function () { | ||||
|
r18910 | var button_index = this.append_cell( | ||
|
r14464 | 'from IPython.html import widgets\n' + | ||
'from IPython.display import display, clear_output\n' + | ||||
|
r17598 | 'button = widgets.Button(description="Title")\n' + | ||
|
r17307 | 'display(button)\n' + | ||
|
r14464 | 'print("Success")\n' + | ||
'def handle_click(sender):\n' + | ||||
|
r17307 | ' display("Clicked")\n' + | ||
|
r14464 | 'button.on_click(handle_click)'); | ||
this.execute_cell_then(button_index, function(index){ | ||||
|
r17307 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | ||
|
r14464 | 'Create button cell executed with correct output.'); | ||
|
r18910 | }); | ||
// Wait for the widgets to actually display. | ||||
var widget_button_selector = '.widget-area .widget-subarea button'; | ||||
this.wait_for_element(button_index, widget_button_selector); | ||||
|
r14464 | |||
|
r18910 | // Continue with the tests. | ||
this.then(function() { | ||||
this.test.assert(this.cell_element_exists(button_index, | ||||
|
r14464 | '.widget-area .widget-subarea'), | ||
'Widget subarea exists.'); | ||||
|
r18910 | this.test.assert(this.cell_element_exists(button_index, | ||
widget_button_selector), | ||||
|
r14464 | 'Widget button exists.'); | ||
|
r18910 | this.test.assert(this.cell_element_function(button_index, | ||
widget_button_selector, 'html')=='Title', | ||||
|
r14464 | 'Set button description.'); | ||
|
r18910 | this.cell_element_function(button_index, | ||
widget_button_selector, 'click'); | ||||
|
r14464 | }); | ||
|
r14970 | this.wait_for_output(button_index, 1); | ||
this.then(function () { | ||||
|
r19293 | this.test.assertEquals(this.get_output_cell(button_index, 1).text, "WARNING: The widget API is still considered experimental and \n may change by the next major release of IPython.\n", | ||
'Importing widgets show a warning'); | ||||
this.test.assertEquals(this.get_output_cell(button_index, 2).data['text/plain'], "'Clicked'", | ||||
|
r14970 | 'Button click event fires.'); | ||
|
r14464 | }); | ||
|
r19293 | }); | ||