Show More
@@ -1,135 +1,135 | |||||
1 | // Test selection class |
|
1 | // Test selection 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 combo_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group .widget-combo-btn'; |
|
9 | var combo_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group .widget-combo-btn'; | |
10 | var multibtn_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group[data-toggle="buttons-radio"]'; |
|
10 | var multibtn_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group[data-toggle="buttons-radio"]'; | |
11 |
var radio_selector = '.widget-area .widget-subarea .widget-hbox . |
|
11 | var radio_selector = '.widget-area .widget-subarea .widget-hbox .widget-radio-box'; | |
12 | var list_selector = '.widget-area .widget-subarea .widget-hbox .widget-listbox'; |
|
12 | var list_selector = '.widget-area .widget-subarea .widget-hbox .widget-listbox'; | |
13 |
|
13 | |||
14 | var selection_index; |
|
14 | var selection_index; | |
15 | var selection_values = 'abcd'; |
|
15 | var selection_values = 'abcd'; | |
16 | var check_state = function(context, index, state){ |
|
16 | var check_state = function(context, index, state){ | |
17 | if (0 <= index && index < selection_values.length) { |
|
17 | if (0 <= index && index < selection_values.length) { | |
18 | var multibtn_state = context.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(' + (index + 1) + ')', 'hasClass', ['active']); |
|
18 | var multibtn_state = context.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(' + (index + 1) + ')', 'hasClass', ['active']); | |
19 | var radio_state = context.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(' + (index + 1) + ') input', 'prop', ['checked']); |
|
19 | var radio_state = context.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(' + (index + 1) + ') input', 'prop', ['checked']); | |
20 | var list_val = context.cell_element_function(selection_index, list_selector, 'val'); |
|
20 | var list_val = context.cell_element_function(selection_index, list_selector, 'val'); | |
21 | var combo_val = context.cell_element_function(selection_index, combo_selector, 'html'); |
|
21 | var combo_val = context.cell_element_function(selection_index, combo_selector, 'html'); | |
22 |
|
22 | |||
23 | var val = selection_values.charAt(index); |
|
23 | var val = selection_values.charAt(index); | |
24 | var list_state = (val == list_val); |
|
24 | var list_state = (val == list_val); | |
25 | var combo_state = (val == combo_val); |
|
25 | var combo_state = (val == combo_val); | |
26 |
|
26 | |||
27 | return multibtn_state == state && |
|
27 | return multibtn_state == state && | |
28 | radio_state == state && |
|
28 | radio_state == state && | |
29 | list_state == state && |
|
29 | list_state == state && | |
30 | combo_state == state; |
|
30 | combo_state == state; | |
31 | } |
|
31 | } | |
32 | return true; |
|
32 | return true; | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 | var verify_selection = function(context, index){ |
|
35 | var verify_selection = function(context, index){ | |
36 | for (var i = 0; i < selection_values.length; i++) { |
|
36 | for (var i = 0; i < selection_values.length; i++) { | |
37 | if (!check_state(context, i, i==index)) { |
|
37 | if (!check_state(context, i, i==index)) { | |
38 | return false; |
|
38 | return false; | |
39 | } |
|
39 | } | |
40 | } |
|
40 | } | |
41 | return true; |
|
41 | return true; | |
42 | }; |
|
42 | }; | |
43 |
|
43 | |||
44 | //values=["' + selection_values + '"[i] for i in range(4)] |
|
44 | //values=["' + selection_values + '"[i] for i in range(4)] | |
45 | selection_index = this.append_cell( |
|
45 | selection_index = this.append_cell( | |
46 | 'values=["' + selection_values + '"[i] for i in range(4)]\n' + |
|
46 | 'values=["' + selection_values + '"[i] for i in range(4)]\n' + | |
47 | 'selection = [widgets.DropdownWidget(values=values),\n' + |
|
47 | 'selection = [widgets.DropdownWidget(values=values),\n' + | |
48 | ' widgets.ToggleButtonsWidget(values=values),\n' + |
|
48 | ' widgets.ToggleButtonsWidget(values=values),\n' + | |
49 | ' widgets.RadioButtonsWidget(values=values),\n' + |
|
49 | ' widgets.RadioButtonsWidget(values=values),\n' + | |
50 | ' widgets.SelectWidget(values=values)]\n' + |
|
50 | ' widgets.SelectWidget(values=values)]\n' + | |
51 | '[display(selection[i]) for i in range(4)]\n' + |
|
51 | '[display(selection[i]) for i in range(4)]\n' + | |
52 | 'for widget in selection:\n' + |
|
52 | 'for widget in selection:\n' + | |
53 | ' def handle_change(name,old,new):\n' + |
|
53 | ' def handle_change(name,old,new):\n' + | |
54 | ' for other_widget in selection:\n' + |
|
54 | ' for other_widget in selection:\n' + | |
55 | ' other_widget.value = new\n' + |
|
55 | ' other_widget.value = new\n' + | |
56 | ' widget.on_trait_change(handle_change, "value")\n' + |
|
56 | ' widget.on_trait_change(handle_change, "value")\n' + | |
57 | 'print("Success")\n'); |
|
57 | 'print("Success")\n'); | |
58 | this.execute_cell_then(selection_index, function(index){ |
|
58 | this.execute_cell_then(selection_index, function(index){ | |
59 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
59 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
60 | 'Create selection cell executed with correct output.'); |
|
60 | 'Create selection cell executed with correct output.'); | |
61 |
|
61 | |||
62 | this.test.assert(this.cell_element_exists(index, |
|
62 | this.test.assert(this.cell_element_exists(index, | |
63 | '.widget-area .widget-subarea'), |
|
63 | '.widget-area .widget-subarea'), | |
64 | 'Widget subarea exists.'); |
|
64 | 'Widget subarea exists.'); | |
65 |
|
65 | |||
66 | this.test.assert(this.cell_element_exists(index, combo_selector), |
|
66 | this.test.assert(this.cell_element_exists(index, combo_selector), | |
67 | 'Widget combobox exists.'); |
|
67 | 'Widget combobox exists.'); | |
68 |
|
68 | |||
69 | this.test.assert(this.cell_element_exists(index, multibtn_selector), |
|
69 | this.test.assert(this.cell_element_exists(index, multibtn_selector), | |
70 | 'Widget multibutton exists.'); |
|
70 | 'Widget multibutton exists.'); | |
71 |
|
71 | |||
72 | this.test.assert(this.cell_element_exists(index, radio_selector), |
|
72 | this.test.assert(this.cell_element_exists(index, radio_selector), | |
73 | 'Widget radio buttons exists.'); |
|
73 | 'Widget radio buttons exists.'); | |
74 |
|
74 | |||
75 | this.test.assert(this.cell_element_exists(index, list_selector), |
|
75 | this.test.assert(this.cell_element_exists(index, list_selector), | |
76 | 'Widget list exists.'); |
|
76 | 'Widget list exists.'); | |
77 |
|
77 | |||
78 | // Verify that no items are selected. |
|
78 | // Verify that no items are selected. | |
79 | this.test.assert(verify_selection(this, 0), 'Default first item selected.'); |
|
79 | this.test.assert(verify_selection(this, 0), 'Default first item selected.'); | |
80 | }); |
|
80 | }); | |
81 |
|
81 | |||
82 | index = this.append_cell( |
|
82 | index = this.append_cell( | |
83 | 'for widget in selection:\n' + |
|
83 | 'for widget in selection:\n' + | |
84 | ' widget.value = "a"\n' + |
|
84 | ' widget.value = "a"\n' + | |
85 | 'print("Success")\n'); |
|
85 | 'print("Success")\n'); | |
86 | this.execute_cell_then(index, function(index){ |
|
86 | this.execute_cell_then(index, function(index){ | |
87 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
87 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', | |
88 | 'Python select item executed with correct output.'); |
|
88 | 'Python select item executed with correct output.'); | |
89 |
|
89 | |||
90 | // Verify that the first item is selected. |
|
90 | // Verify that the first item is selected. | |
91 | this.test.assert(verify_selection(this, 0), 'Python selected'); |
|
91 | this.test.assert(verify_selection(this, 0), 'Python selected'); | |
92 |
|
92 | |||
93 | // Verify that selecting a radio button updates all of the others. |
|
93 | // Verify that selecting a radio button updates all of the others. | |
94 | this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click'); |
|
94 | this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click'); | |
95 | }); |
|
95 | }); | |
96 | this.wait_for_idle(); |
|
96 | this.wait_for_idle(); | |
97 | this.then(function () { |
|
97 | this.then(function () { | |
98 | this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.'); |
|
98 | this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.'); | |
99 |
|
99 | |||
100 | // Verify that selecting a list option updates all of the others. |
|
100 | // Verify that selecting a list option updates all of the others. | |
101 | this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click'); |
|
101 | this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click'); | |
102 | }); |
|
102 | }); | |
103 | this.wait_for_idle(); |
|
103 | this.wait_for_idle(); | |
104 | this.then(function () { |
|
104 | this.then(function () { | |
105 | this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.'); |
|
105 | this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.'); | |
106 |
|
106 | |||
107 | // Verify that selecting a multibutton option updates all of the others. |
|
107 | // Verify that selecting a multibutton option updates all of the others. | |
108 | this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click'); |
|
108 | this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click'); | |
109 | }); |
|
109 | }); | |
110 | this.wait_for_idle(); |
|
110 | this.wait_for_idle(); | |
111 | this.then(function () { |
|
111 | this.then(function () { | |
112 | this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.'); |
|
112 | this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.'); | |
113 |
|
113 | |||
114 | // Verify that selecting a combobox option updates all of the others. |
|
114 | // Verify that selecting a combobox option updates all of the others. | |
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'); |
|
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_for_idle(); |
|
117 | this.wait_for_idle(); | |
118 | this.then(function () { |
|
118 | this.then(function () { | |
119 | this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.'); |
|
119 | this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.'); | |
120 | }); |
|
120 | }); | |
121 |
|
121 | |||
122 | this.wait_for_idle(); |
|
122 | this.wait_for_idle(); | |
123 |
|
123 | |||
124 | index = this.append_cell( |
|
124 | index = this.append_cell( | |
125 | 'for widget in selection:\n' + |
|
125 | 'for widget in selection:\n' + | |
126 | ' d = widget.values.copy()\n' + |
|
126 | ' d = widget.values.copy()\n' + | |
127 | ' d["z"] = "z"\n' + |
|
127 | ' d["z"] = "z"\n' + | |
128 | ' widget.values = d\n' + |
|
128 | ' widget.values = d\n' + | |
129 | 'selection[0].value = "z"'); |
|
129 | 'selection[0].value = "z"'); | |
130 | this.execute_cell_then(index, function(index){ |
|
130 | this.execute_cell_then(index, function(index){ | |
131 |
|
131 | |||
132 | // Verify that selecting a combobox option updates all of the others. |
|
132 | // Verify that selecting a combobox option updates all of the others. | |
133 | this.test.assert(verify_selection(this, 4), 'Item added to selection widget.'); |
|
133 | this.test.assert(verify_selection(this, 4), 'Item added to selection widget.'); | |
134 | }); |
|
134 | }); | |
135 | }); No newline at end of file |
|
135 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now