widgets_bool.js
97 lines
| 4.2 KiB
| application/javascript
|
JavascriptLexer
|
r14464 | // Test widget bool 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 bool_index = this.append_cell( | |||
|
r14583 | 'bool_widgets = [widgets.BoolWidget(description="Title", value=True) for i in range(2)]\n' + | |
'display(bool_widgets[0])\n' + | |||
'bool_widgets[1].view_name = "ToggleButtonView"\n' + | |||
'display(bool_widgets[1])\n' + | |||
'for widget in bool_widgets:\n' + | |||
' def handle_change(name,old,new):\n' + | |||
' for other_widget in bool_widgets:\n' + | |||
' other_widget.value = new\n' + | |||
' widget.on_trait_change(handle_change, "value")\n' + | |||
|
r14464 | 'print("Success")'); | |
this.execute_cell_then(bool_index, function(index){ | |||
this.test.assert(this.get_output_cell(index).text == 'Success\n', | |||
'Create bool widget 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 .widget-hbox-single input'), | |||
'Checkbox exists.'); | |||
this.test.assert(this.cell_element_function(index, | |||
'.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), | |||
'Checkbox is checked.'); | |||
this.test.assert(this.cell_element_exists(index, | |||
'.widget-area .widget-subarea .widget-hbox-single .widget-hlabel'), | |||
'Checkbox label exists.'); | |||
this.test.assert(this.cell_element_function(index, | |||
'.widget-area .widget-subarea .widget-hbox-single .widget-hlabel', 'html')=="Title", | |||
'Checkbox labeled correctly.'); | |||
this.test.assert(this.cell_element_exists(index, | |||
|
r14583 | '.widget-area .widget-subarea button'), | |
|
r14464 | 'Toggle button exists.'); | |
this.test.assert(this.cell_element_function(index, | |||
|
r14583 | '.widget-area .widget-subarea button', 'html')=="Title", | |
|
r14464 | 'Toggle button labeled correctly.'); | |
this.test.assert(this.cell_element_function(index, | |||
|
r14583 | '.widget-area .widget-subarea button', 'hasClass', ['active']), | |
|
r14464 | 'Toggle button is toggled.'); | |
}); | |||
index = this.append_cell( | |||
|
r14583 | 'bool_widgets[0].value = False\n' + | |
|
r14464 | 'print("Success")'); | |
this.execute_cell_then(index, function(index){ | |||
this.test.assert(this.get_output_cell(index).text == 'Success\n', | |||
'Change bool widget value cell executed with correct output.'); | |||
this.test.assert(! this.cell_element_function(bool_index, | |||
'.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), | |||
'Checkbox is not checked. (1)'); | |||
this.test.assert(! this.cell_element_function(bool_index, | |||
|
r14583 | '.widget-area .widget-subarea button', 'hasClass', ['active']), | |
|
r14464 | 'Toggle button is not toggled. (1)'); | |
// Try toggling the bool by clicking on the toggle button. | |||
|
r14583 | this.cell_element_function(bool_index, '.widget-area .widget-subarea button', 'click'); | |
|
r14464 | ||
this.test.assert(this.cell_element_function(bool_index, | |||
'.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), | |||
'Checkbox is checked. (2)'); | |||
this.test.assert(this.cell_element_function(bool_index, | |||
|
r14583 | '.widget-area .widget-subarea button', 'hasClass', ['active']), | |
|
r14464 | 'Toggle button is toggled. (2)'); | |
// Try toggling the bool by clicking on the checkbox. | |||
this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox-single input', 'click'); | |||
this.test.assert(! this.cell_element_function(bool_index, | |||
'.widget-area .widget-subarea .widget-hbox-single input', 'prop', ['checked']), | |||
'Checkbox is not checked. (3)'); | |||
this.test.assert(! this.cell_element_function(bool_index, | |||
|
r14583 | '.widget-area .widget-subarea button', 'hasClass', ['active']), | |
|
r14464 | 'Toggle button is not toggled. (3)'); | |
}); | |||
}); |