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