##// END OF EJS Templates
Make all tests async display safe
Jonathan Frederic -
Show More
@@ -80,7 +80,7 b' define(["widgets/js/manager",'
80 this.trigger('msg:custom', msg.content.data.content);
80 this.trigger('msg:custom', msg.content.data.content);
81 break;
81 break;
82 case 'display':
82 case 'display':
83 return that.widget_manager.display_view(msg, that);
83 this.widget_manager.display_view(msg, that);
84 break;
84 break;
85 }
85 }
86 },
86 },
@@ -180,10 +180,31 b' casper.wait_for_widget = function (widget_info) {'
180 // widget_info : object
180 // widget_info : object
181 // Object which contains info related to the widget. The model_id property
181 // Object which contains info related to the widget. The model_id property
182 // is used to identify the widget.
182 // is used to identify the widget.
183
184 // Clear the results of a previous query, if they exist. Make sure a
185 // dictionary exists to store the async results in.
186 this.thenEvaluate(function(model_id) {
187 if (window.pending_msgs === undefined) {
188 window.pending_msgs = {};
189 } else {
190 window.pending_msgs[model_id] = -1;
191 }
192 }, {model_id: widget_info.model_id});
193
194 // Wait for the pending messages to be 0.
183 this.waitFor(function () {
195 this.waitFor(function () {
184 var pending = this.evaluate(function (m) {
196 var pending = this.evaluate(function (model_id) {
185 return IPython.notebook.kernel.widget_manager.get_model(m).pending_msgs;
197
186 }, {m: widget_info.model_id});
198 // Get the model. Once the model is had, store it's pending_msgs
199 // count in the window's dictionary.
200 IPython.notebook.kernel.widget_manager.get_model(model_id)
201 .then(function(model) {
202 window.pending_msgs[model_id] = model.pending_msgs;
203 });
204
205 // Return the pending_msgs result.
206 return window.pending_msgs[model_id];
207 }, {model_id: widget_info.model_id});
187
208
188 if (pending === 0) {
209 if (pending === 0) {
189 return true;
210 return true;
@@ -314,13 +335,13 b' casper.execute_cell_then = function(index, then_callback, expect_failure) {'
314 return return_val;
335 return return_val;
315 };
336 };
316
337
317 casper.waitfor_cell_element = function(index, selector){
338 casper.wait_for_element = function(index, selector){
318 // Utility function that allows us to easily wait for an element
339 // Utility function that allows us to easily wait for an element
319 // within a cell. Uses JQuery selector to look for the element.
340 // within a cell. Uses JQuery selector to look for the element.
320 var that = this;
341 var that = this;
321 this.waitFor(function() {
342 this.waitFor(function() {
322 return that.cell_element_exists(index, selector);
343 return that.cell_element_exists(index, selector);
323 }, function() { console.log('FOUND!'); });
344 });
324 };
345 };
325
346
326 casper.cell_element_exists = function(index, selector){
347 casper.cell_element_exists = function(index, selector){
@@ -131,7 +131,7 b' casper.notebook_test(function () {'
131 multiset.model_id = this.get_output_cell(index).text.trim();
131 multiset.model_id = this.get_output_cell(index).text.trim();
132 });
132 });
133
133
134 this.wait_for_widget(multiset);
134 this.wait_for_widget(multiset);
135
135
136 index = this.append_cell(
136 index = this.append_cell(
137 'print("%d%d%d" % (multiset.a, multiset.b, multiset.c))');
137 'print("%d%d%d" % (multiset.a, multiset.b, multiset.c))');
@@ -1,9 +1,7 b''
1 // Test widget bool class
1 // Test widget bool class
2 casper.notebook_test(function () {
2 casper.notebook_test(function () {
3 // index = this.append_cell(
4 // 'print("Success")');
5 // this.execute_cell_then(index);
6
3
4 // Create a checkbox and togglebutton.
7 var bool_index = this.append_cell(
5 var bool_index = this.append_cell(
8 'from IPython.html import widgets\n' +
6 'from IPython.html import widgets\n' +
9 'from IPython.display import display, clear_output\n' +
7 'from IPython.display import display, clear_output\n' +
@@ -17,20 +15,24 b' casper.notebook_test(function () {'
17 'Create bool widget cell executed with correct output.');
15 'Create bool widget cell executed with correct output.');
18 });
16 });
19
17
20 this.waitfor_cell_element(bool_index, '.widget-area .widget-subarea .widget-hbox input');
18 // Wait for the widgets to actually display.
21 this.waitfor_cell_element(bool_index, '.widget-area .widget-subarea button');
19 var widget_checkbox_selector = '.widget-area .widget-subarea .widget-hbox input';
20 var widget_togglebutton_selector = '.widget-area .widget-subarea button';
21 this.wait_for_element(bool_index, widget_checkbox_selector);
22 this.wait_for_element(bool_index, widget_togglebutton_selector);
22
23
24 // Continue the tests.
23 this.then(function() {
25 this.then(function() {
24 this.test.assert(this.cell_element_exists(bool_index,
26 this.test.assert(this.cell_element_exists(bool_index,
25 '.widget-area .widget-subarea'),
27 '.widget-area .widget-subarea'),
26 'Widget subarea exists.');
28 'Widget subarea exists.');
27
29
28 this.test.assert(this.cell_element_exists(bool_index,
30 this.test.assert(this.cell_element_exists(bool_index,
29 '.widget-area .widget-subarea .widget-hbox input'),
31 widget_checkbox_selector),
30 'Checkbox exists.');
32 'Checkbox exists.');
31
33
32 this.test.assert(this.cell_element_function(bool_index,
34 this.test.assert(this.cell_element_function(bool_index,
33 '.widget-area .widget-subarea .widget-hbox input', 'prop', ['checked']),
35 widget_checkbox_selector, 'prop', ['checked']),
34 'Checkbox is checked.');
36 'Checkbox is checked.');
35
37
36 this.test.assert(this.cell_element_exists(bool_index,
38 this.test.assert(this.cell_element_exists(bool_index,
@@ -42,18 +44,19 b' casper.notebook_test(function () {'
42 'Checkbox labeled correctly.');
44 'Checkbox labeled correctly.');
43
45
44 this.test.assert(this.cell_element_exists(bool_index,
46 this.test.assert(this.cell_element_exists(bool_index,
45 '.widget-area .widget-subarea button'),
47 widget_togglebutton_selector),
46 'Toggle button exists.');
48 'Toggle button exists.');
47
49
48 this.test.assert(this.cell_element_function(bool_index,
50 this.test.assert(this.cell_element_function(bool_index,
49 '.widget-area .widget-subarea button', 'html')=="Title",
51 widget_togglebutton_selector, 'html')=="Title",
50 'Toggle button labeled correctly.');
52 'Toggle button labeled correctly.');
51
53
52 this.test.assert(this.cell_element_function(bool_index,
54 this.test.assert(this.cell_element_function(bool_index,
53 '.widget-area .widget-subarea button', 'hasClass', ['active']),
55 widget_togglebutton_selector, 'hasClass', ['active']),
54 'Toggle button is toggled.');
56 'Toggle button is toggled.');
55 });
57 });
56
58
59 // Try changing the state of the widgets programatically.
57 index = this.append_cell(
60 index = this.append_cell(
58 'bool_widgets[0].value = False\n' +
61 'bool_widgets[0].value = False\n' +
59 'bool_widgets[1].value = False\n' +
62 'bool_widgets[1].value = False\n' +
@@ -63,25 +66,25 b' casper.notebook_test(function () {'
63 'Change bool widget value cell executed with correct output.');
66 'Change bool widget value cell executed with correct output.');
64
67
65 this.test.assert(! this.cell_element_function(bool_index,
68 this.test.assert(! this.cell_element_function(bool_index,
66 '.widget-area .widget-subarea .widget-hbox input', 'prop', ['checked']),
69 widget_checkbox_selector, 'prop', ['checked']),
67 'Checkbox is not checked. (1)');
70 'Checkbox is not checked. (1)');
68
71
69 this.test.assert(! this.cell_element_function(bool_index,
72 this.test.assert(! this.cell_element_function(bool_index,
70 '.widget-area .widget-subarea button', 'hasClass', ['active']),
73 widget_togglebutton_selector, 'hasClass', ['active']),
71 'Toggle button is not toggled. (1)');
74 'Toggle button is not toggled. (1)');
72
75
73 // Try toggling the bool by clicking on the checkbox.
76 // Try toggling the bool by clicking on the checkbox.
74 this.cell_element_function(bool_index, '.widget-area .widget-subarea .widget-hbox input', 'click');
77 this.cell_element_function(bool_index, widget_checkbox_selector, 'click');
75
78
76 this.test.assert(this.cell_element_function(bool_index,
79 this.test.assert(this.cell_element_function(bool_index,
77 '.widget-area .widget-subarea .widget-hbox input', 'prop', ['checked']),
80 widget_checkbox_selector, 'prop', ['checked']),
78 'Checkbox is checked. (2)');
81 'Checkbox is checked. (2)');
79
82
80 // Try toggling the bool by clicking on the toggle button.
83 // Try toggling the bool by clicking on the toggle button.
81 this.cell_element_function(bool_index, '.widget-area .widget-subarea button', 'click');
84 this.cell_element_function(bool_index, widget_togglebutton_selector, 'click');
82
85
83 this.test.assert(this.cell_element_function(bool_index,
86 this.test.assert(this.cell_element_function(bool_index,
84 '.widget-area .widget-subarea button', 'hasClass', ['active']),
87 widget_togglebutton_selector, 'hasClass', ['active']),
85 'Toggle button is toggled. (3)');
88 'Toggle button is toggled. (3)');
86
89
87 });
90 });
@@ -1,12 +1,10 b''
1 // Test container class
1 // Test container class
2 casper.notebook_test(function () {
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
3
4 // Create a box widget.
9 var container_index = this.append_cell(
5 var container_index = this.append_cell(
6 'from IPython.html import widgets\n' +
7 'from IPython.display import display, clear_output\n' +
10 'container = widgets.Box()\n' +
8 'container = widgets.Box()\n' +
11 'button = widgets.Button()\n'+
9 'button = widgets.Button()\n'+
12 'container.children = [button]\n'+
10 'container.children = [button]\n'+
@@ -14,24 +12,32 b' casper.notebook_test(function () {'
14 'container._dom_classes = ["my-test-class"]\n'+
12 'container._dom_classes = ["my-test-class"]\n'+
15 'print("Success")\n');
13 'print("Success")\n');
16 this.execute_cell_then(container_index, function(index){
14 this.execute_cell_then(container_index, function(index){
17
18 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
15 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
19 'Create container cell executed with correct output.');
16 'Create container cell executed with correct output.');
17 });
20
18
21 this.test.assert(this.cell_element_exists(index,
19 // Wait for the widgets to actually display.
20 var widget_box_selector = '.widget-area .widget-subarea .widget-box';
21 var widget_box_button_selector = '.widget-area .widget-subarea .widget-box button';
22 this.wait_for_element(container_index, widget_box_selector);
23 this.wait_for_element(container_index, widget_box_button_selector);
24
25 // Continue with the tests.
26 this.then(function() {
27 this.test.assert(this.cell_element_exists(container_index,
22 '.widget-area .widget-subarea'),
28 '.widget-area .widget-subarea'),
23 'Widget subarea exists.');
29 'Widget subarea exists.');
24
30
25 this.test.assert(this.cell_element_exists(index,
31 this.test.assert(this.cell_element_exists(container_index,
26 '.widget-area .widget-subarea .widget-box'),
32 widget_box_selector),
27 'Widget container exists.');
33 'Widget container exists.');
28
34
29 this.test.assert(this.cell_element_exists(index,
35 this.test.assert(this.cell_element_exists(container_index,
30 '.widget-area .widget-subarea .my-test-class'),
36 '.widget-area .widget-subarea .my-test-class'),
31 '_dom_classes works.');
37 '_dom_classes works.');
32
38
33 this.test.assert(this.cell_element_exists(index,
39 this.test.assert(this.cell_element_exists(container_index,
34 '.widget-area .widget-subarea .my-test-class button'),
40 widget_box_button_selector),
35 'Container parent/child relationship works.');
41 'Container parent/child relationship works.');
36 });
42 });
37
43
@@ -61,20 +67,26 b' casper.notebook_test(function () {'
61 '_dom_classes can be used to remove a class.');
67 '_dom_classes can be used to remove a class.');
62 });
68 });
63
69
64 index = this.append_cell(
70 var boxalone_index = this.append_cell(
65 'display(button)\n'+
71 'display(button)\n'+
66 'print("Success")\n');
72 'print("Success")\n');
67 this.execute_cell_then(index, function(index){
73 this.execute_cell_then(boxalone_index, function(index){
68
69 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
74 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
70 'Display container child executed with correct output.');
75 'Display container child executed with correct output.');
76 });
77
78 // Wait for the widget to actually display.
79 var widget_button_selector = '.widget-area .widget-subarea button';
80 this.wait_for_element(boxalone_index, widget_button_selector);
71
81
72 this.test.assert(! this.cell_element_exists(index,
82 // Continue with the tests.
73 '.widget-area .widget-subarea .widget-box'),
83 this.then(function() {
84 this.test.assert(! this.cell_element_exists(boxalone_index,
85 widget_box_selector),
74 'Parent container not displayed.');
86 'Parent container not displayed.');
75
87
76 this.test.assert(this.cell_element_exists(index,
88 this.test.assert(this.cell_element_exists(boxalone_index,
77 '.widget-area .widget-subarea button'),
89 widget_button_selector),
78 'Child displayed.');
90 'Child displayed.');
79 });
91 });
80 }); No newline at end of file
92 });
@@ -1,12 +1,8 b''
1 // Test widget button class
1 // Test widget button class
2 casper.notebook_test(function () {
2 casper.notebook_test(function () {
3 index = this.append_cell(
3 var button_index = this.append_cell(
4 'from IPython.html import widgets\n' +
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var button_index = this.append_cell(
10 'button = widgets.Button(description="Title")\n' +
6 'button = widgets.Button(description="Title")\n' +
11 'display(button)\n' +
7 'display(button)\n' +
12 'print("Success")\n' +
8 'print("Success")\n' +
@@ -14,24 +10,30 b' casper.notebook_test(function () {'
14 ' display("Clicked")\n' +
10 ' display("Clicked")\n' +
15 'button.on_click(handle_click)');
11 'button.on_click(handle_click)');
16 this.execute_cell_then(button_index, function(index){
12 this.execute_cell_then(button_index, function(index){
17
18 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
13 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
19 'Create button cell executed with correct output.');
14 'Create button cell executed with correct output.');
15 });
16
17 // Wait for the widgets to actually display.
18 var widget_button_selector = '.widget-area .widget-subarea button';
19 this.wait_for_element(button_index, widget_button_selector);
20
20
21 this.test.assert(this.cell_element_exists(index,
21 // Continue with the tests.
22 this.then(function() {
23 this.test.assert(this.cell_element_exists(button_index,
22 '.widget-area .widget-subarea'),
24 '.widget-area .widget-subarea'),
23 'Widget subarea exists.');
25 'Widget subarea exists.');
24
26
25 this.test.assert(this.cell_element_exists(index,
27 this.test.assert(this.cell_element_exists(button_index,
26 '.widget-area .widget-subarea button'),
28 widget_button_selector),
27 'Widget button exists.');
29 'Widget button exists.');
28
30
29 this.test.assert(this.cell_element_function(index,
31 this.test.assert(this.cell_element_function(button_index,
30 '.widget-area .widget-subarea button', 'html')=='Title',
32 widget_button_selector, 'html')=='Title',
31 'Set button description.');
33 'Set button description.');
32
34
33 this.cell_element_function(index,
35 this.cell_element_function(button_index,
34 '.widget-area .widget-subarea button', 'click');
36 widget_button_selector, 'click');
35 });
37 });
36
38
37 this.wait_for_output(button_index, 1);
39 this.wait_for_output(button_index, 1);
@@ -1,30 +1,34 b''
1 // Test widget float class
1 // Test widget float class
2 casper.notebook_test(function () {
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var float_text = {};
3 var float_text = {};
10 float_text.query = '.widget-area .widget-subarea .my-second-float-text input';
4 float_text.query = '.widget-area .widget-subarea .my-second-float-text input';
11 float_text.index = this.append_cell(
5 float_text.index = this.append_cell(
6 'from IPython.html import widgets\n' +
7 'from IPython.display import display, clear_output\n' +
12 'float_widget = widgets.FloatText()\n' +
8 'float_widget = widgets.FloatText()\n' +
13 'display(float_widget)\n' +
9 'display(float_widget)\n' +
14 'float_widget._dom_classes = ["my-second-float-text"]\n' +
10 'float_widget._dom_classes = ["my-second-float-text"]\n' +
15 'print(float_widget.model_id)\n');
11 'print(float_widget.model_id)\n');
16 this.execute_cell_then(float_text.index, function(index){
12 this.execute_cell_then(float_text.index, function(index){
17 float_text.model_id = this.get_output_cell(index).text.trim();
13 float_text.model_id = this.get_output_cell(index).text.trim();
18
14 });
19 this.test.assert(this.cell_element_exists(index,
15
16 // Wait for the widget to actually display.
17 this.wait_for_element(float_text.index, float_text.query);
18
19 // Continue with the tests
20 this.then(function(){
21 this.test.assert(this.cell_element_exists(float_text.index,
20 '.widget-area .widget-subarea'),
22 '.widget-area .widget-subarea'),
21 'Widget subarea exists.');
23 'Widget subarea exists.');
22
24
23 this.test.assert(this.cell_element_exists(index, float_text.query),
25 this.test.assert(this.cell_element_exists(float_text.index, float_text.query),
24 'Widget float textbox exists.');
26 'Widget float textbox exists.');
25
27
26 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
28 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
29 console.log('send keys');
27 this.sendKeys(float_text.query, '1.05');
30 this.sendKeys(float_text.query, '1.05');
31 console.log('send keys done');
28 });
32 });
29
33
30 this.wait_for_widget(float_text);
34 this.wait_for_widget(float_text);
@@ -64,18 +68,23 b' casper.notebook_test(function () {'
64 '[display(floatrange[i]) for i in range(2)]\n' +
68 '[display(floatrange[i]) for i in range(2)]\n' +
65 'print("Success")\n');
69 'print("Success")\n');
66 this.execute_cell_then(slider.index, function(index){
70 this.execute_cell_then(slider.index, function(index){
67
68 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
71 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
69 'Create float range cell executed with correct output.');
72 'Create float range cell executed with correct output.');
73 });
74
75 // Wait for the widgets to actually display.
76 this.wait_for_element(slider.index, slider.query);
77 this.wait_for_element(slider.index, float_text_query);
70
78
71 this.test.assert(this.cell_element_exists(index,
79 this.then(function(){
80 this.test.assert(this.cell_element_exists(slider.index,
72 '.widget-area .widget-subarea'),
81 '.widget-area .widget-subarea'),
73 'Widget subarea exists.');
82 'Widget subarea exists.');
74
83
75 this.test.assert(this.cell_element_exists(index, slider.query),
84 this.test.assert(this.cell_element_exists(slider.index, slider.query),
76 'Widget slider exists.');
85 'Widget slider exists.');
77
86
78 this.test.assert(this.cell_element_exists(index, float_text_query),
87 this.test.assert(this.cell_element_exists(slider.index, float_text_query),
79 'Widget float textbox exists.');
88 'Widget float textbox exists.');
80 });
89 });
81
90
@@ -26,19 +26,23 b' casper.notebook_test(function () {'
26 'display(image)\n' +
26 'display(image)\n' +
27 'print("Success")\n');
27 'print("Success")\n');
28 this.execute_cell_then(image_index, function(index){
28 this.execute_cell_then(image_index, function(index){
29
30 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
29 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
31 'Create image executed with correct output.');
30 'Create image executed with correct output.');
31 });
32
33 // Wait for the widget to actually display.
34 var img_selector = '.widget-area .widget-subarea img';
35 this.wait_for_element(image_index, img_selector);
32
36
33 this.test.assert(this.cell_element_exists(index,
37 this.then(function(){
38 this.test.assert(this.cell_element_exists(image_index,
34 '.widget-area .widget-subarea'),
39 '.widget-area .widget-subarea'),
35 'Widget subarea exists.');
40 'Widget subarea exists.');
36
41
37 var img_sel = '.widget-area .widget-subarea img';
42 this.test.assert(this.cell_element_exists(image_index, img_selector), 'Image exists.');
38 this.test.assert(this.cell_element_exists(index, img_sel), 'Image exists.');
39
43
40 // Verify that the image's base64 data has made it into the DOM.
44 // Verify that the image's base64 data has made it into the DOM.
41 var img_src = this.cell_element_function(image_index, img_sel, 'attr', ['src']);
45 var img_src = this.cell_element_function(image_index, img_selector, 'attr', ['src']);
42 this.test.assert(img_src.indexOf(test_jpg) > -1, 'Image src data exists.');
46 this.test.assert(img_src.indexOf(test_jpg) > -1, 'Image src data exists.');
43 });
47 });
44 }); No newline at end of file
48 });
@@ -1,26 +1,28 b''
1 // Test widget int class
1 // Test widget int class
2 casper.notebook_test(function () {
2 casper.notebook_test(function () {
3 index = this.append_cell(
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var int_text = {};
3 var int_text = {};
10 int_text.query = '.widget-area .widget-subarea .my-second-int-text input';
4 int_text.query = '.widget-area .widget-subarea .my-second-int-text input';
11 int_text.index = this.append_cell(
5 int_text.index = this.append_cell(
6 'from IPython.html import widgets\n' +
7 'from IPython.display import display, clear_output\n' +
12 'int_widget = widgets.IntText()\n' +
8 'int_widget = widgets.IntText()\n' +
13 'display(int_widget)\n' +
9 'display(int_widget)\n' +
14 'int_widget._dom_classes = ["my-second-int-text"]\n' +
10 'int_widget._dom_classes = ["my-second-int-text"]\n' +
15 'print(int_widget.model_id)\n');
11 'print(int_widget.model_id)\n');
16 this.execute_cell_then(int_text.index, function(index){
12 this.execute_cell_then(int_text.index, function(index){
17 int_text.model_id = this.get_output_cell(index).text.trim();
13 int_text.model_id = this.get_output_cell(index).text.trim();
18
14 });
19 this.test.assert(this.cell_element_exists(index,
15
16 // Wait for the widget to actually display.
17 this.wait_for_element(int_text.index, int_text.query);
18
19 // Continue with the tests.
20 this.then(function() {
21 this.test.assert(this.cell_element_exists(int_text.index,
20 '.widget-area .widget-subarea'),
22 '.widget-area .widget-subarea'),
21 'Widget subarea exists.');
23 'Widget subarea exists.');
22
24
23 this.test.assert(this.cell_element_exists(index, int_text.query),
25 this.test.assert(this.cell_element_exists(int_text.index, int_text.query),
24 'Widget int textbox exists.');
26 'Widget int textbox exists.');
25
27
26 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
28 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
@@ -54,13 +56,6 b' casper.notebook_test(function () {'
54 this.test.assertEquals(this.get_output_cell(index).text, '12\n',
56 this.test.assertEquals(this.get_output_cell(index).text, '12\n',
55 'Invald int textbox value caught and filtered.');
57 'Invald int textbox value caught and filtered.');
56 });
58 });
57
58 index = this.append_cell(
59 'from IPython.html import widgets\n' +
60 'from IPython.display import display, clear_output\n' +
61 'print("Success")');
62 this.execute_cell_then(index);
63
64
59
65 var slider_query = '.widget-area .widget-subarea .slider';
60 var slider_query = '.widget-area .widget-subarea .slider';
66 var int_text2 = {};
61 var int_text2 = {};
@@ -73,15 +68,22 b' casper.notebook_test(function () {'
73 'print(intrange[0].model_id)\n');
68 'print(intrange[0].model_id)\n');
74 this.execute_cell_then(int_text2.index, function(index){
69 this.execute_cell_then(int_text2.index, function(index){
75 int_text2.model_id = this.get_output_cell(index).text.trim();
70 int_text2.model_id = this.get_output_cell(index).text.trim();
71 });
72
73 // Wait for the widgets to actually display.
74 this.wait_for_element(int_text2.index, int_text2.query);
75 this.wait_for_element(int_text2.index, slider_query);
76
76
77 this.test.assert(this.cell_element_exists(index,
77 // Continue with the tests.
78 this.then(function(){
79 this.test.assert(this.cell_element_exists(int_text2.index,
78 '.widget-area .widget-subarea'),
80 '.widget-area .widget-subarea'),
79 'Widget subarea exists.');
81 'Widget subarea exists.');
80
82
81 this.test.assert(this.cell_element_exists(index, slider_query),
83 this.test.assert(this.cell_element_exists(int_text2.index, slider_query),
82 'Widget slider exists.');
84 'Widget slider exists.');
83
85
84 this.test.assert(this.cell_element_exists(index, int_text2.query),
86 this.test.assert(this.cell_element_exists(int_text2.index, int_text2.query),
85 'Widget int textbox exists.');
87 'Widget int textbox exists.');
86 });
88 });
87
89
@@ -58,21 +58,30 b' casper.notebook_test(function () {'
58 this.execute_cell_then(selection_index, function(index){
58 this.execute_cell_then(selection_index, function(index){
59 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
59 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
60 'Create selection cell executed with correct output.');
60 'Create selection cell executed with correct output.');
61 });
62
63 // Wait for the widgets to actually display.
64 this.wait_for_element(selection_index, combo_selector);
65 this.wait_for_element(selection_index, multibtn_selector);
66 this.wait_for_element(selection_index, radio_selector);
67 this.wait_for_element(selection_index, list_selector);
61
68
62 this.test.assert(this.cell_element_exists(index,
69 // Continue with the tests.
70 this.then(function() {
71 this.test.assert(this.cell_element_exists(selection_index,
63 '.widget-area .widget-subarea'),
72 '.widget-area .widget-subarea'),
64 'Widget subarea exists.');
73 'Widget subarea exists.');
65
74
66 this.test.assert(this.cell_element_exists(index, combo_selector),
75 this.test.assert(this.cell_element_exists(selection_index, combo_selector),
67 'Widget combobox exists.');
76 'Widget combobox exists.');
68
77
69 this.test.assert(this.cell_element_exists(index, multibtn_selector),
78 this.test.assert(this.cell_element_exists(selection_index, multibtn_selector),
70 'Widget multibutton exists.');
79 'Widget multibutton exists.');
71
80
72 this.test.assert(this.cell_element_exists(index, radio_selector),
81 this.test.assert(this.cell_element_exists(selection_index, radio_selector),
73 'Widget radio buttons exists.');
82 'Widget radio buttons exists.');
74
83
75 this.test.assert(this.cell_element_exists(index, list_selector),
84 this.test.assert(this.cell_element_exists(selection_index, list_selector),
76 'Widget list exists.');
85 'Widget list exists.');
77
86
78 // Verify that no items are selected.
87 // Verify that no items are selected.
@@ -18,20 +18,22 b' casper.notebook_test(function () {'
18 'multicontainer.selected_index = 0\n' +
18 'multicontainer.selected_index = 0\n' +
19 'print("Success")\n');
19 'print("Success")\n');
20 this.execute_cell_then(multicontainer1_index, function(index){
20 this.execute_cell_then(multicontainer1_index, function(index){
21
22 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
21 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
23 'Create multicontainer cell executed with correct output. (1)');
22 'Create multicontainer cell executed with correct output. (1)');
23 });
24
25 // Wait for the widget to actually display.
26 this.wait_for_element(multicontainer1_index, multicontainer1_query);
24
27
25 this.test.assert(this.cell_element_exists(index,
28 // Continue with the tests.
29 this.then(function() {
30 this.test.assert(this.cell_element_exists(multicontainer1_index,
26 '.widget-area .widget-subarea'),
31 '.widget-area .widget-subarea'),
27 'Widget subarea exists.');
32 'Widget subarea exists.');
28
33
29 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
34 this.test.assert(this.cell_element_exists(multicontainer1_index, multicontainer1_query),
30 'Widget tab list exists.');
35 'Widget tab list exists.');
31
36
32 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
33 'First widget tab list exists.');
34
35 // JQuery selector is 1 based
37 // JQuery selector is 1 based
36 this.click(multicontainer1_query + ' li:nth-child(2) a');
38 this.click(multicontainer1_query + ' li:nth-child(2) a');
37 });
39 });
@@ -74,23 +76,28 b' casper.notebook_test(function () {'
74 'multicontainer.selected_index = 0\n' +
76 'multicontainer.selected_index = 0\n' +
75 'print("Success")\n');
77 'print("Success")\n');
76 this.execute_cell_then(multicontainer2_index, function(index){
78 this.execute_cell_then(multicontainer2_index, function(index){
77
78 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
79 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
79 'Create multicontainer cell executed with correct output. (2)');
80 'Create multicontainer cell executed with correct output. (2)');
81 });
82
83 // Wait for the widget to actually display.
84 this.wait_for_element(multicontainer2_index, multicontainer2_query);
80
85
81 this.test.assert(this.cell_element_exists(index,
86 // Continue with the tests.
87 this.then(function() {
88 this.test.assert(this.cell_element_exists(multicontainer2_index,
82 '.widget-area .widget-subarea'),
89 '.widget-area .widget-subarea'),
83 'Widget subarea exists.');
90 'Widget subarea exists.');
84
91
85 this.test.assert(this.cell_element_exists(index, multicontainer2_query),
92 this.test.assert(this.cell_element_exists(multicontainer2_index, multicontainer2_query),
86 'Widget accordion exists.');
93 'Widget accordion exists.');
87
94
88 this.test.assert(this.cell_element_exists(index, multicontainer2_query +
95 this.test.assert(this.cell_element_exists(multicontainer2_index, multicontainer2_query +
89 ' .panel:nth-child(1) .panel-collapse'),
96 ' .panel:nth-child(1) .panel-collapse'),
90 'First accordion page exists.');
97 'First accordion page exists.');
91
98
92 // JQuery selector is 1 based
99 // JQuery selector is 1 based
93 this.test.assert(this.cell_element_function(index, multicontainer2_query +
100 this.test.assert(this.cell_element_function(multicontainer2_index, multicontainer2_query +
94 ' .panel.panel-default:nth-child(3) .panel-heading .accordion-toggle',
101 ' .panel.panel-default:nth-child(3) .panel-heading .accordion-toggle',
95 'html')=='good', 'Accordion page title set (before display).');
102 'html')=='good', 'Accordion page title set (before display).');
96
103
@@ -1,12 +1,8 b''
1 // Test widget string class
1 // Test widget string class
2 casper.notebook_test(function () {
2 casper.notebook_test(function () {
3 index = this.append_cell(
3 var string_index = this.append_cell(
4 'from IPython.html import widgets\n' +
4 'from IPython.html import widgets\n' +
5 'from IPython.display import display, clear_output\n' +
5 'from IPython.display import display, clear_output\n' +
6 'print("Success")');
7 this.execute_cell_then(index);
8
9 var string_index = this.append_cell(
10 'string_widget = [widgets.Text(value = "xyz", placeholder = "abc"),\n' +
6 'string_widget = [widgets.Text(value = "xyz", placeholder = "abc"),\n' +
11 ' widgets.Textarea(value = "xyz", placeholder = "def"),\n' +
7 ' widgets.Textarea(value = "xyz", placeholder = "def"),\n' +
12 ' widgets.HTML(value = "xyz"),\n' +
8 ' widgets.HTML(value = "xyz"),\n' +
@@ -14,40 +10,50 b' casper.notebook_test(function () {'
14 '[display(widget) for widget in string_widget]\n'+
10 '[display(widget) for widget in string_widget]\n'+
15 'print("Success")');
11 'print("Success")');
16 this.execute_cell_then(string_index, function(index){
12 this.execute_cell_then(string_index, function(index){
17
18 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
13 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
19 'Create string widget cell executed with correct output.');
14 'Create string widget cell executed with correct output.');
15 });
16
17 // Wait for the widget to actually display.
18 var textbox_selector = '.widget-area .widget-subarea .widget-hbox input[type=text]';
19 var textarea_selector = '.widget-area .widget-subarea .widget-hbox textarea';
20 var latex_selector = '.widget-area .widget-subarea div span.MathJax_Preview';
21 this.wait_for_element(string_index, textbox_selector);
22 this.wait_for_element(string_index, textarea_selector);
23 this.wait_for_element(string_index, latex_selector);
20
24
21 this.test.assert(this.cell_element_exists(index,
25 // Continue with the tests.
26 this.then(function(){
27 this.test.assert(this.cell_element_exists(string_index,
22 '.widget-area .widget-subarea'),
28 '.widget-area .widget-subarea'),
23 'Widget subarea exists.');
29 'Widget subarea exists.');
24
30
25 this.test.assert(this.cell_element_exists(index,
31 this.test.assert(this.cell_element_exists(string_index,
26 '.widget-area .widget-subarea .widget-hbox input[type=text]'),
32 textbox_selector),
27 'Textbox exists.');
33 'Textbox exists.');
28
34
29 this.test.assert(this.cell_element_exists(index,
35 this.test.assert(this.cell_element_exists(string_index,
30 '.widget-area .widget-subarea .widget-hbox textarea'),
36 textarea_selector),
31 'Textarea exists.');
37 'Textarea exists.');
32
38
33 this.test.assert(this.cell_element_function(index,
39 this.test.assert(this.cell_element_function(string_index,
34 '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='xyz',
40 textarea_selector, 'val')=='xyz',
35 'Python set textarea value.');
41 'Python set textarea value.');
36
42
37 this.test.assert(this.cell_element_function(index,
43 this.test.assert(this.cell_element_function(string_index,
38 '.widget-area .widget-subarea .widget-hbox input[type=text]', 'val')=='xyz',
44 textbox_selector, 'val')=='xyz',
39 'Python set textbox value.');
45 'Python set textbox value.');
40
46
41 this.test.assert(this.cell_element_exists(string_index,
47 this.test.assert(this.cell_element_exists(string_index,
42 '.widget-area .widget-subarea div span.MathJax_Preview'),
48 latex_selector),
43 'MathJax parsed the LaTeX successfully.');
49 'MathJax parsed the LaTeX successfully.');
44
50
45 this.test.assert(this.cell_element_function(index,
51 this.test.assert(this.cell_element_function(string_index,
46 '.widget-area .widget-subarea .widget-hbox textarea', 'attr', ['placeholder'])=='def',
52 textarea_selector, 'attr', ['placeholder'])=='def',
47 'Python set textarea placeholder.');
53 'Python set textarea placeholder.');
48
54
49 this.test.assert(this.cell_element_function(index,
55 this.test.assert(this.cell_element_function(string_index,
50 '.widget-area .widget-subarea .widget-hbox input[type=text]', 'attr', ['placeholder'])=='abc',
56 textbox_selector, 'attr', ['placeholder'])=='abc',
51 'Python set textbox placehoder.');
57 'Python set textbox placehoder.');
52 });
58 });
53 });
59 });
General Comments 0
You need to be logged in to leave comments. Login now