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