Created
March 12, 2015 11:51
-
-
Save bollwyvl/5a6c0dab551f20aba3ac to your computer and use it in GitHub Desktop.
test_widget_multipleselection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test selection class | |
casper.notebook_test(function () { | |
var assert_cell_prints = (function(src, val, msg){ | |
var index = this.append_cell(src); | |
this.execute_cell_then(index, function(index){ | |
this.test.assertEquals( | |
this.get_output_cell(index).text, | |
val + "\n", | |
msg); | |
}); | |
return index; | |
}).bind(this); | |
var click = (function(selector, modifier){ | |
var bb = this.getElementBounds(selector); | |
this.page.sendEvent( | |
'mousedown', | |
bb.left + 1, bb.top + 1, | |
'left', | |
this.page.event.modifier["modifier"] | |
); | |
}).bind(this); | |
var tuple = function(){ | |
var bits = []; | |
for | |
} | |
assert_cell_prints( | |
'from IPython.html import widgets\n' + | |
'from IPython.display import display, clear_output\n' + | |
'print("Success")', | |
'Success', | |
'Widgets import correctly' | |
); | |
var selector = { | |
SelectMultiple: '.widget-select-multiple .widget-listbox', | |
}; | |
var selection_values = 'abcd'; | |
var selection_index = assert_cell_prints( | |
'options=[i for i in "' + selection_values + '"]\n' + | |
'selection = [\n' + | |
' widgets.SelectMultiple(options=options),\n' + | |
']\n' + | |
'[display(i) for i in selection]\n' + | |
'for widget in selection:\n' + | |
' def handle_change(name,old,new):\n' + | |
' for other_widget in selection:\n' + | |
' other_widget.value = new\n' + | |
' widget.on_trait_change(handle_change, "value")\n' + | |
'print("Success")', | |
'Success', | |
'Create selection cell executed with correct output.' | |
); | |
// Wait for the widgets to actually display. | |
this.wait_for_element(selection_index, selector.SelectMultiple); | |
// Continue with the tests. | |
this.then(function() { | |
this.test.assert( | |
this.cell_element_exists( | |
selection_index, | |
'.widget-area .widget-subarea' | |
), | |
'Widget subarea exists.' | |
); | |
Object.keys(selector).map((function(cls){ | |
this.test.assert( | |
this.cell_element_exists(selection_index, selector[cls]), | |
cls + ' widget exists.' | |
); | |
}).bind(this)); | |
}); | |
this.then(function(){ | |
this.click(selector.SelectMultiple + " option:nth-child(3)"); | |
assert_cell_prints( | |
'print(selection[0].value[0] == options[2])', | |
"True", | |
'SelectMultiple value changed by click'); | |
}); | |
this.wait_for_idle(); | |
this.then(function(){ | |
click(selector.SelectMultiple + " option:nth-child(1)", "ctrl"); | |
assert_cell_prints( | |
'print(selection[0].value == (options[0], options[2]))', | |
"True", | |
'SelectMultiple can use ctrl-click to multiselect non-adjacent'); | |
}); | |
this.wait_for_idle(); | |
this.then(function(){ | |
this.click(selector.SelectMultiple + " option:nth-child(2)"); | |
}); | |
this.then(function(){ | |
click(selector.SelectMultiple + " option:nth-child(4)", "shift"); | |
assert_cell_prints( | |
'print(selection[0].value == (options[1], options[2], options[3]))', | |
"True", | |
'SelectMultiple can use shift-click to multiselect adjacent'); | |
this.page.sendEvent('keyup', this.page.event.key.Shift); | |
}); | |
this.wait_for_idle(); | |
this.then(function(){ | |
this.click(selector.SelectMultiple + " option:nth-child(1)"); | |
}); | |
this.wait_for_idle(); | |
this.then(function(){ | |
this.sendKeys(selector.SelectMultiple, this.page.event.key.Down, { | |
modifiers: "shift" | |
}); | |
assert_cell_prints( | |
'print(selection[0].value == (options[1], options[2]))', | |
"True", | |
'SelectMultiple can use shift-arrow to multiselect adjacent'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment