##// END OF EJS Templates
Merge pull request #6650 from jdfreder/widg_int_test...
Min RK -
r18194:3c12ada1 merge
parent child Browse files
Show More
@@ -1,175 +1,175 b''
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 9 var int_text = {};
10 10 int_text.query = '.widget-area .widget-subarea .my-second-int-text input';
11 11 int_text.index = this.append_cell(
12 12 'int_widget = widgets.IntText()\n' +
13 13 'display(int_widget)\n' +
14 14 'int_widget._dom_classes = ["my-second-int-text"]\n' +
15 15 'print(int_widget.model_id)\n');
16 16 this.execute_cell_then(int_text.index, function(index){
17 17 int_text.model_id = this.get_output_cell(index).text.trim();
18 18
19 19 this.test.assert(this.cell_element_exists(index,
20 20 '.widget-area .widget-subarea'),
21 21 'Widget subarea exists.');
22 22
23 23 this.test.assert(this.cell_element_exists(index, int_text.query),
24 24 'Widget int textbox exists.');
25 25
26 26 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
27 27 this.sendKeys(int_text.query, '1.05');
28 28 });
29 29
30 30 this.wait_for_widget(int_text);
31 31
32 32 index = this.append_cell('print(int_widget.value)\n');
33 33 this.execute_cell_then(index, function(index){
34 34 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
35 35 'Int textbox value set.');
36 36 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
37 37 this.sendKeys(int_text.query, '123456789');
38 38 });
39 39
40 40 this.wait_for_widget(int_text);
41 41
42 42 index = this.append_cell('print(int_widget.value)\n');
43 43 this.execute_cell_then(index, function(index){
44 44 this.test.assertEquals(this.get_output_cell(index).text, '123456789\n',
45 45 'Long int textbox value set (probably triggers throttling).');
46 46 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
47 47 this.sendKeys(int_text.query, '12hello');
48 48 });
49 49
50 50 this.wait_for_widget(int_text);
51 51
52 52 index = this.append_cell('print(int_widget.value)\n');
53 53 this.execute_cell_then(index, function(index){
54 54 this.test.assertEquals(this.get_output_cell(index).text, '12\n',
55 55 'Invald int textbox value caught and filtered.');
56 56 });
57 57
58 58 index = this.append_cell(
59 59 'from IPython.html import widgets\n' +
60 60 'from IPython.display import display, clear_output\n' +
61 61 'print("Success")');
62 62 this.execute_cell_then(index);
63 63
64 64
65 65 var slider_query = '.widget-area .widget-subarea .slider';
66 66 var int_text2 = {};
67 67 int_text2.query = '.widget-area .widget-subarea .my-second-num-test-text input';
68 68 int_text2.index = this.append_cell(
69 69 'intrange = [widgets.BoundedIntTextWidget(),\n' +
70 70 ' widgets.IntSliderWidget()]\n' +
71 71 '[display(intrange[i]) for i in range(2)]\n' +
72 72 'intrange[0]._dom_classes = ["my-second-num-test-text"]\n' +
73 73 'print(intrange[0].model_id)\n');
74 74 this.execute_cell_then(int_text2.index, function(index){
75 75 int_text2.model_id = this.get_output_cell(index).text.trim();
76 76
77 77 this.test.assert(this.cell_element_exists(index,
78 78 '.widget-area .widget-subarea'),
79 79 'Widget subarea exists.');
80 80
81 81 this.test.assert(this.cell_element_exists(index, slider_query),
82 82 'Widget slider exists.');
83 83
84 84 this.test.assert(this.cell_element_exists(index, int_text2.query),
85 85 'Widget int textbox exists.');
86 86 });
87 87
88 88 index = this.append_cell(
89 89 'for widget in intrange:\n' +
90 90 ' widget.max = 50\n' +
91 91 ' widget.min = -50\n' +
92 92 ' widget.value = 25\n' +
93 93 'print("Success")\n');
94 94 this.execute_cell_then(index, function(index){
95 95
96 96 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
97 97 'Int range properties cell executed with correct output.');
98 98
99 99 this.test.assert(this.cell_element_exists(int_text2.index, slider_query),
100 100 'Widget slider exists.');
101 101
102 102 this.test.assert(this.cell_element_function(int_text2.index, slider_query,
103 103 'slider', ['value']) == 25,
104 104 'Slider set to Python value.');
105 105
106 106 this.test.assert(this.cell_element_function(int_text2.index, int_text2.query,
107 107 'val') == 25, 'Int textbox set to Python value.');
108 108
109 109 // Clear the int textbox value and then set it to 1 by emulating
110 110 // keyboard presses.
111 111 this.evaluate(function(q){
112 112 var textbox = IPython.notebook.element.find(q);
113 113 textbox.val('1');
114 114 textbox.trigger('keyup');
115 115 }, {q: int_text2.query});
116 116 });
117 117
118 118 this.wait_for_widget(int_text2);
119 119
120 120 index = this.append_cell('print(intrange[0].value)\n');
121 121 this.execute_cell_then(index, function(index){
122 122 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
123 123 'Int textbox set int range value');
124 124
125 125 // Clear the int textbox value and then set it to 120 by emulating
126 126 // keyboard presses.
127 127 this.evaluate(function(q){
128 128 var textbox = IPython.notebook.element.find(q);
129 129 textbox.val('120');
130 130 textbox.trigger('keyup');
131 131 }, {q: int_text2.query});
132 132 });
133 133
134 134 this.wait_for_widget(int_text2);
135 135
136 136 index = this.append_cell('print(intrange[0].value)\n');
137 137 this.execute_cell_then(index, function(index){
138 138 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
139 139 'Int textbox value bound');
140 140
141 141 // Clear the int textbox value and then set it to 'hello world' by
142 142 // emulating keyboard presses. 'hello world' should get filtered...
143 143 this.evaluate(function(q){
144 144 var textbox = IPython.notebook.element.find(q);
145 145 textbox.val('hello world');
146 146 textbox.trigger('keyup');
147 147 }, {q: int_text2.query});
148 148 });
149 149
150 150 this.wait_for_widget(int_text2);
151 151
152 152 index = this.append_cell('print(intrange[0].value)\n');
153 153 this.execute_cell_then(index, function(index){
154 154 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
155 155 'Invalid int textbox characters ignored');
156 156 });
157 157
158 158 index = this.append_cell(
159 159 'a = widgets.IntSlider()\n' +
160 160 'display(a)\n' +
161 161 'a.max = -1\n' +
162 162 'print("Success")\n');
163 163 this.execute_cell_then(index, function(index){
164 164 this.test.assertEquals(0, 0, 'Invalid int range max bound does not cause crash.');
165 });
165 }, true);
166 166
167 167 index = this.append_cell(
168 168 'a = widgets.IntSlider()\n' +
169 169 'display(a)\n' +
170 170 'a.min = 101\n' +
171 171 'print("Success")\n');
172 172 this.execute_cell_then(index, function(index){
173 173 this.test.assertEquals(0, 0, 'Invalid int range min bound does not cause crash.');
174 });
174 }, true);
175 175 }); No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now