Show More
@@ -1,147 +1,108 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( |
|
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 float_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text'; |
|
9 | var float_text_query_2 = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text'; | |
10 |
|
10 | |||
11 | var float_index = this.append_cell( |
|
11 | var float_index = this.append_cell( | |
12 | 'float_widget = widgets.FloatTextWidget()\n' + |
|
12 | 'float_widget = widgets.FloatTextWidget()\n' + | |
13 | 'display(float_widget)\n' + |
|
13 | 'display(float_widget)\n' + | |
14 | 'float_widget.add_class("my-second-float-text")\n' + |
|
14 | 'float_widget.add_class("my-second-float-text")\n' + | |
15 | 'print("Success")\n'); |
|
15 | 'print("Success")\n'); | |
16 | this.execute_cell_then(float_index, function(index){ |
|
16 | this.execute_cell_then(float_index, function(index){ | |
17 |
|
17 | |||
18 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
18 | this.test.assert(this.get_output_cell(index).text == 'Success\n', | |
19 | 'Create float cell executed with correct output.'); |
|
19 | 'Create float 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, float_text_query_2), |
|
25 | this.test.assert(this.cell_element_exists(index, float_text_query_2), | |
26 | 'Widget float textbox exists.'); |
|
26 | 'Widget float textbox exists.'); | |
27 |
|
27 | |||
28 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); |
|
28 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); | |
29 | this.sendKeys(float_text_query_2, '1.05'); |
|
29 | this.sendKeys(float_text_query_2, '1.05'); | |
30 | }); |
|
30 | }); | |
31 |
|
31 | |||
32 | this.wait(500); // Wait for change to execute in kernel |
|
32 | this.wait(500); // Wait for change to execute in kernel | |
33 |
|
33 | |||
34 | index = this.append_cell('print(float_widget.value)\n'); |
|
34 | index = this.append_cell('print(float_widget.value)\n'); | |
35 | this.execute_cell_then(index, function(index){ |
|
35 | this.execute_cell_then(index, function(index){ | |
36 | this.test.assert(this.get_output_cell(index).text == '1.05\n', |
|
36 | this.test.assert(this.get_output_cell(index).text == '1.05\n', | |
37 | 'Float textbox value set.'); |
|
37 | 'Float textbox value set.'); | |
38 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); |
|
38 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); | |
39 | this.sendKeys(float_text_query_2, '123456789.0'); |
|
39 | this.sendKeys(float_text_query_2, '123456789.0'); | |
40 | }); |
|
40 | }); | |
41 |
|
41 | |||
42 | this.wait(500); // Wait for change to execute in kernel |
|
42 | this.wait(500); // Wait for change to execute in kernel | |
43 |
|
43 | |||
44 | index = this.append_cell('print(float_widget.value)\n'); |
|
44 | index = this.append_cell('print(float_widget.value)\n'); | |
45 | this.execute_cell_then(index, function(index){ |
|
45 | this.execute_cell_then(index, function(index){ | |
46 | this.test.assert(this.get_output_cell(index).text == '123456789.0\n', |
|
46 | this.test.assert(this.get_output_cell(index).text == '123456789.0\n', | |
47 | 'Long float textbox value set (probably triggers throttling).'); |
|
47 | 'Long float textbox value set (probably triggers throttling).'); | |
48 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); |
|
48 | this.cell_element_function(float_index, float_text_query_2, 'val', ['']); | |
49 | this.sendKeys(float_text_query_2, '12hello'); |
|
49 | this.sendKeys(float_text_query_2, '12hello'); | |
50 | }); |
|
50 | }); | |
51 |
|
51 | |||
52 | this.wait(500); // Wait for change to execute in kernel |
|
52 | this.wait(500); // Wait for change to execute in kernel | |
53 |
|
53 | |||
54 | index = this.append_cell('print(float_widget.value)\n'); |
|
54 | index = this.append_cell('print(float_widget.value)\n'); | |
55 | this.execute_cell_then(index, function(index){ |
|
55 | this.execute_cell_then(index, function(index){ | |
56 | this.test.assert(this.get_output_cell(index).text == '12.0\n', |
|
56 | this.test.assert(this.get_output_cell(index).text == '12.0\n', | |
57 | 'Invald float textbox value caught and filtered.'); |
|
57 | 'Invald float textbox value caught and filtered.'); | |
58 | }); |
|
58 | }); | |
59 |
|
59 | |||
60 | index = this.append_cell( |
|
60 | index = this.append_cell( | |
61 | 'from IPython.html import widgets\n' + |
|
61 | 'from IPython.html import widgets\n' + | |
62 | 'from IPython.display import display, clear_output\n' + |
|
62 | 'from IPython.display import display, clear_output\n' + | |
63 | 'print("Success")'); |
|
63 | 'print("Success")'); | |
64 | this.execute_cell_then(index); |
|
64 | this.execute_cell_then(index); | |
65 |
|
65 | |||
66 | var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider'; |
|
66 | var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider'; | |
67 | var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text'; |
|
67 | var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text'; | |
68 |
|
68 | |||
69 | var floatrange_index = this.append_cell( |
|
69 | var floatrange_index = this.append_cell( | |
70 | 'floatrange = [widgets.BoundedFloatTextWidget(), \n' + |
|
70 | 'floatrange = [widgets.BoundedFloatTextWidget(), \n' + | |
71 | ' widgets.FloatSliderWidget()]\n' + |
|
71 | ' widgets.FloatSliderWidget()]\n' + | |
72 | '[display(floatrange[i]) for i in range(2)]\n' + |
|
72 | '[display(floatrange[i]) for i in range(2)]\n' + | |
73 | 'print("Success")\n'); |
|
73 | 'print("Success")\n'); | |
74 | this.execute_cell_then(floatrange_index, function(index){ |
|
74 | this.execute_cell_then(floatrange_index, function(index){ | |
75 |
|
75 | |||
76 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
76 | this.test.assert(this.get_output_cell(index).text == 'Success\n', | |
77 | 'Create float range cell executed with correct output.'); |
|
77 | 'Create float range cell executed with correct output.'); | |
78 |
|
78 | |||
79 | this.test.assert(this.cell_element_exists(index, |
|
79 | this.test.assert(this.cell_element_exists(index, | |
80 | '.widget-area .widget-subarea'), |
|
80 | '.widget-area .widget-subarea'), | |
81 | 'Widget subarea exists.'); |
|
81 | 'Widget subarea exists.'); | |
82 |
|
82 | |||
83 | this.test.assert(this.cell_element_exists(index, slider_query), |
|
83 | this.test.assert(this.cell_element_exists(index, slider_query), | |
84 | 'Widget slider exists.'); |
|
84 | 'Widget slider exists.'); | |
85 |
|
85 | |||
86 | this.test.assert(this.cell_element_exists(index, float_text_query), |
|
86 | this.test.assert(this.cell_element_exists(index, float_text_query), | |
87 | 'Widget float textbox exists.'); |
|
87 | 'Widget float textbox exists.'); | |
88 | }); |
|
88 | }); | |
89 |
|
89 | |||
90 | index = this.append_cell( |
|
90 | index = this.append_cell( | |
91 | 'for widget in floatrange:\n' + |
|
91 | 'for widget in floatrange:\n' + | |
92 | ' widget.max = 50.0\n' + |
|
92 | ' widget.max = 50.0\n' + | |
93 | ' widget.min = -50.0\n' + |
|
93 | ' widget.min = -50.0\n' + | |
94 |
' widget.value = 2 |
|
94 | ' widget.value = 25.0\n' + | |
95 | 'print("Success")\n'); |
|
95 | 'print("Success")\n'); | |
96 | this.execute_cell_then(index, function(index){ |
|
96 | this.execute_cell_then(index, function(index){ | |
97 |
|
97 | |||
98 | this.test.assert(this.get_output_cell(index).text == 'Success\n', |
|
98 | this.test.assert(this.get_output_cell(index).text == 'Success\n', | |
99 | 'Float range properties cell executed with correct output.'); |
|
99 | 'Float range properties cell executed with correct output.'); | |
100 |
|
100 | |||
101 | this.test.assert(this.cell_element_exists(floatrange_index, slider_query), |
|
101 | this.test.assert(this.cell_element_exists(floatrange_index, slider_query), | |
102 | 'Widget slider exists.'); |
|
102 | 'Widget slider exists.'); | |
103 |
|
103 | |||
104 | this.test.assert(this.cell_element_function(floatrange_index, slider_query, |
|
104 | this.test.assert(this.cell_element_function(floatrange_index, slider_query, | |
105 |
'slider', ['value']) == 2 |
|
105 | 'slider', ['value']) == 25.0, | |
106 | 'Slider set to Python value.'); |
|
106 | 'Slider set to Python value.'); | |
107 |
|
||||
108 | // Clear the float textbox value and then set it to 1 by emulating |
|
|||
109 | // keyboard presses. |
|
|||
110 | this.cell_element_function(floatrange_index, float_text_query, 'val', ['']); |
|
|||
111 | this.sendKeys(float_text_query, '1'); |
|
|||
112 | }); |
|
|||
113 |
|
||||
114 | this.wait(1500); // Wait for change to execute in kernel |
|
|||
115 |
|
||||
116 | index = this.append_cell('for widget in floatrange:\n print(widget.value)\n'); |
|
|||
117 | this.execute_cell_then(index, function(index){ |
|
|||
118 | this.test.assert(this.get_output_cell(index).text == '1.0\n20.0\n', |
|
|||
119 | 'Float textbox set float range value'); |
|
|||
120 |
|
||||
121 | // Clear the float textbox value and then set it to 120 by emulating |
|
|||
122 | // keyboard presses. |
|
|||
123 | this.cell_element_function(floatrange_index, float_text_query, 'val', ['']); |
|
|||
124 | this.sendKeys(float_text_query, '120'); |
|
|||
125 | }); |
|
|||
126 |
|
||||
127 | this.wait(500); // Wait for change to execute in kernel |
|
|||
128 |
|
||||
129 | index = this.append_cell('print(floatrange[0].value)\n'); |
|
|||
130 | this.execute_cell_then(index, function(index){ |
|
|||
131 | this.test.assert(this.get_output_cell(index).text == '50.0\n', |
|
|||
132 | 'Float textbox value bound'); |
|
|||
133 |
|
||||
134 | // Clear the float textbox value and then set it to 'hello world' by |
|
|||
135 | // emulating keyboard presses. 'hello world' should get filtered... |
|
|||
136 | this.cell_element_function(floatrange_index, float_text_query, 'val', ['']); |
|
|||
137 | this.sendKeys(float_text_query, 'hello world'); |
|
|||
138 | }); |
|
|||
139 |
|
||||
140 | this.wait(500); // Wait for change to execute in kernel |
|
|||
141 |
|
||||
142 | index = this.append_cell('print(floatrange[0].value)\n'); |
|
|||
143 | this.execute_cell_then(index, function(index){ |
|
|||
144 | this.test.assert(this.get_output_cell(index).text == '50.0\n', |
|
|||
145 | 'Invalid float textbox characters ignored'); |
|
|||
146 | }); |
|
107 | }); | |
147 | }); No newline at end of file |
|
108 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now