Show More
@@ -1,72 +1,67 b'' | |||||
1 | // Test the widget framework. |
|
1 | // Test the widget framework. | |
2 | casper.notebook_test(function () { |
|
2 | casper.notebook_test(function () { | |
3 | var index; |
|
3 | var index; | |
4 |
|
4 | |||
5 | this.then(function () { |
|
5 | this.then(function () { | |
6 |
|
6 | |||
7 | // Check if the WidgetManager class is defined. |
|
7 | // Check if the WidgetManager class is defined. | |
8 | this.test.assert(this.evaluate(function() { |
|
8 | this.test.assert(this.evaluate(function() { | |
9 | return IPython.WidgetManager !== undefined; |
|
9 | return IPython.WidgetManager !== undefined; | |
10 | }), 'WidgetManager class is defined'); |
|
10 | }), 'WidgetManager class is defined'); | |
11 | }); |
|
11 | }); | |
12 |
|
12 | |||
13 | index = this.append_cell( |
|
13 | index = this.append_cell( | |
14 | 'from IPython.html import widgets\n' + |
|
14 | 'from IPython.html import widgets\n' + | |
15 | 'from IPython.display import display, clear_output\n' + |
|
15 | 'from IPython.display import display, clear_output\n' + | |
16 | 'print("Success")'); |
|
16 | 'print("Success")'); | |
17 | this.execute_cell_then(index); |
|
17 | this.execute_cell_then(index); | |
18 |
|
18 | |||
19 | this.then(function () { |
|
19 | this.then(function () { | |
20 | // Check if the widget manager has been instantiated. |
|
20 | // Check if the widget manager has been instantiated. | |
21 | this.test.assert(this.evaluate(function() { |
|
21 | this.test.assert(this.evaluate(function() { | |
22 | return IPython.notebook.kernel.widget_manager !== undefined; |
|
22 | return IPython.notebook.kernel.widget_manager !== undefined; | |
23 | }), 'Notebook widget manager instantiated'); |
|
23 | }), 'Notebook widget manager instantiated'); | |
24 | }); |
|
24 | }); | |
25 |
|
25 | |||
|
26 | var textbox = {}; | |||
26 | throttle_index = this.append_cell( |
|
27 | throttle_index = this.append_cell( | |
27 | 'import time\n' + |
|
28 | 'import time\n' + | |
28 | 'textbox = widgets.TextWidget()\n' + |
|
29 | 'textbox = widgets.TextWidget()\n' + | |
29 | 'display(textbox)\n' + |
|
30 | 'display(textbox)\n' + | |
30 | 'textbox.add_class("my-throttle-textbox")\n' + |
|
31 | 'textbox.add_class("my-throttle-textbox")\n' + | |
31 | 'def handle_change(name, old, new):\n' + |
|
32 | 'def handle_change(name, old, new):\n' + | |
32 | ' print(len(new))\n' + |
|
33 | ' print(len(new))\n' + | |
33 | ' time.sleep(0.5)\n' + |
|
34 | ' time.sleep(0.5)\n' + | |
34 | 'textbox.on_trait_change(handle_change, "value")\n' + |
|
35 | 'textbox.on_trait_change(handle_change, "value")\n' + | |
35 |
'print( |
|
36 | 'print(textbox.model_id)'); | |
36 | this.execute_cell_then(throttle_index, function(index){ |
|
37 | this.execute_cell_then(throttle_index, function(index){ | |
37 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
38 | textbox.model_id = this.get_output_cell(index).text.trim(); | |
38 | 'Test throttling cell executed with correct output'); |
|
|||
39 |
|
39 | |||
40 | this.test.assert(this.cell_element_exists(index, |
|
40 | this.test.assert(this.cell_element_exists(index, | |
41 | '.widget-area .widget-subarea'), |
|
41 | '.widget-area .widget-subarea'), | |
42 | 'Widget subarea exists.'); |
|
42 | 'Widget subarea exists.'); | |
43 |
|
43 | |||
44 | this.test.assert(this.cell_element_exists(index, |
|
44 | this.test.assert(this.cell_element_exists(index, | |
45 | '.my-throttle-textbox'), 'Textbox exists.'); |
|
45 | '.my-throttle-textbox'), 'Textbox exists.'); | |
46 |
|
46 | |||
47 | // Send 20 characters |
|
47 | // Send 20 characters | |
48 | this.sendKeys('.my-throttle-textbox', '....................'); |
|
48 | this.sendKeys('.my-throttle-textbox', '....................'); | |
49 | }); |
|
49 | }); | |
50 |
|
50 | |||
51 | this.waitFor(function check() { |
|
51 | this.wait_for_widget(textbox); | |
52 | var outputs = this.evaluate(function(i) { |
|
52 | ||
53 | return IPython.notebook.get_cell(i).output_area.outputs; |
|
53 | this.then(function () { | |
54 | }, {i : throttle_index}); |
|
|||
55 | var output = outputs[outputs.length-1].text.trim(); |
|
|||
56 | return (output == '20'); |
|
|||
57 |
|
||||
58 | }, function then() { |
|
|||
59 | var outputs = this.evaluate(function(i) { |
|
54 | var outputs = this.evaluate(function(i) { | |
60 | return IPython.notebook.get_cell(i).output_area.outputs; |
|
55 | return IPython.notebook.get_cell(i).output_area.outputs; | |
61 | }, {i : throttle_index}); |
|
56 | }, {i : throttle_index}); | |
62 |
|
57 | |||
63 | // Only 4 outputs should have printed, but because of timing, sometimes |
|
58 | // Only 4 outputs should have printed, but because of timing, sometimes | |
64 | // 5 outputs will print. All we need to do is verify num outputs <= 5 |
|
59 | // 5 outputs will print. All we need to do is verify num outputs <= 5 | |
65 | // because that is much less than 20. |
|
60 | // because that is much less than 20. | |
66 | this.test.assert(outputs.length <= 5, 'Messages throttled.'); |
|
61 | this.test.assert(outputs.length <= 5, 'Messages throttled.'); | |
67 |
|
62 | |||
68 | // We also need to verify that the last state sent was correct. |
|
63 | // We also need to verify that the last state sent was correct. | |
69 | var last_state = outputs[outputs.length-1].text; |
|
64 | var last_state = outputs[outputs.length-1].text; | |
70 | this.test.assertEquals(last_state, "20\n", "Last state sent when throttling."); |
|
65 | this.test.assertEquals(last_state, "20\n", "Last state sent when throttling."); | |
71 | }); |
|
66 | }); | |
72 | }); |
|
67 | }); |
@@ -1,52 +1,45 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 | 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")'); |
|
6 | 'print("Success")'); | |
7 | this.execute_cell_then(index); |
|
7 | this.execute_cell_then(index); | |
8 |
|
8 | |||
9 | var string_index = this.append_cell( |
|
9 | var string_index = this.append_cell( | |
10 | 'string_widget = [widgets.TextWidget(value = "xyz"),\n' + |
|
10 | 'string_widget = [widgets.TextWidget(value = "xyz"),\n' + | |
11 | ' widgets.TextareaWidget(value = "xyz"),\n' + |
|
11 | ' widgets.TextareaWidget(value = "xyz"),\n' + | |
12 | ' widgets.HTMLWidget(value = "xyz"),\n' + |
|
12 | ' widgets.HTMLWidget(value = "xyz"),\n' + | |
13 | ' widgets.LatexWidget(value = "$\\\\LaTeX{}$")]\n' + |
|
13 | ' widgets.LatexWidget(value = "$\\\\LaTeX{}$")]\n' + | |
14 | '[display(widget) for widget in string_widget]\n'+ |
|
14 | '[display(widget) for widget in string_widget]\n'+ | |
15 | 'print("Success")'); |
|
15 | 'print("Success")'); | |
16 | this.execute_cell_then(string_index, function(index){ |
|
16 | this.execute_cell_then(string_index, function(index){ | |
17 |
|
17 | |||
18 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
18 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
19 | 'Create string widget cell executed with correct output.'); |
|
19 | 'Create string widget cell executed with correct output.'); | |
20 |
|
20 | |||
21 | this.test.assert(this.cell_element_exists(index, |
|
21 | this.test.assert(this.cell_element_exists(index, | |
22 | '.widget-area .widget-subarea'), |
|
22 | '.widget-area .widget-subarea'), | |
23 | 'Widget subarea exists.'); |
|
23 | 'Widget subarea exists.'); | |
24 |
|
24 | |||
25 | this.test.assert(this.cell_element_exists(index, |
|
25 | this.test.assert(this.cell_element_exists(index, | |
26 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]'), |
|
26 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]'), | |
27 | 'Textbox exists.'); |
|
27 | 'Textbox exists.'); | |
28 |
|
28 | |||
29 | this.test.assert(this.cell_element_exists(index, |
|
29 | this.test.assert(this.cell_element_exists(index, | |
30 | '.widget-area .widget-subarea .widget-hbox textarea'), |
|
30 | '.widget-area .widget-subarea .widget-hbox textarea'), | |
31 | 'Textarea exists.'); |
|
31 | 'Textarea exists.'); | |
32 |
|
32 | |||
33 | this.test.assert(this.cell_element_function(index, |
|
33 | this.test.assert(this.cell_element_function(index, | |
34 | '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='xyz', |
|
34 | '.widget-area .widget-subarea .widget-hbox textarea', 'val')=='xyz', | |
35 | 'Python set textarea value.'); |
|
35 | 'Python set textarea value.'); | |
36 |
|
36 | |||
37 | this.test.assert(this.cell_element_function(index, |
|
37 | this.test.assert(this.cell_element_function(index, | |
38 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='xyz', |
|
38 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'val')=='xyz', | |
39 | 'Python set textbox value.'); |
|
39 | 'Python set textbox value.'); | |
40 |
|
40 | |||
41 | }); |
|
|||
42 |
|
||||
43 | this.wait(500); // Wait for change to execute in kernel |
|
|||
44 |
|
||||
45 | index = this.append_cell('print(string_widget.value)'); |
|
|||
46 | this.execute_cell_then(index, function(index){ |
|
|||
47 |
|
||||
48 | this.test.assert(this.cell_element_exists(string_index, |
|
41 | this.test.assert(this.cell_element_exists(string_index, | |
49 | '.widget-area .widget-subarea div span.MathJax_Preview'), |
|
42 | '.widget-area .widget-subarea div span.MathJax_Preview'), | |
50 | 'MathJax parsed the LaTeX successfully.'); |
|
43 | 'MathJax parsed the LaTeX successfully.'); | |
51 | }); |
|
44 | }); | |
52 | }); No newline at end of file |
|
45 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now