Show More
@@ -44,7 +44,7 casper.notebook_test(function () { | |||||
44 |
|
44 | |||
45 |
|
45 | |||
46 | // Check widget mapping //////////////////////////////////////////////////// |
|
46 | // Check widget mapping //////////////////////////////////////////////////// | |
47 | var cell_index = run_python_code('names = [name for name in dir(widgets)' + |
|
47 | var names_cell_index = run_python_code('names = [name for name in dir(widgets)' + | |
48 | ' if name.endswith("Widget") and name!= "Widget"]\n' + |
|
48 | ' if name.endswith("Widget") and name!= "Widget"]\n' + | |
49 | 'for name in names:\n' + |
|
49 | 'for name in names:\n' + | |
50 | ' print(name)\n'); |
|
50 | ' print(name)\n'); | |
@@ -62,7 +62,7 casper.notebook_test(function () { | |||||
62 | }); |
|
62 | }); | |
63 |
|
63 | |||
64 | // Get the widget names registered in python. |
|
64 | // Get the widget names registered in python. | |
65 | var python_names = this.get_output_cell(cell_index).text.split('\n'); |
|
65 | var python_names = this.get_output_cell(names_cell_index).text.split('\n'); | |
66 |
|
66 | |||
67 | // Make sure the two lists have the same items. |
|
67 | // Make sure the two lists have the same items. | |
68 | for (var i in javascript_names) { |
|
68 | for (var i in javascript_names) { | |
@@ -91,30 +91,54 casper.notebook_test(function () { | |||||
91 | this.test.assert(found, python_name + ' exists in javascript'); |
|
91 | this.test.assert(found, python_name + ' exists in javascript'); | |
92 | } |
|
92 | } | |
93 | } |
|
93 | } | |
|
94 | }); | |||
|
95 | ||||
94 |
|
96 | |||
95 | // Try to create a button widget |
|
|||
96 | cell_index = run_python_code('button = widgets.ButtonWidget()\n' + |
|
|||
97 | 'display(button)\n'+ |
|
|||
98 | 'print("Success")'); |
|
|||
99 |
|
97 | |||
100 | this.then(function () { |
|
98 | // Test button widget ////////////////////////////////////////////////////// | |
|
99 | button_cell_index = run_python_code('button = widgets.ButtonWidget(description="Title")\n' + | |||
|
100 | 'display(button)\n'+ | |||
|
101 | 'print("Success")\n' + | |||
|
102 | 'def handle_click(sender):\n' + | |||
|
103 | ' print("Clicked")\n' + | |||
|
104 | 'button.on_click(handle_click)'); | |||
101 |
|
105 | |||
102 | // Check if the WidgetManager class is defined. |
|
106 | this.then(function () { | |
103 | var $widget_subarea = this.evaluate(function() { |
|
107 | var button_output = this.get_output_cell(button_cell_index).text; | |
104 | var $cell = IPython.notebook.get_cell_element(cell_index); |
|
108 | this.test.assert(button_output == 'Success\n', 'Create button widget, cell executed with correct output.'); | |
105 | return $cell.find('.widget-area.widget-subarea'); |
|
109 | ||
106 | }); |
|
110 | this.test.assert(casper.evaluate(function (i) { | |
|
111 | var $cell = IPython.notebook.get_cell(i).element; | |||
|
112 | return $cell.find('.widget-area').find('.widget-subarea').length > 0; | |||
|
113 | }, | |||
|
114 | {i : button_cell_index}), 'Create button widget, widget subarea exist.'); | |||
|
115 | ||||
|
116 | this.test.assert(casper.evaluate(function (i) { | |||
|
117 | var $cell = IPython.notebook.get_cell(i).element; | |||
|
118 | return $cell.find('.widget-area').find('.widget-subarea').find('button').length > 0; | |||
|
119 | }, | |||
|
120 | {i : button_cell_index}), 'Create button widget, widget button exist.'); | |||
|
121 | ||||
|
122 | this.test.assert(casper.evaluate(function (i) { | |||
|
123 | var $cell = IPython.notebook.get_cell(i).element; | |||
|
124 | return $cell.find('.widget-area').find('.widget-subarea').find('button').html() == 'Title'; | |||
|
125 | }, | |||
|
126 | {i : button_cell_index}), 'Set button description.'); | |||
|
127 | ||||
|
128 | casper.evaluate(function (i) { | |||
|
129 | var $cell = IPython.notebook.get_cell(i).element; | |||
|
130 | $cell.find('.widget-area').find('.widget-subarea').find('button').click(); | |||
|
131 | }, | |||
|
132 | {i : button_cell_index}); | |||
|
133 | }); | |||
107 |
|
134 | |||
108 | // Make sure the widget subarea was found. |
|
135 | this.wait(1000); // Wait for click to execute in kernel and write output | |
109 | this.test.assert($widget_subarea.length > 0, 'Create button widget, widget subarea exist?'); |
|
|||
110 |
|
136 | |||
111 | var $widget_button = $widget_subarea.find('button'); |
|
137 | this.then(function () { | |
112 | this.test.assert($$widget_button.length > 0, 'Create button widget, widget button exist?'); |
|
138 | var button_output = this.get_output_cell(button_cell_index, 1).text; | |
113 | } |
|
139 | this.test.assert(button_output == 'Clicked\n', 'Button click event fires.'); | |
114 |
|
||||
115 | }); |
|
140 | }); | |
116 |
|
141 | |||
117 |
|
||||
118 | //}); // end of test.begin |
|
142 | //}); // end of test.begin | |
119 | }); |
|
143 | }); | |
120 |
|
144 |
General Comments 0
You need to be logged in to leave comments.
Login now