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

43 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-12-13 02:49:34 +08:00
// Test widget button class
casper.notebook_test(function () {
index = this.append_cell(
'from IPython.html import widgets\n' +
'from IPython.display import display, clear_output\n' +
'print("Success")');
this.execute_cell_then(index);
var button_index = this.append_cell(
'button = widgets.ButtonWidget(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.');
this.test.assert(this.cell_element_exists(index,
'.widget-area .widget-subarea'),
'Widget subarea exists.');
this.test.assert(this.cell_element_exists(index,
'.widget-area .widget-subarea button'),
'Widget button exists.');
this.test.assert(this.cell_element_function(index,
'.widget-area .widget-subarea button', 'html')=='Title',
'Set button description.');
this.cell_element_function(index,
'.widget-area .widget-subarea button', 'click');
});
this.wait_for_output(button_index, 1);
this.then(function () {
2014-07-22 03:06:27 +08:00
this.test.assertEquals(this.get_output_cell(button_index, 1)['text/plain'], "'Clicked'",
'Button click event fires.');
2013-12-13 02:49:34 +08:00
});
});