notebook/IPython/html/tests/widgets/widget_button.js

48 lines
1.9 KiB
JavaScript
Raw Normal View History

2013-12-13 02:49:34 +08:00
// Test widget button class
casper.notebook_test(function () {
2014-11-11 04:36:39 +08:00
var button_index = this.append_cell(
2013-12-13 02:49:34 +08:00
'from IPython.html import widgets\n' +
'from IPython.display import display, clear_output\n' +
'button = widgets.Button(description="Title")\n' +
2014-07-22 03:06:27 +08:00
'display(button)\n' +
2013-12-13 02:49:34 +08:00
'print("Success")\n' +
'def handle_click(sender):\n' +
2014-07-22 03:06:27 +08:00
' display("Clicked")\n' +
2013-12-13 02:49:34 +08:00
'button.on_click(handle_click)');
this.execute_cell_then(button_index, function(index){
2014-07-22 03:06:27 +08:00
this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
2013-12-13 02:49:34 +08:00
'Create button cell executed with correct output.');
2014-11-11 04:36:39 +08:00
});
// 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);
2013-12-13 02:49:34 +08:00
2014-11-11 04:36:39 +08:00
// Continue with the tests.
this.then(function() {
this.test.assert(this.cell_element_exists(button_index,
2013-12-13 02:49:34 +08:00
'.widget-area .widget-subarea'),
'Widget subarea exists.');
2014-11-11 04:36:39 +08:00
this.test.assert(this.cell_element_exists(button_index,
widget_button_selector),
2013-12-13 02:49:34 +08:00
'Widget button exists.');
2014-11-11 04:36:39 +08:00
this.test.assert(this.cell_element_function(button_index,
widget_button_selector, 'html')=='Title',
2013-12-13 02:49:34 +08:00
'Set button description.');
2014-11-11 04:36:39 +08:00
this.cell_element_function(button_index,
widget_button_selector, 'click');
2013-12-13 02:49:34 +08:00
});
this.wait_for_output(button_index, 1);
this.then(function () {
2014-12-07 00:21:28 +08:00
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'",
'Button click event fires.');
2013-12-13 02:49:34 +08:00
});
2014-12-07 00:21:28 +08:00
});