##// END OF EJS Templates
Fix js-tests for new default selector logic.
Jonathan Frederic -
Show More
@@ -1,188 +1,188 b''
1 var xor = function (a, b) {return !a ^ !b;};
1 var xor = function (a, b) {return !a ^ !b;};
2 var isArray = function (a) {
2 var isArray = function (a) {
3 try {
3 try {
4 return Object.toString.call(a) === "[object Array]" || Object.toString.call(a) === "[object RuntimeArray]";
4 return Object.toString.call(a) === "[object Array]" || Object.toString.call(a) === "[object RuntimeArray]";
5 } catch (e) {
5 } catch (e) {
6 return Array.isArray(a);
6 return Array.isArray(a);
7 }
7 }
8 };
8 };
9 var recursive_compare = function(a, b) {
9 var recursive_compare = function(a, b) {
10 // Recursively compare two objects.
10 // Recursively compare two objects.
11 var same = true;
11 var same = true;
12 same = same && !xor(a instanceof Object || typeof a == 'object', b instanceof Object || typeof b == 'object');
12 same = same && !xor(a instanceof Object || typeof a == 'object', b instanceof Object || typeof b == 'object');
13 same = same && !xor(isArray(a), isArray(b));
13 same = same && !xor(isArray(a), isArray(b));
14
14
15 if (same) {
15 if (same) {
16 if (a instanceof Object) {
16 if (a instanceof Object) {
17 var key;
17 var key;
18 for (key in a) {
18 for (key in a) {
19 if (a.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
19 if (a.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
20 same = false;
20 same = false;
21 break;
21 break;
22 }
22 }
23 }
23 }
24 for (key in b) {
24 for (key in b) {
25 if (b.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
25 if (b.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
26 same = false;
26 same = false;
27 break;
27 break;
28 }
28 }
29 }
29 }
30 } else {
30 } else {
31 return a === b;
31 return a === b;
32 }
32 }
33 }
33 }
34
34
35 return same;
35 return same;
36 };
36 };
37
37
38 // Test the widget framework.
38 // Test the widget framework.
39 casper.notebook_test(function () {
39 casper.notebook_test(function () {
40 var index;
40 var index;
41
41
42 this.then(function () {
42 this.then(function () {
43
43
44 // Check if the WidgetManager class is defined.
44 // Check if the WidgetManager class is defined.
45 this.test.assert(this.evaluate(function() {
45 this.test.assert(this.evaluate(function() {
46 return IPython.WidgetManager !== undefined;
46 return IPython.WidgetManager !== undefined;
47 }), 'WidgetManager class is defined');
47 }), 'WidgetManager class is defined');
48 });
48 });
49
49
50 index = this.append_cell(
50 index = this.append_cell(
51 'from IPython.html import widgets\n' +
51 'from IPython.html import widgets\n' +
52 'from IPython.display import display, clear_output\n' +
52 'from IPython.display import display, clear_output\n' +
53 'print("Success")');
53 'print("Success")');
54 this.execute_cell_then(index);
54 this.execute_cell_then(index);
55
55
56 this.then(function () {
56 this.then(function () {
57 // Check if the widget manager has been instantiated.
57 // Check if the widget manager has been instantiated.
58 this.test.assert(this.evaluate(function() {
58 this.test.assert(this.evaluate(function() {
59 return IPython.notebook.kernel.widget_manager !== undefined;
59 return IPython.notebook.kernel.widget_manager !== undefined;
60 }), 'Notebook widget manager instantiated');
60 }), 'Notebook widget manager instantiated');
61
61
62 // Functions that can be used to test the packing and unpacking APIs
62 // Functions that can be used to test the packing and unpacking APIs
63 var that = this;
63 var that = this;
64 var test_pack = function (input) {
64 var test_pack = function (input) {
65 var output = that.evaluate(function(input) {
65 var output = that.evaluate(function(input) {
66 var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
66 var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
67 var results = model._pack_models(input);
67 var results = model._pack_models(input);
68 return results;
68 return results;
69 }, {input: input});
69 }, {input: input});
70 that.test.assert(recursive_compare(input, output),
70 that.test.assert(recursive_compare(input, output),
71 JSON.stringify(input) + ' passed through Model._pack_model unchanged');
71 JSON.stringify(input) + ' passed through Model._pack_model unchanged');
72 };
72 };
73 var test_unpack = function (input) {
73 var test_unpack = function (input) {
74 var output = that.evaluate(function(input) {
74 var output = that.evaluate(function(input) {
75 var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
75 var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
76 var results = model._unpack_models(input);
76 var results = model._unpack_models(input);
77 return results;
77 return results;
78 }, {input: input});
78 }, {input: input});
79 that.test.assert(recursive_compare(input, output),
79 that.test.assert(recursive_compare(input, output),
80 JSON.stringify(input) + ' passed through Model._unpack_model unchanged');
80 JSON.stringify(input) + ' passed through Model._unpack_model unchanged');
81 };
81 };
82 var test_packing = function(input) {
82 var test_packing = function(input) {
83 test_pack(input);
83 test_pack(input);
84 test_unpack(input);
84 test_unpack(input);
85 };
85 };
86
86
87 test_packing({0: 'hi', 1: 'bye'});
87 test_packing({0: 'hi', 1: 'bye'});
88 test_packing(['hi', 'bye']);
88 test_packing(['hi', 'bye']);
89 test_packing(['hi', 5]);
89 test_packing(['hi', 5]);
90 test_packing(['hi', '5']);
90 test_packing(['hi', '5']);
91 test_packing([1.0, 0]);
91 test_packing([1.0, 0]);
92 test_packing([1.0, false]);
92 test_packing([1.0, false]);
93 test_packing([1, false]);
93 test_packing([1, false]);
94 test_packing([1, false, {a: 'hi'}]);
94 test_packing([1, false, {a: 'hi'}]);
95 test_packing([1, false, ['hi']]);
95 test_packing([1, false, ['hi']]);
96
96
97 // Test multi-set, single touch code. First create a custom widget.
97 // Test multi-set, single touch code. First create a custom widget.
98 this.evaluate(function() {
98 this.evaluate(function() {
99 var MultiSetView = IPython.DOMWidgetView.extend({
99 var MultiSetView = IPython.DOMWidgetView.extend({
100 render: function(){
100 render: function(){
101 this.model.set('a', 1);
101 this.model.set('a', 1);
102 this.model.set('b', 2);
102 this.model.set('b', 2);
103 this.model.set('c', 3);
103 this.model.set('c', 3);
104 this.touch();
104 this.touch();
105 },
105 },
106 });
106 });
107 IPython.WidgetManager.register_widget_view('MultiSetView', MultiSetView);
107 IPython.WidgetManager.register_widget_view('MultiSetView', MultiSetView);
108 }, {});
108 }, {});
109 });
109 });
110
110
111 // Try creating the multiset widget, verify that sets the values correctly.
111 // Try creating the multiset widget, verify that sets the values correctly.
112 var multiset = {};
112 var multiset = {};
113 multiset.index = this.append_cell(
113 multiset.index = this.append_cell(
114 'from IPython.utils.traitlets import Unicode, CInt\n' +
114 'from IPython.utils.traitlets import Unicode, CInt\n' +
115 'class MultiSetWidget(widgets.Widget):\n' +
115 'class MultiSetWidget(widgets.Widget):\n' +
116 ' _view_name = Unicode("MultiSetView", sync=True)\n' +
116 ' _view_name = Unicode("MultiSetView", sync=True)\n' +
117 ' a = CInt(0, sync=True)\n' +
117 ' a = CInt(0, sync=True)\n' +
118 ' b = CInt(0, sync=True)\n' +
118 ' b = CInt(0, sync=True)\n' +
119 ' c = CInt(0, sync=True)\n' +
119 ' c = CInt(0, sync=True)\n' +
120 ' d = CInt(-1, sync=True)\n' + // See if it sends a full state.
120 ' d = CInt(-1, sync=True)\n' + // See if it sends a full state.
121 ' def _handle_receive_state(self, sync_data):\n' +
121 ' def _handle_receive_state(self, sync_data):\n' +
122 ' widgets.Widget._handle_receive_state(self, sync_data)\n'+
122 ' widgets.Widget._handle_receive_state(self, sync_data)\n'+
123 ' self.d = len(sync_data)\n' +
123 ' self.d = len(sync_data)\n' +
124 'multiset = MultiSetWidget()\n' +
124 'multiset = MultiSetWidget()\n' +
125 'display(multiset)\n' +
125 'display(multiset)\n' +
126 'print(multiset.model_id)');
126 'print(multiset.model_id)');
127 this.execute_cell_then(multiset.index, function(index) {
127 this.execute_cell_then(multiset.index, function(index) {
128 multiset.model_id = this.get_output_cell(index).text.trim();
128 multiset.model_id = this.get_output_cell(index).text.trim();
129 });
129 });
130
130
131 this.wait_for_widget(multiset);
131 this.wait_for_widget(multiset);
132
132
133 index = this.append_cell(
133 index = this.append_cell(
134 'print("%d%d%d" % (multiset.a, multiset.b, multiset.c))');
134 'print("%d%d%d" % (multiset.a, multiset.b, multiset.c))');
135 this.execute_cell_then(index, function(index) {
135 this.execute_cell_then(index, function(index) {
136 this.test.assertEquals(this.get_output_cell(index).text.trim(), '123',
136 this.test.assertEquals(this.get_output_cell(index).text.trim(), '123',
137 'Multiple model.set calls and one view.touch update state in back-end.');
137 'Multiple model.set calls and one view.touch update state in back-end.');
138 });
138 });
139
139
140 index = this.append_cell(
140 index = this.append_cell(
141 'print("%d" % (multiset.d))');
141 'print("%d" % (multiset.d))');
142 this.execute_cell_then(index, function(index) {
142 this.execute_cell_then(index, function(index) {
143 this.test.assertEquals(this.get_output_cell(index).text.trim(), '3',
143 this.test.assertEquals(this.get_output_cell(index).text.trim(), '3',
144 'Multiple model.set calls sent a partial state.');
144 'Multiple model.set calls sent a partial state.');
145 });
145 });
146
146
147 var textbox = {};
147 var textbox = {};
148 throttle_index = this.append_cell(
148 throttle_index = this.append_cell(
149 'import time\n' +
149 'import time\n' +
150 'textbox = widgets.TextWidget()\n' +
150 'textbox = widgets.TextWidget()\n' +
151 'display(textbox)\n' +
151 'display(textbox)\n' +
152 'textbox.add_class("my-throttle-textbox")\n' +
152 'textbox.add_class("my-throttle-textbox", selector="input")\n' +
153 'def handle_change(name, old, new):\n' +
153 'def handle_change(name, old, new):\n' +
154 ' display(len(new))\n' +
154 ' display(len(new))\n' +
155 ' time.sleep(0.5)\n' +
155 ' time.sleep(0.5)\n' +
156 'textbox.on_trait_change(handle_change, "value")\n' +
156 'textbox.on_trait_change(handle_change, "value")\n' +
157 'print(textbox.model_id)');
157 'print(textbox.model_id)');
158 this.execute_cell_then(throttle_index, function(index){
158 this.execute_cell_then(throttle_index, function(index){
159 textbox.model_id = this.get_output_cell(index).text.trim();
159 textbox.model_id = this.get_output_cell(index).text.trim();
160
160
161 this.test.assert(this.cell_element_exists(index,
161 this.test.assert(this.cell_element_exists(index,
162 '.widget-area .widget-subarea'),
162 '.widget-area .widget-subarea'),
163 'Widget subarea exists.');
163 'Widget subarea exists.');
164
164
165 this.test.assert(this.cell_element_exists(index,
165 this.test.assert(this.cell_element_exists(index,
166 '.my-throttle-textbox'), 'Textbox exists.');
166 '.my-throttle-textbox'), 'Textbox exists.');
167
167
168 // Send 20 characters
168 // Send 20 characters
169 this.sendKeys('.my-throttle-textbox', '....................');
169 this.sendKeys('.my-throttle-textbox', '....................');
170 });
170 });
171
171
172 this.wait_for_widget(textbox);
172 this.wait_for_widget(textbox);
173
173
174 this.then(function () {
174 this.then(function () {
175 var outputs = this.evaluate(function(i) {
175 var outputs = this.evaluate(function(i) {
176 return IPython.notebook.get_cell(i).output_area.outputs;
176 return IPython.notebook.get_cell(i).output_area.outputs;
177 }, {i : throttle_index});
177 }, {i : throttle_index});
178
178
179 // Only 4 outputs should have printed, but because of timing, sometimes
179 // Only 4 outputs should have printed, but because of timing, sometimes
180 // 5 outputs will print. All we need to do is verify num outputs <= 5
180 // 5 outputs will print. All we need to do is verify num outputs <= 5
181 // because that is much less than 20.
181 // because that is much less than 20.
182 this.test.assert(outputs.length <= 5, 'Messages throttled.');
182 this.test.assert(outputs.length <= 5, 'Messages throttled.');
183
183
184 // We also need to verify that the last state sent was correct.
184 // We also need to verify that the last state sent was correct.
185 var last_state = outputs[outputs.length-1]['text/plain'];
185 var last_state = outputs[outputs.length-1]['text/plain'];
186 this.test.assertEquals(last_state, "20", "Last state sent when throttling.");
186 this.test.assertEquals(last_state, "20", "Last state sent when throttling.");
187 });
187 });
188 });
188 });
@@ -1,100 +1,100 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 = {};
9 var float_text = {};
10 float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
10 float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
11 float_text.index = this.append_cell(
11 float_text.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", selector="input")\n' +
15 'print(float_widget.model_id)\n');
15 'print(float_widget.model_id)\n');
16 this.execute_cell_then(float_text.index, function(index){
16 this.execute_cell_then(float_text.index, function(index){
17 float_text.model_id = this.get_output_cell(index).text.trim();
17 float_text.model_id = this.get_output_cell(index).text.trim();
18
18
19 this.test.assert(this.cell_element_exists(index,
19 this.test.assert(this.cell_element_exists(index,
20 '.widget-area .widget-subarea'),
20 '.widget-area .widget-subarea'),
21 'Widget subarea exists.');
21 'Widget subarea exists.');
22
22
23 this.test.assert(this.cell_element_exists(index, float_text.query),
23 this.test.assert(this.cell_element_exists(index, float_text.query),
24 'Widget float textbox exists.');
24 'Widget float textbox exists.');
25
25
26 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
26 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
27 this.sendKeys(float_text.query, '1.05');
27 this.sendKeys(float_text.query, '1.05');
28 });
28 });
29
29
30 this.wait_for_widget(float_text);
30 this.wait_for_widget(float_text);
31
31
32 index = this.append_cell('print(float_widget.value)\n');
32 index = this.append_cell('print(float_widget.value)\n');
33 this.execute_cell_then(index, function(index){
33 this.execute_cell_then(index, function(index){
34 this.test.assertEquals(this.get_output_cell(index).text, '1.05\n',
34 this.test.assertEquals(this.get_output_cell(index).text, '1.05\n',
35 'Float textbox value set.');
35 'Float textbox value set.');
36 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
36 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
37 this.sendKeys(float_text.query, '123456789.0');
37 this.sendKeys(float_text.query, '123456789.0');
38 });
38 });
39
39
40 this.wait_for_widget(float_text);
40 this.wait_for_widget(float_text);
41
41
42 index = this.append_cell('print(float_widget.value)\n');
42 index = this.append_cell('print(float_widget.value)\n');
43 this.execute_cell_then(index, function(index){
43 this.execute_cell_then(index, function(index){
44 this.test.assertEquals(this.get_output_cell(index).text, '123456789.0\n',
44 this.test.assertEquals(this.get_output_cell(index).text, '123456789.0\n',
45 'Long float textbox value set (probably triggers throttling).');
45 'Long float textbox value set (probably triggers throttling).');
46 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
46 this.cell_element_function(float_text.index, float_text.query, 'val', ['']);
47 this.sendKeys(float_text.query, '12hello');
47 this.sendKeys(float_text.query, '12hello');
48 });
48 });
49
49
50 this.wait_for_widget(float_text);
50 this.wait_for_widget(float_text);
51
51
52 index = this.append_cell('print(float_widget.value)\n');
52 index = this.append_cell('print(float_widget.value)\n');
53 this.execute_cell_then(index, function(index){
53 this.execute_cell_then(index, function(index){
54 this.test.assertEquals(this.get_output_cell(index).text, '12.0\n',
54 this.test.assertEquals(this.get_output_cell(index).text, '12.0\n',
55 'Invald float textbox value caught and filtered.');
55 'Invald float textbox value caught and filtered.');
56 });
56 });
57
57
58 var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text';
58 var float_text_query = '.widget-area .widget-subarea .widget-hbox-single .widget-numeric-text';
59 var slider = {};
59 var slider = {};
60 slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider';
60 slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider';
61 slider.index = this.append_cell(
61 slider.index = this.append_cell(
62 'floatrange = [widgets.BoundedFloatTextWidget(), \n' +
62 'floatrange = [widgets.BoundedFloatTextWidget(), \n' +
63 ' widgets.FloatSliderWidget()]\n' +
63 ' widgets.FloatSliderWidget()]\n' +
64 '[display(floatrange[i]) for i in range(2)]\n' +
64 '[display(floatrange[i]) for i in range(2)]\n' +
65 'print("Success")\n');
65 'print("Success")\n');
66 this.execute_cell_then(slider.index, function(index){
66 this.execute_cell_then(slider.index, function(index){
67
67
68 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
68 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
69 'Create float range cell executed with correct output.');
69 'Create float range cell executed with correct output.');
70
70
71 this.test.assert(this.cell_element_exists(index,
71 this.test.assert(this.cell_element_exists(index,
72 '.widget-area .widget-subarea'),
72 '.widget-area .widget-subarea'),
73 'Widget subarea exists.');
73 'Widget subarea exists.');
74
74
75 this.test.assert(this.cell_element_exists(index, slider.query),
75 this.test.assert(this.cell_element_exists(index, slider.query),
76 'Widget slider exists.');
76 'Widget slider exists.');
77
77
78 this.test.assert(this.cell_element_exists(index, float_text_query),
78 this.test.assert(this.cell_element_exists(index, float_text_query),
79 'Widget float textbox exists.');
79 'Widget float textbox exists.');
80 });
80 });
81
81
82 index = this.append_cell(
82 index = this.append_cell(
83 'for widget in floatrange:\n' +
83 'for widget in floatrange:\n' +
84 ' widget.max = 50.0\n' +
84 ' widget.max = 50.0\n' +
85 ' widget.min = -50.0\n' +
85 ' widget.min = -50.0\n' +
86 ' widget.value = 25.0\n' +
86 ' widget.value = 25.0\n' +
87 'print("Success")\n');
87 'print("Success")\n');
88 this.execute_cell_then(index, function(index){
88 this.execute_cell_then(index, function(index){
89
89
90 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
90 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
91 'Float range properties cell executed with correct output.');
91 'Float range properties cell executed with correct output.');
92
92
93 this.test.assert(this.cell_element_exists(slider.index, slider.query),
93 this.test.assert(this.cell_element_exists(slider.index, slider.query),
94 'Widget slider exists.');
94 'Widget slider exists.');
95
95
96 this.test.assert(this.cell_element_function(slider.index, slider.query,
96 this.test.assert(this.cell_element_function(slider.index, slider.query,
97 'slider', ['value']) == 25.0,
97 'slider', ['value']) == 25.0,
98 'Slider set to Python value.');
98 'Slider set to Python value.');
99 });
99 });
100 }); No newline at end of file
100 });
@@ -1,157 +1,157 b''
1 // Test widget int class
1 // Test widget int 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 int_text = {}
9 var int_text = {};
10 int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
10 int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
11 int_text.index = this.append_cell(
11 int_text.index = this.append_cell(
12 'int_widget = widgets.IntTextWidget()\n' +
12 'int_widget = widgets.IntTextWidget()\n' +
13 'display(int_widget)\n' +
13 'display(int_widget)\n' +
14 'int_widget.add_class("my-second-int-text")\n' +
14 'int_widget.add_class("my-second-int-text", selector="input")\n' +
15 'print(int_widget.model_id)\n');
15 'print(int_widget.model_id)\n');
16 this.execute_cell_then(int_text.index, function(index){
16 this.execute_cell_then(int_text.index, function(index){
17 int_text.model_id = this.get_output_cell(index).text.trim();
17 int_text.model_id = this.get_output_cell(index).text.trim();
18
18
19 this.test.assert(this.cell_element_exists(index,
19 this.test.assert(this.cell_element_exists(index,
20 '.widget-area .widget-subarea'),
20 '.widget-area .widget-subarea'),
21 'Widget subarea exists.');
21 'Widget subarea exists.');
22
22
23 this.test.assert(this.cell_element_exists(index, int_text.query),
23 this.test.assert(this.cell_element_exists(index, int_text.query),
24 'Widget int textbox exists.');
24 'Widget int textbox exists.');
25
25
26 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
26 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
27 this.sendKeys(int_text.query, '1.05');
27 this.sendKeys(int_text.query, '1.05');
28 });
28 });
29
29
30 this.wait_for_widget(int_text);
30 this.wait_for_widget(int_text);
31
31
32 index = this.append_cell('print(int_widget.value)\n');
32 index = this.append_cell('print(int_widget.value)\n');
33 this.execute_cell_then(index, function(index){
33 this.execute_cell_then(index, function(index){
34 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
34 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
35 'Int textbox value set.');
35 'Int textbox value set.');
36 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
36 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
37 this.sendKeys(int_text.query, '123456789');
37 this.sendKeys(int_text.query, '123456789');
38 });
38 });
39
39
40 this.wait_for_widget(int_text);
40 this.wait_for_widget(int_text);
41
41
42 index = this.append_cell('print(int_widget.value)\n');
42 index = this.append_cell('print(int_widget.value)\n');
43 this.execute_cell_then(index, function(index){
43 this.execute_cell_then(index, function(index){
44 this.test.assertEquals(this.get_output_cell(index).text, '123456789\n',
44 this.test.assertEquals(this.get_output_cell(index).text, '123456789\n',
45 'Long int textbox value set (probably triggers throttling).');
45 'Long int textbox value set (probably triggers throttling).');
46 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
46 this.cell_element_function(int_text.index, int_text.query, 'val', ['']);
47 this.sendKeys(int_text.query, '12hello');
47 this.sendKeys(int_text.query, '12hello');
48 });
48 });
49
49
50 this.wait_for_widget(int_text);
50 this.wait_for_widget(int_text);
51
51
52 index = this.append_cell('print(int_widget.value)\n');
52 index = this.append_cell('print(int_widget.value)\n');
53 this.execute_cell_then(index, function(index){
53 this.execute_cell_then(index, function(index){
54 this.test.assertEquals(this.get_output_cell(index).text, '12\n',
54 this.test.assertEquals(this.get_output_cell(index).text, '12\n',
55 'Invald int textbox value caught and filtered.');
55 'Invald int textbox value caught and filtered.');
56 });
56 });
57
57
58 index = this.append_cell(
58 index = this.append_cell(
59 'from IPython.html import widgets\n' +
59 'from IPython.html import widgets\n' +
60 'from IPython.display import display, clear_output\n' +
60 'from IPython.display import display, clear_output\n' +
61 'print("Success")');
61 'print("Success")');
62 this.execute_cell_then(index);
62 this.execute_cell_then(index);
63
63
64
64
65 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
65 var slider_query = '.widget-area .widget-subarea .widget-hbox-single .slider';
66 var int_text2 = {};
66 var int_text2 = {};
67 int_text2.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
67 int_text2.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-num-test-text';
68 int_text2.index = this.append_cell(
68 int_text2.index = this.append_cell(
69 'intrange = [widgets.BoundedIntTextWidget(),\n' +
69 'intrange = [widgets.BoundedIntTextWidget(),\n' +
70 ' widgets.IntSliderWidget()]\n' +
70 ' widgets.IntSliderWidget()]\n' +
71 '[display(intrange[i]) for i in range(2)]\n' +
71 '[display(intrange[i]) for i in range(2)]\n' +
72 'intrange[0].add_class("my-second-num-test-text")\n' +
72 'intrange[0].add_class("my-second-num-test-text", selector="input")\n' +
73 'print(intrange[0].model_id)\n');
73 'print(intrange[0].model_id)\n');
74 this.execute_cell_then(int_text2.index, function(index){
74 this.execute_cell_then(int_text2.index, function(index){
75 int_text2.model_id = this.get_output_cell(index).text.trim();
75 int_text2.model_id = this.get_output_cell(index).text.trim();
76
76
77 this.test.assert(this.cell_element_exists(index,
77 this.test.assert(this.cell_element_exists(index,
78 '.widget-area .widget-subarea'),
78 '.widget-area .widget-subarea'),
79 'Widget subarea exists.');
79 'Widget subarea exists.');
80
80
81 this.test.assert(this.cell_element_exists(index, slider_query),
81 this.test.assert(this.cell_element_exists(index, slider_query),
82 'Widget slider exists.');
82 'Widget slider exists.');
83
83
84 this.test.assert(this.cell_element_exists(index, int_text2.query),
84 this.test.assert(this.cell_element_exists(index, int_text2.query),
85 'Widget int textbox exists.');
85 'Widget int textbox exists.');
86 });
86 });
87
87
88 index = this.append_cell(
88 index = this.append_cell(
89 'for widget in intrange:\n' +
89 'for widget in intrange:\n' +
90 ' widget.max = 50\n' +
90 ' widget.max = 50\n' +
91 ' widget.min = -50\n' +
91 ' widget.min = -50\n' +
92 ' widget.value = 25\n' +
92 ' widget.value = 25\n' +
93 'print("Success")\n');
93 'print("Success")\n');
94 this.execute_cell_then(index, function(index){
94 this.execute_cell_then(index, function(index){
95
95
96 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
96 this.test.assertEquals(this.get_output_cell(index).text, 'Success\n',
97 'Int range properties cell executed with correct output.');
97 'Int range properties cell executed with correct output.');
98
98
99 this.test.assert(this.cell_element_exists(int_text2.index, slider_query),
99 this.test.assert(this.cell_element_exists(int_text2.index, slider_query),
100 'Widget slider exists.');
100 'Widget slider exists.');
101
101
102 this.test.assert(this.cell_element_function(int_text2.index, slider_query,
102 this.test.assert(this.cell_element_function(int_text2.index, slider_query,
103 'slider', ['value']) == 25,
103 'slider', ['value']) == 25,
104 'Slider set to Python value.');
104 'Slider set to Python value.');
105
105
106 this.test.assert(this.cell_element_function(int_text2.index, int_text2.query,
106 this.test.assert(this.cell_element_function(int_text2.index, int_text2.query,
107 'val') == 25, 'Int textbox set to Python value.');
107 'val') == 25, 'Int textbox set to Python value.');
108
108
109 // Clear the int textbox value and then set it to 1 by emulating
109 // Clear the int textbox value and then set it to 1 by emulating
110 // keyboard presses.
110 // keyboard presses.
111 this.evaluate(function(q){
111 this.evaluate(function(q){
112 var textbox = IPython.notebook.element.find(q);
112 var textbox = IPython.notebook.element.find(q);
113 textbox.val('1');
113 textbox.val('1');
114 textbox.trigger('keyup');
114 textbox.trigger('keyup');
115 }, {q: int_text2.query});
115 }, {q: int_text2.query});
116 });
116 });
117
117
118 this.wait_for_widget(int_text2);
118 this.wait_for_widget(int_text2);
119
119
120 index = this.append_cell('print(intrange[0].value)\n');
120 index = this.append_cell('print(intrange[0].value)\n');
121 this.execute_cell_then(index, function(index){
121 this.execute_cell_then(index, function(index){
122 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
122 this.test.assertEquals(this.get_output_cell(index).text, '1\n',
123 'Int textbox set int range value');
123 'Int textbox set int range value');
124
124
125 // Clear the int textbox value and then set it to 120 by emulating
125 // Clear the int textbox value and then set it to 120 by emulating
126 // keyboard presses.
126 // keyboard presses.
127 this.evaluate(function(q){
127 this.evaluate(function(q){
128 var textbox = IPython.notebook.element.find(q);
128 var textbox = IPython.notebook.element.find(q);
129 textbox.val('120');
129 textbox.val('120');
130 textbox.trigger('keyup');
130 textbox.trigger('keyup');
131 }, {q: int_text2.query});
131 }, {q: int_text2.query});
132 });
132 });
133
133
134 this.wait_for_widget(int_text2);
134 this.wait_for_widget(int_text2);
135
135
136 index = this.append_cell('print(intrange[0].value)\n');
136 index = this.append_cell('print(intrange[0].value)\n');
137 this.execute_cell_then(index, function(index){
137 this.execute_cell_then(index, function(index){
138 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
138 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
139 'Int textbox value bound');
139 'Int textbox value bound');
140
140
141 // Clear the int textbox value and then set it to 'hello world' by
141 // Clear the int textbox value and then set it to 'hello world' by
142 // emulating keyboard presses. 'hello world' should get filtered...
142 // emulating keyboard presses. 'hello world' should get filtered...
143 this.evaluate(function(q){
143 this.evaluate(function(q){
144 var textbox = IPython.notebook.element.find(q);
144 var textbox = IPython.notebook.element.find(q);
145 textbox.val('hello world');
145 textbox.val('hello world');
146 textbox.trigger('keyup');
146 textbox.trigger('keyup');
147 }, {q: int_text2.query});
147 }, {q: int_text2.query});
148 });
148 });
149
149
150 this.wait_for_widget(int_text2);
150 this.wait_for_widget(int_text2);
151
151
152 index = this.append_cell('print(intrange[0].value)\n');
152 index = this.append_cell('print(intrange[0].value)\n');
153 this.execute_cell_then(index, function(index){
153 this.execute_cell_then(index, function(index){
154 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
154 this.test.assertEquals(this.get_output_cell(index).text, '50\n',
155 'Invalid int textbox characters ignored');
155 'Invalid int textbox characters ignored');
156 });
156 });
157 }); No newline at end of file
157 });
General Comments 0
You need to be logged in to leave comments. Login now