##// END OF EJS Templates
Remove sleep from the following,...
Jonathan Frederic -
Show More
@@ -1,72 +1,72
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 26 throttle_index = this.append_cell(
27 27 'import time\n' +
28 28 'textbox = widgets.TextWidget()\n' +
29 29 'display(textbox)\n' +
30 30 'textbox.add_class("my-throttle-textbox")\n' +
31 31 'def handle_change(name, old, new):\n' +
32 32 ' print(len(new))\n' +
33 33 ' time.sleep(0.5)\n' +
34 34 'textbox.on_trait_change(handle_change, "value")\n' +
35 35 'print("Success")');
36 36 this.execute_cell_then(throttle_index, function(index){
37 37 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
38 38 'Test throttling cell executed with correct output');
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 this.sendKeys('.my-throttle-textbox', '...................A');
48 this.sendKeys('.my-throttle-textbox', '....................');
49 49 });
50 50
51 51 this.waitFor(function check() {
52 52 var outputs = this.evaluate(function(i) {
53 53 return IPython.notebook.get_cell(i).output_area.outputs;
54 54 }, {i : throttle_index});
55 var output = outputs[outputs.length-1].text;
56 return (output[output.length-1] == 'A');
55 var output = outputs[outputs.length-1].text.trim();
56 return (output == '20');
57 57
58 58 }, function then() {
59 59 var outputs = this.evaluate(function(i) {
60 60 return IPython.notebook.get_cell(i).output_area.outputs;
61 61 }, {i : throttle_index});
62 62
63 63 // Only 4 outputs should have printed, but because of timing, sometimes
64 64 // 5 outputs will print. All we need to do is verify num outputs <= 5
65 65 // because that is much less than 20.
66 66 this.test.assert(outputs.length <= 5, 'Messages throttled.');
67 67
68 68 // We also need to verify that the last state sent was correct.
69 69 var last_state = outputs[outputs.length-1].text;
70 70 this.test.assertEquals(last_state, "20\n", "Last state sent when throttling.");
71 71 });
72 72 });
@@ -1,44 +1,43
1 1 // Test widget button 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 button_index = this.append_cell(
10 10 'button = widgets.ButtonWidget(description="Title")\n' +
11 11 'display(button)\n'+
12 12 'print("Success")\n' +
13 13 'def handle_click(sender):\n' +
14 14 ' print("Clicked")\n' +
15 15 'button.on_click(handle_click)');
16 16 this.execute_cell_then(button_index, function(index){
17 17
18 18 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
19 19 'Create button 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 button'),
27 27 'Widget button exists.');
28 28
29 29 this.test.assert(this.cell_element_function(index,
30 30 '.widget-area .widget-subarea button', 'html')=='Title',
31 31 'Set button description.');
32 32
33 33 this.cell_element_function(index,
34 34 '.widget-area .widget-subarea button', 'click');
35 35 });
36 36
37 this.waitFor(function check() {
38 return (this.get_output_cell(button_index, 1).text == 'Clicked\n');
39 }, function then() {
40 this.test.assert(true, 'Button click event fires.');
41 }), function timeout() {
42 this.test.assert(false, 'Button click event fires.');
37 this.wait_for_output(button_index, 1);
38
39 this.then(function () {
40 this.test.assertEquals(this.get_output_cell(button_index, 1).text, 'Clicked\n',
41 'Button click event fires.');
43 42 });
44 43 }); No newline at end of file
@@ -1,108 +1,100
1 1 // Test widget float 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 var float_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
10
11 var float_index = this.append_cell(
9 var float_text = {};
10 float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
11 float_text.index = this.append_cell(
12 12 'float_widget = widgets.FloatTextWidget()\n' +
13 13 'display(float_widget)\n' +
14 14 'float_widget.add_class("my-second-float-text")\n' +
15 'print("Success")\n');
16 this.execute_cell_then(float_index, function(index){
17
18 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
19 'Create float cell executed with correct output.');
15 'print(float_widget.model_id)\n');
16 this.execute_cell_then(float_text.index, function(index){
17 float_text.model_id = this.get_output_cell(index).text.trim();
20 18
21 19 this.test.assert(this.cell_element_exists(index,
22 20 '.widget-area .widget-subarea'),
23 21 'Widget subarea exists.');
24 22
25 this.test.assert(this.cell_element_exists(index, float_text_query_2),
23 this.test.assert(this.cell_element_exists(index, float_text.query),
26 24 'Widget float textbox exists.');
27 25
28 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
29 this.sendKeys(float_text_query_2, '1.05');
26 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
27 this.sendKeys(float_text.query, '1.05');
30 28 });
31 29
32 this.wait(500); // Wait for change to execute in kernel
30 this.wait_for_widget(float_text);
33 31
34 32 index = this.append_cell('print(float_widget.value)\n');
35 33 this.execute_cell_then(index, function(index){
36 34 this.test.assertEquals(this.get_output_cell(index).text, '1.05\n',
37 35 'Float textbox value set.');
38 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
39 this.sendKeys(float_text_query_2, '123456789.0');
36 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
37 this.sendKeys(float_text.query, '123456789.0');
40 38 });
41 39
42 this.wait(500); // Wait for change to execute in kernel
40 this.wait_for_widget(float_text);
43 41
44 42 index = this.append_cell('print(float_widget.value)\n');
45 43 this.execute_cell_then(index, function(index){
46 44 this.test.assertEquals(this.get_output_cell(index).text, '123456789.0\n',
47 45 'Long float textbox value set (probably triggers throttling).');
48 this.cell_element_function(float_index, float_text_query_2, 'val', ['']);
49 this.sendKeys(float_text_query_2, '12hello');
46 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
47 this.sendKeys(float_text.query, '12hello');
50 48 });
51 49
52 this.wait(500); // Wait for change to execute in kernel
50 this.wait_for_widget(float_text);
53 51
54 52 index = this.append_cell('print(float_widget.value)\n');
55 53 this.execute_cell_then(index, function(index){
56 54 this.test.assertEquals(this.get_output_cell(index).text, '12.0\n',
57 55 'Invald float textbox value caught and filtered.');
58 56 });
59 57
60 index = this.append_cell(
61 'from IPython.html import widgets\n' +
62 'from IPython.display import display, clear_output\n' +
63 'print("Success")');
64 this.execute_cell_then(index);
65
66 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
67 58 var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text';
68
69 var floatrange_index = this.append_cell(
59 var slider = {};
60 slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider';
61 slider.index = this.append_cell(
70 62 'floatrange = [widgets.BoundedFloatTextWidget(), \n' +
71 63 ' widgets.FloatSliderWidget()]\n' +
72 64 '[display(floatrange[i]) for i in range(2)]\n' +
73 65 'print("Success")\n');
74 this.execute_cell_then(floatrange_index, function(index){
66 this.execute_cell_then(slider.index, function(index){
75 67
76 68 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
77 69 'Create float range cell executed with correct output.');
78 70
79 71 this.test.assert(this.cell_element_exists(index,
80 72 '.widget-area .widget-subarea'),
81 73 'Widget subarea exists.');
82 74
83 this.test.assert(this.cell_element_exists(index, slider_query),
75 this.test.assert(this.cell_element_exists(index, slider.query),
84 76 'Widget slider exists.');
85 77
86 78 this.test.assert(this.cell_element_exists(index, float_text_query),
87 79 'Widget float textbox exists.');
88 80 });
89 81
90 82 index = this.append_cell(
91 83 'for widget in floatrange:\n' +
92 84 ' widget.max = 50.0\n' +
93 85 ' widget.min = -50.0\n' +
94 86 ' widget.value = 25.0\n' +
95 87 'print("Success")\n');
96 88 this.execute_cell_then(index, function(index){
97 89
98 90 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
99 91 'Float range properties cell executed with correct output.');
100 92
101 this.test.assert(this.cell_element_exists(floatrange_index, slider_query),
93 this.test.assert(this.cell_element_exists(slider.index, slider.query),
102 94 'Widget slider exists.');
103 95
104 this.test.assert(this.cell_element_function(floatrange_index, slider_query,
96 this.test.assert(this.cell_element_function(slider.index, slider.query,
105 97 'slider', ['value']) == 25.0,
106 98 'Slider set to Python value.');
107 99 });
108 100 }); No newline at end of file
@@ -1,151 +1,148
1 1 // Test widget int 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 var int_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
10
11 var int_index = this.append_cell(
9 var int_text = {}
10 int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
11 int_text.index = this.append_cell(
12 12 'int_widget = widgets.IntTextWidget()\n' +
13 13 'display(int_widget)\n' +
14 14 'int_widget.add_class("my-second-int-text")\n' +
15 'print("Success")\n');
16 this.execute_cell_then(int_index, function(index){
17
18 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
19 'Create int cell executed with correct output.');
15 'print(int_widget.model_id)\n');
16 this.execute_cell_then(int_text.index, function(index){
17 int_text.model_id = this.get_output_cell(index).text.trim();
20 18
21 19 this.test.assert(this.cell_element_exists(index,
22 20 '.widget-area .widget-subarea'),
23 21 'Widget subarea exists.');
24 22
25 this.test.assert(this.cell_element_exists(index, int_text_query_2),
23 this.test.assert(this.cell_element_exists(index, int_text.query),
26 24 'Widget int textbox exists.');
27 25
28 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
29 this.sendKeys(int_text_query_2, '1.05');
26 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
27 this.sendKeys(int_text.query, '1.05');
30 28 });
31 29
32 this.wait(500); // Wait for change to execute in kernel
30 this.wait_for_widget(int_text);
33 31
34 32 index = this.append_cell('print(int_widget.value)\n');
35 33 this.execute_cell_then(index, function(index){
36 34 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
37 35 'Int textbox value set.');
38 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
39 this.sendKeys(int_text_query_2, '123456789');
36 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
37 this.sendKeys(int_text.query, '123456789');
40 38 });
41 39
42 this.wait(500); // Wait for change to execute in kernel
40 this.wait_for_widget(int_text);
43 41
44 42 index = this.append_cell('print(int_widget.value)\n');
45 43 this.execute_cell_then(index, function(index){
46 44 this.test.assertEquals(this.get_output_cell(index).text, '123456789\n',
47 45 'Long int textbox value set (probably triggers throttling).');
48 this.cell_element_function(int_index, int_text_query_2, 'val', ['']);
49 this.sendKeys(int_text_query_2, '12hello');
46 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
47 this.sendKeys(int_text.query, '12hello');
50 48 });
51 49
52 this.wait(500); // Wait for change to execute in kernel
50 this.wait_for_widget(int_text);
53 51
54 52 index = this.append_cell('print(int_widget.value)\n');
55 53 this.execute_cell_then(index, function(index){
56 54 this.test.assertEquals(this.get_output_cell(index).text, '12\n',
57 55 'Invald int textbox value caught and filtered.');
58 56 });
59 57
60 58 index = this.append_cell(
61 59 'from IPython.html import widgets\n' +
62 60 'from IPython.display import display, clear_output\n' +
63 61 'print("Success")');
64 62 this.execute_cell_then(index);
65 63
66 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
67 var int_text_query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
68 64
69 var intrange_index = this.append_cell(
65 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
66 var int_text2 = {};
67 int_text2.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
68 int_text2.index = this.append_cell(
70 69 'intrange = [widgets.BoundedIntTextWidget(),\n' +
71 70 ' widgets.IntSliderWidget()]\n' +
72 71 '[display(intrange[i]) for i in range(2)]\n' +
73 72 'intrange[0].add_class("my-second-num-test-text")\n' +
74 'print("Success")\n');
75 this.execute_cell_then(intrange_index, function(index){
76
77 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
78 'Create int range cell executed with correct output.');
73 'print(intrange[0].model_id)\n');
74 this.execute_cell_then(int_text2.index, function(index){
75 int_text2.model_id = this.get_output_cell(index).text.trim();
79 76
80 77 this.test.assert(this.cell_element_exists(index,
81 78 '.widget-area .widget-subarea'),
82 79 'Widget subarea exists.');
83 80
84 81 this.test.assert(this.cell_element_exists(index, slider_query),
85 82 'Widget slider exists.');
86 83
87 this.test.assert(this.cell_element_exists(index, int_text_query),
84 this.test.assert(this.cell_element_exists(index, int_text2.query),
88 85 'Widget int textbox exists.');
89 86 });
90 87
91 88 index = this.append_cell(
92 89 'for widget in intrange:\n' +
93 90 ' widget.max = 50\n' +
94 91 ' widget.min = -50\n' +
95 92 ' widget.value = 25\n' +
96 93 'print("Success")\n');
97 94 this.execute_cell_then(index, function(index){
98 95
99 96 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
100 97 'Int range properties cell executed with correct output.');
101 98
102 this.test.assert(this.cell_element_exists(intrange_index, slider_query),
99 this.test.assert(this.cell_element_exists(int_text2.index, slider_query),
103 100 'Widget slider exists.');
104 101
105 this.test.assert(this.cell_element_function(intrange_index, slider_query,
102 this.test.assert(this.cell_element_function(int_text2.index, slider_query,
106 103 'slider', ['value']) == 25,
107 104 'Slider set to Python value.');
108 105
109 this.test.assert(this.cell_element_function(intrange_index, int_text_query,
106 this.test.assert(this.cell_element_function(int_text2.index, int_text2.query,
110 107 'val') == 25, 'Int textbox set to Python value.');
111 108
112 109 // Clear the int textbox value and then set it to 1 by emulating
113 110 // keyboard presses.
114 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
115 this.sendKeys(int_text_query, '1');
111 this.cell_element_function(int_text2.index, int_text2.query, 'val', ['']);
112 this.sendKeys(int_text2.query, '1');
116 113 });
117 114
118 this.wait(500); // Wait for change to execute in kernel
115 this.wait_for_widget(int_text2);
119 116
120 117 index = this.append_cell('print(intrange[0].value)\n');
121 118 this.execute_cell_then(index, function(index){
122 119 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
123 120 'Int textbox set int range value');
124 121
125 122 // Clear the int textbox value and then set it to 120 by emulating
126 123 // keyboard presses.
127 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
128 this.sendKeys(int_text_query, '120');
124 this.cell_element_function(int_text2.index, int_text2.query, 'val', ['']);
125 this.sendKeys(int_text2.query, '120');
129 126 });
130 127
131 this.wait(500); // Wait for change to execute in kernel
128 this.wait_for_widget(int_text2);
132 129
133 130 index = this.append_cell('print(intrange[0].value)\n');
134 131 this.execute_cell_then(index, function(index){
135 132 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
136 133 'Int textbox value bound');
137 134
138 135 // Clear the int textbox value and then set it to 'hello world' by
139 136 // emulating keyboard presses. 'hello world' should get filtered...
140 this.cell_element_function(intrange_index, int_text_query, 'val', ['']);
141 this.sendKeys(int_text_query, 'hello world');
137 this.cell_element_function(int_text2.index, int_text2.query, 'val', ['']);
138 this.sendKeys(int_text2.query, 'hello world');
142 139 });
143 140
144 this.wait(500); // Wait for change to execute in kernel
141 this.wait_for_widget(int_text2);
145 142
146 143 index = this.append_cell('print(intrange[0].value)\n');
147 144 this.execute_cell_then(index, function(index){
148 145 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
149 146 'Invalid int textbox characters ignored');
150 147 });
151 148 }); No newline at end of file
@@ -1,108 +1,108
1 1 // Test multicontainer 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 // Test tab view
10 10 var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs';
11 11 var multicontainer1_index = this.append_cell(
12 12 'multicontainer = widgets.TabWidget()\n' +
13 13 'page1 = widgets.TextWidget()\n' +
14 14 'page2 = widgets.TextWidget()\n' +
15 15 'page3 = widgets.TextWidget()\n' +
16 16 'multicontainer.children = [page1, page2, page3]\n' +
17 17 'display(multicontainer)\n' +
18 18 'multicontainer.selected_index = 0\n' +
19 19 'print("Success")\n');
20 20 this.execute_cell_then(multicontainer1_index, function(index){
21 21
22 22 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
23 23 'Create multicontainer cell executed with correct output. (1)');
24 24
25 25 this.test.assert(this.cell_element_exists(index,
26 26 '.widget-area .widget-subarea'),
27 27 'Widget subarea exists.');
28 28
29 29 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
30 30 'Widget tab list exists.');
31 31
32 32 this.test.assert(this.cell_element_exists(index, multicontainer1_query),
33 33 'First widget tab list exists.');
34 34
35 35 // JQuery selector is 1 based
36 36 this.click(multicontainer1_query + ' li:nth-child(2) a');
37 37 });
38 38
39 this.wait(500); // Wait for change to execute in kernel
39 this.wait_for_idle();
40 40
41 41 index = this.append_cell(
42 42 'print(multicontainer.selected_index)\n' +
43 43 'multicontainer.selected_index = 2'); // 0 based
44 44 this.execute_cell_then(index, function(index){
45 45 this.test.assertEquals(this.get_output_cell(index).text, '1\n', // 0 based
46 46 'selected_index property updated with tab change.');
47 47
48 48 // JQuery selector is 1 based
49 49 this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(1)', 'hasClass', ['active']),
50 50 "Tab 1 is not selected.");
51 51 this.test.assert(!this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(2)', 'hasClass', ['active']),
52 52 "Tab 2 is not selected.");
53 53 this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query + ' li:nth-child(3)', 'hasClass', ['active']),
54 54 "Tab 3 is selected.");
55 55 });
56 56
57 57 index = this.append_cell('multicontainer.set_title(1, "hello")\nprint("Success")'); // 0 based
58 58 this.execute_cell_then(index, function(index){
59 59 this.test.assert(this.cell_element_function(multicontainer1_index, multicontainer1_query +
60 60 ' li:nth-child(2) a', 'html') == 'hello',
61 61 'Tab page title set (after display).');
62 62 });
63 63
64 64 // Test accordion view
65 65 var multicontainer2_query = '.widget-area .widget-subarea .accordion';
66 66 var multicontainer2_index = this.append_cell(
67 67 'multicontainer = widgets.AccordionWidget()\n' +
68 68 'page1 = widgets.TextWidget()\n' +
69 69 'page2 = widgets.TextWidget()\n' +
70 70 'page3 = widgets.TextWidget()\n' +
71 71 'multicontainer.children = [page1, page2, page3]\n' +
72 72 'multicontainer.set_title(2, "good")\n' +
73 73 'display(multicontainer)\n' +
74 74 'multicontainer.selected_index = 0\n' +
75 75 'print("Success")\n');
76 76 this.execute_cell_then(multicontainer2_index, function(index){
77 77
78 78 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
79 79 'Create multicontainer cell executed with correct output. (2)');
80 80
81 81 this.test.assert(this.cell_element_exists(index,
82 82 '.widget-area .widget-subarea'),
83 83 'Widget subarea exists.');
84 84
85 85 this.test.assert(this.cell_element_exists(index, multicontainer2_query),
86 86 'Widget accordion exists.');
87 87
88 88 this.test.assert(this.cell_element_exists(index, multicontainer2_query +
89 89 ' .accordion-group:nth-child(1) .accordion-body'),
90 90 'First accordion page exists.');
91 91
92 92 // JQuery selector is 1 based
93 93 this.test.assert(this.cell_element_function(index, multicontainer2_query +
94 94 ' .accordion-group:nth-child(3) .accordion-heading .accordion-toggle',
95 95 'html')=='good', 'Accordion page title set (before display).');
96 96
97 97 // JQuery selector is 1 based
98 98 this.click(multicontainer2_query + ' .accordion-group:nth-child(2) .accordion-heading .accordion-toggle');
99 99 });
100 100
101 this.wait(500); // Wait for change to execute in kernel
101 this.wait_for_idle();
102 102
103 103 index = this.append_cell('print(multicontainer.selected_index)'); // 0 based
104 104 this.execute_cell_then(index, function(index){
105 105 this.test.assertEquals(this.get_output_cell(index).text, '1\n', // 0 based
106 106 'selected_index property updated with tab change.');
107 107 });
108 108 }); No newline at end of file
@@ -1,133 +1,133
1 1 // Test selection 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 combo_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group .widget-combo-btn';
10 10 var multibtn_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group[data-toggle="buttons-radio"]';
11 11 var radio_selector = '.widget-area .widget-subarea .widget-hbox .vbox';
12 12 var list_selector = '.widget-area .widget-subarea .widget-hbox .widget-listbox';
13 13
14 14 var selection_index;
15 15 var selection_values = 'abcd';
16 16 var check_state = function(context, index, state){
17 17 if (0 <= index && index < selection_values.length) {
18 18 var multibtn_state = context.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(' + (index + 1) + ')', 'hasClass', ['active']);
19 19 var radio_state = context.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(' + (index + 1) + ') input', 'prop', ['checked']);
20 20 var list_val = context.cell_element_function(selection_index, list_selector, 'val');
21 21 var combo_val = context.cell_element_function(selection_index, combo_selector, 'html');
22 22
23 23 var val = selection_values.charAt(index);
24 24 var list_state = (val == list_val);
25 25 var combo_state = (val == combo_val);
26 26
27 27 return multibtn_state == state &&
28 28 radio_state == state &&
29 29 list_state == state &&
30 30 combo_state == state;
31 31 }
32 32 return true;
33 33 };
34 34
35 35 var verify_selection = function(context, index){
36 36 for (var i = 0; i < selection_values.length; i++) {
37 37 if (!check_state(context, i, i==index)) {
38 38 return false;
39 39 }
40 40 }
41 41 return true;
42 42 };
43 43
44 44 //values=["' + selection_values + '"[i] for i in range(4)]
45 45 selection_index = this.append_cell(
46 46 'values=["' + selection_values + '"[i] for i in range(4)]\n' +
47 47 'selection = [widgets.DropdownWidget(values=values),\n' +
48 48 ' widgets.ToggleButtonsWidget(values=values),\n' +
49 49 ' widgets.RadioButtonsWidget(values=values),\n' +
50 50 ' widgets.SelectWidget(values=values)]\n' +
51 51 '[display(selection[i]) for i in range(4)]\n' +
52 52 'for widget in selection:\n' +
53 53 ' def handle_change(name,old,new):\n' +
54 54 ' for other_widget in selection:\n' +
55 55 ' other_widget.value = new\n' +
56 56 ' widget.on_trait_change(handle_change, "value")\n' +
57 57 'print("Success")\n');
58 58 this.execute_cell_then(selection_index, function(index){
59 59 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
60 60 'Create selection cell executed with correct output.');
61 61
62 62 this.test.assert(this.cell_element_exists(index,
63 63 '.widget-area .widget-subarea'),
64 64 'Widget subarea exists.');
65 65
66 66 this.test.assert(this.cell_element_exists(index, combo_selector),
67 67 'Widget combobox exists.');
68 68
69 69 this.test.assert(this.cell_element_exists(index, multibtn_selector),
70 70 'Widget multibutton exists.');
71 71
72 72 this.test.assert(this.cell_element_exists(index, radio_selector),
73 73 'Widget radio buttons exists.');
74 74
75 75 this.test.assert(this.cell_element_exists(index, list_selector),
76 76 'Widget list exists.');
77 77
78 78 // Verify that no items are selected.
79 79 this.test.assert(verify_selection(this, -1), 'No items selected.');
80 80 });
81 81
82 82 index = this.append_cell(
83 83 'for widget in selection:\n' +
84 84 ' widget.value = "a"\n' +
85 85 'print("Success")\n');
86 86 this.execute_cell_then(index, function(index){
87 87 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
88 88 'Python select item executed with correct output.');
89 89
90 90 // Verify that the first item is selected.
91 91 this.test.assert(verify_selection(this, 0), 'Python selected');
92 92
93 93 // Verify that selecting a radio button updates all of the others.
94 94 this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click');
95 95 });
96 this.wait(500);
96 this.wait_for_idle();
97 97 this.then(function () {
98 98 this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.');
99 99
100 100 // Verify that selecting a list option updates all of the others.
101 101 this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click');
102 102 });
103 this.wait(500);
103 this.wait_for_idle();
104 104 this.then(function () {
105 105 this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.');
106 106
107 107 // Verify that selecting a multibutton option updates all of the others.
108 108 this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click');
109 109 });
110 this.wait(500);
110 this.wait_for_idle();
111 111 this.then(function () {
112 112 this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.');
113 113
114 114 // Verify that selecting a combobox option updates all of the others.
115 115 this.cell_element_function(selection_index, '.widget-area .widget-subarea .widget-hbox-single .btn-group ul.dropdown-menu li:nth-child(3) a', 'click');
116 116 });
117 this.wait(500);
117 this.wait_for_idle();
118 118 this.then(function () {
119 119 this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.');
120 120 });
121 121
122 this.wait(500); // Wait for change to execute in kernel
122 this.wait_for_idle();
123 123
124 124 index = this.append_cell(
125 125 'for widget in selection:\n' +
126 126 ' widget.values = list(widget.values) + ["z"]\n' +
127 127 'selection[0].value = "z"');
128 128 this.execute_cell_then(index, function(index){
129 129
130 130 // Verify that selecting a combobox option updates all of the others.
131 131 this.test.assert(verify_selection(this, 4), 'Item added to selection widget.');
132 132 });
133 133 }); No newline at end of file
@@ -1,240 +1,261
1 1 //
2 2 // Utility functions for the HTML notebook's CasperJS tests.
3 3 //
4 4
5 5 // Get the URL of a notebook server on which to run tests.
6 6 casper.get_notebook_server = function () {
7 7 port = casper.cli.get("port")
8 8 port = (typeof port === 'undefined') ? '8888' : port;
9 9 return 'http://127.0.0.1:' + port
10 10 };
11 11
12 12 // Create and open a new notebook.
13 13 casper.open_new_notebook = function () {
14 14 var baseUrl = this.get_notebook_server();
15 15 this.start(baseUrl);
16 16 this.thenClick('button#new_notebook');
17 17 this.waitForPopup('');
18 18
19 19 this.withPopup('', function () {this.waitForSelector('.CodeMirror-code');});
20 20 this.then(function () {
21 21 // XXX: Kind of odd, the next line works for one test, but not when
22 22 // running multiple tests back-to-back, so we will just point the main
23 23 // casper browser to the same URL as the popup we just grabbed.
24 24
25 25 //this.page = this.popups[0];
26 26 this.open(this.popups[0].url);
27 27 });
28 28
29 29 // initially, the cells aren't created, so wait for them to appear
30 30 this.waitForSelector('.CodeMirror-code');
31 31 // and make sure the kernel has started
32 32 this.waitFor( this.kernel_running );
33 33 // track the IPython busy/idle state
34 34 this.thenEvaluate(function () {
35 35 $([IPython.events]).on('status_idle.Kernel',function () {
36 36 IPython._status = 'idle';
37 37 });
38 38 $([IPython.events]).on('status_busy.Kernel',function () {
39 39 IPython._status = 'busy';
40 40 });
41 41 });
42 42 };
43 43
44 44 // return whether or not the kernel is running
45 45 casper.kernel_running = function kernel_running() {
46 46 return this.evaluate(function kernel_running() {
47 47 return IPython.notebook.kernel.running;
48 48 });
49 49 };
50 50
51 51 // Shut down the current notebook's kernel.
52 52 casper.shutdown_current_kernel = function () {
53 53 this.thenEvaluate(function() {
54 54 IPython.notebook.kernel.kill();
55 55 });
56 56 };
57 57
58 58 // Delete created notebook.
59 59 casper.delete_current_notebook = function () {
60 60 this.thenEvaluate(function() {
61 61 var nbData = $('body').data();
62 62 var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
63 63 $.ajax(url, {
64 64 type: 'DELETE',
65 65 });
66 66 });
67 67 };
68 68
69 69 casper.wait_for_idle = function () {
70 70 this.waitFor(function () {
71 71 return this.evaluate(function () {
72 72 return IPython._status == 'idle';
73 73 });
74 74 });
75 75 };
76 76
77 77 // wait for the nth output in a given cell
78 78 casper.wait_for_output = function (cell_num, out_num) {
79 79 this.wait_for_idle();
80 80 out_num = out_num || 0;
81 81 this.then(function() {
82 82 this.waitFor(function (c, o) {
83 83 return this.evaluate(function get_output(c, o) {
84 84 var cell = IPython.notebook.get_cell(c);
85 85 return cell.output_area.outputs.length > o;
86 86 },
87 87 // pass parameter from the test suite js to the browser code js
88 88 {c : cell_num, o : out_num});
89 89 });
90 90 },
91 91 function then() { },
92 92 function timeout() {
93 93 this.echo("wait_for_output timed out!");
94 94 });
95 95 };
96 96
97 // wait for a widget msg que to reach 0
98 //
99 // Parameters
100 // ----------
101 // widget_info : object
102 // Object which contains info related to the widget. The model_id property
103 // is used to identify the widget.
104 casper.wait_for_widget = function (widget_info) {
105 this.waitFor(function () {
106 var pending = this.evaluate(function (m) {
107 return IPython.notebook.kernel.widget_manager.get_model(m).pending_msgs;
108 }, {m: widget_info.model_id});
109
110 if (pending == 0) {
111 return true;
112 } else {
113 return false;
114 }
115 });
116 }
117
97 118 // return an output of a given cell
98 119 casper.get_output_cell = function (cell_num, out_num) {
99 120 out_num = out_num || 0;
100 121 var result = casper.evaluate(function (c, o) {
101 122 var cell = IPython.notebook.get_cell(c);
102 123 return cell.output_area.outputs[o];
103 124 },
104 125 {c : cell_num, o : out_num});
105 126 if (!result) {
106 127 var num_outputs = casper.evaluate(function (c) {
107 128 var cell = IPython.notebook.get_cell(c);
108 129 return cell.output_area.outputs.length;
109 130 },
110 131 {c : cell_num});
111 132 this.test.assertTrue(false,
112 133 "Cell " + cell_num + " has no output #" + out_num + " (" + num_outputs + " total)"
113 134 );
114 135 } else {
115 136 return result;
116 137 }
117 138 };
118 139
119 140 // return the number of cells in the notebook
120 141 casper.get_cells_length = function () {
121 142 var result = casper.evaluate(function () {
122 143 return IPython.notebook.get_cells().length;
123 144 })
124 145 return result;
125 146 };
126 147
127 148 // Set the text content of a cell.
128 149 casper.set_cell_text = function(index, text){
129 150 this.evaluate(function (index, text) {
130 151 var cell = IPython.notebook.get_cell(index);
131 152 cell.set_text(text);
132 153 }, index, text);
133 154 };
134 155
135 156 // Inserts a cell at the bottom of the notebook
136 157 // Returns the new cell's index.
137 158 casper.insert_cell_at_bottom = function(cell_type){
138 159 if (cell_type===undefined) {
139 160 cell_type = 'code';
140 161 }
141 162
142 163 return this.evaluate(function (cell_type) {
143 164 var cell = IPython.notebook.insert_cell_at_bottom(cell_type);
144 165 return IPython.notebook.find_cell_index(cell);
145 166 }, cell_type);
146 167 };
147 168
148 169 // Insert a cell at the bottom of the notebook and set the cells text.
149 170 // Returns the new cell's index.
150 171 casper.append_cell = function(text, cell_type) {
151 172 var index = this.insert_cell_at_bottom(cell_type);
152 173 if (text !== undefined) {
153 174 this.set_cell_text(index, text);
154 175 }
155 176 return index;
156 177 };
157 178
158 179 // Asynchronously executes a cell by index.
159 180 // Returns the cell's index.
160 181 casper.execute_cell = function(index){
161 182 var that = this;
162 183 this.then(function(){
163 184 that.evaluate(function (index) {
164 185 var cell = IPython.notebook.get_cell(index);
165 186 cell.execute();
166 187 }, index);
167 188 });
168 189 return index;
169 190 };
170 191
171 192 // Synchronously executes a cell by index.
172 193 // Optionally accepts a then_callback parameter. then_callback will get called
173 194 // when the cell has finished executing.
174 195 // Returns the cell's index.
175 196 casper.execute_cell_then = function(index, then_callback) {
176 197 var return_val = this.execute_cell(index);
177 198
178 199 this.wait_for_idle();
179 200
180 201 var that = this;
181 202 this.then(function(){
182 203 if (then_callback!==undefined) {
183 204 then_callback.apply(that, [index]);
184 205 }
185 206 });
186 207
187 208 return return_val;
188 209 };
189 210
190 211 // Utility function that allows us to easily check if an element exists
191 212 // within a cell. Uses JQuery selector to look for the element.
192 213 casper.cell_element_exists = function(index, selector){
193 214 return casper.evaluate(function (index, selector) {
194 215 var $cell = IPython.notebook.get_cell(index).element;
195 216 return $cell.find(selector).length > 0;
196 217 }, index, selector);
197 218 };
198 219
199 220 // Utility function that allows us to execute a jQuery function on an
200 221 // element within a cell.
201 222 casper.cell_element_function = function(index, selector, function_name, function_args){
202 223 return casper.evaluate(function (index, selector, function_name, function_args) {
203 224 var $cell = IPython.notebook.get_cell(index).element;
204 225 var $el = $cell.find(selector);
205 226 return $el[function_name].apply($el, function_args);
206 227 }, index, selector, function_name, function_args);
207 228 };
208 229
209 230 // Wrap a notebook test to reduce boilerplate.
210 231 casper.notebook_test = function(test) {
211 232 this.open_new_notebook();
212 233 this.then(test);
213 234 //XXX: we get sporadic error messages when shutting down some of the tests.
214 235 // Since the entire server will go down at the end of running the test
215 236 // suite, it's ok for now to not try to shut anything down.
216 237 this.shutdown_current_kernel();
217 238
218 239 //XXX: the implementation of delete_current_notebook is currently broken
219 240 // it's not a big deal, since the notebook directory will be deleted on
220 241 // cleanup, but we should add tests for deleting the notebook separately
221 242 //this.delete_current_notebook();
222 243
223 244 // Run the browser automation.
224 245 this.run(function() {
225 246 this.test.done();
226 247 });
227 248 };
228 249
229 250 casper.options.waitTimeout=10000
230 251 casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
231 252 this.echo("Timeout for " + casper.get_notebook_server());
232 253 this.echo("Is the notebook server running?");
233 254 });
234 255
235 256 // Pass `console.log` calls from page JS to casper.
236 257 casper.printLog = function () {
237 258 this.on('remote.message', function(msg) {
238 259 this.echo('Remote message caught: ' + msg);
239 260 });
240 261 };
General Comments 0
You need to be logged in to leave comments. Login now