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' +
2014-07-19 03:47:33 +08:00
'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
} ) ;
2014-02-01 03:48:51 +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'" ,
2014-02-01 03:48:51 +08:00
'Button click event fires.' ) ;
2013-12-13 02:49:34 +08:00
} ) ;
2014-12-07 00:21:28 +08:00
} ) ;