##// END OF EJS Templates
Merge pull request #4952 from jdfreder/widget-tests...
Min RK -
r15050:3457a5d7 merge
parent child Browse files
Show More
@@ -16,8 +16,6 b' casper.notebook_test(function () {'
16 16 'print("Success")');
17 17 this.execute_cell_then(index);
18 18
19 this.wait(500); // Wait for require.js async callbacks to load dependencies.
20
21 19 this.then(function () {
22 20 // Check if the widget manager has been instantiated.
23 21 this.test.assert(this.evaluate(function() {
@@ -25,6 +23,7 b' casper.notebook_test(function () {'
25 23 }), 'Notebook widget manager instantiated');
26 24 });
27 25
26 var textbox = {};
28 27 throttle_index = this.append_cell(
29 28 'import time\n' +
30 29 'textbox = widgets.TextWidget()\n' +
@@ -34,10 +33,9 b' casper.notebook_test(function () {'
34 33 ' print(len(new))\n' +
35 34 ' time.sleep(0.5)\n' +
36 35 'textbox.on_trait_change(handle_change, "value")\n' +
37 'print("Success")');
36 'print(textbox.model_id)');
38 37 this.execute_cell_then(throttle_index, function(index){
39 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
40 'Test throttling cell executed with correct output');
38 textbox.model_id = this.get_output_cell(index).text.trim();
41 39
42 40 this.test.assert(this.cell_element_exists(index,
43 41 '.widget-area .widget-subarea'),
@@ -50,7 +48,7 b' casper.notebook_test(function () {'
50 48 this.sendKeys('.my-throttle-textbox', '....................');
51 49 });
52 50
53 this.wait(2000); // Wait for clicks to execute in kernel
51 this.wait_for_widget(textbox);
54 52
55 53 this.then(function(){
56 54 var outputs = this.evaluate(function(i) {
@@ -34,7 +34,7 b' casper.notebook_test(function () {'
34 34 '.widget-area .widget-subarea button', 'click');
35 35 });
36 36
37 this.wait(500); // Wait for click to execute in kernel and write output
37 this.wait_for_output(button_index, 1);
38 38
39 39 this.then(function () {
40 40 this.test.assertEquals(this.get_output_cell(button_index, 1).text, 'Clicked\n',
@@ -6,50 +6,48 b' casper.notebook_test(function () {'
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){
@@ -57,21 +55,15 b' casper.notebook_test(function () {'
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.');
@@ -80,7 +72,7 b' casper.notebook_test(function () {'
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),
@@ -98,10 +90,10 b' casper.notebook_test(function () {'
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 });
@@ -6,50 +6,48 b' casper.notebook_test(function () {'
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){
@@ -63,19 +61,18 b' casper.notebook_test(function () {'
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'),
@@ -84,7 +81,7 b' casper.notebook_test(function () {'
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
@@ -99,23 +96,23 b' casper.notebook_test(function () {'
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){
@@ -124,11 +121,11 b' casper.notebook_test(function () {'
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){
@@ -137,11 +134,11 b' casper.notebook_test(function () {'
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){
@@ -36,7 +36,7 b' casper.notebook_test(function () {'
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' +
@@ -98,7 +98,7 b' casper.notebook_test(function () {'
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){
@@ -93,33 +93,33 b' casper.notebook_test(function () {'
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' +
@@ -38,13 +38,6 b' casper.notebook_test(function () {'
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.');
@@ -94,6 +94,27 b' casper.wait_for_output = function (cell_num, out_num) {'
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;
General Comments 0
You need to be logged in to leave comments. Login now