Show More
@@ -1,135 +1,135 b'' | |||
|
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-single .btn-group .widget-combo-btn'; |
|
10 | 10 | var multibtn_selector = '.widget-area .widget-subarea .widget-hbox-single .btn-group[data-toggle="buttons-radio"]'; |
|
11 | 11 | var radio_selector = '.widget-area .widget-subarea .widget-hbox .vbox'; |
|
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.DropdownWidget(values=values),\n' + |
|
48 | 48 | ' widgets.ToggleButtonsWidget(values=values),\n' + |
|
49 | 49 | ' widgets.RadioButtonsWidget(values=values),\n' + |
|
50 | 50 | ' widgets.SelectWidget(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 | this.test.assert(this.cell_element_exists(index, |
|
63 | 63 | '.widget-area .widget-subarea'), |
|
64 | 64 | 'Widget subarea exists.'); |
|
65 | 65 | |
|
66 | 66 | this.test.assert(this.cell_element_exists(index, combo_selector), |
|
67 | 67 | 'Widget combobox exists.'); |
|
68 | 68 | |
|
69 | 69 | this.test.assert(this.cell_element_exists(index, multibtn_selector), |
|
70 | 70 | 'Widget multibutton exists.'); |
|
71 | 71 | |
|
72 | 72 | this.test.assert(this.cell_element_exists(index, radio_selector), |
|
73 | 73 | 'Widget radio buttons exists.'); |
|
74 | 74 | |
|
75 | 75 | this.test.assert(this.cell_element_exists(index, list_selector), |
|
76 | 76 | 'Widget list exists.'); |
|
77 | 77 | |
|
78 | 78 | // Verify that no items are selected. |
|
79 |
this.test.assert(verify_selection(this, |
|
|
79 | this.test.assert(verify_selection(this, 0), 'Default first item selected.'); | |
|
80 | 80 | }); |
|
81 | 81 | |
|
82 | 82 | index = this.append_cell( |
|
83 | 83 | 'for widget in selection:\n' + |
|
84 | 84 | ' widget.value = "a"\n' + |
|
85 | 85 | 'print("Success")\n'); |
|
86 | 86 | this.execute_cell_then(index, function(index){ |
|
87 | 87 | this.test.assertEquals(this.get_output_cell(index).text, 'Success\n', |
|
88 | 88 | 'Python select item executed with correct output.'); |
|
89 | 89 | |
|
90 | 90 | // Verify that the first item is selected. |
|
91 | 91 | this.test.assert(verify_selection(this, 0), 'Python selected'); |
|
92 | 92 | |
|
93 | 93 | // Verify that selecting a radio button updates all of the others. |
|
94 | 94 | this.cell_element_function(selection_index, radio_selector + ' .radio:nth-child(2) input', 'click'); |
|
95 | 95 | }); |
|
96 | 96 | this.wait(500); |
|
97 | 97 | this.then(function () { |
|
98 | 98 | this.test.assert(verify_selection(this, 1), 'Radio button selection updated view states correctly.'); |
|
99 | 99 | |
|
100 | 100 | // Verify that selecting a list option updates all of the others. |
|
101 | 101 | this.cell_element_function(selection_index, list_selector + ' option:nth-child(3)', 'click'); |
|
102 | 102 | }); |
|
103 | 103 | this.wait(500); |
|
104 | 104 | this.then(function () { |
|
105 | 105 | this.test.assert(verify_selection(this, 2), 'List selection updated view states correctly.'); |
|
106 | 106 | |
|
107 | 107 | // Verify that selecting a multibutton option updates all of the others. |
|
108 | 108 | this.cell_element_function(selection_index, multibtn_selector + ' .btn:nth-child(4)', 'click'); |
|
109 | 109 | }); |
|
110 | 110 | this.wait(500); |
|
111 | 111 | this.then(function () { |
|
112 | 112 | this.test.assert(verify_selection(this, 3), 'Multibutton selection updated view states correctly.'); |
|
113 | 113 | |
|
114 | 114 | // Verify that selecting a combobox option updates all of the others. |
|
115 | 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 | 117 | this.wait(500); |
|
118 | 118 | this.then(function () { |
|
119 | 119 | this.test.assert(verify_selection(this, 2), 'Combobox selection updated view states correctly.'); |
|
120 | 120 | }); |
|
121 | 121 | |
|
122 | 122 | this.wait(500); // Wait for change to execute in kernel |
|
123 | 123 | |
|
124 | 124 | index = this.append_cell( |
|
125 | 125 | 'for widget in selection:\n' + |
|
126 | 126 | ' d = widget.values.copy()\n' + |
|
127 | 127 | ' d["z"] = "z"\n' + |
|
128 | 128 | ' widget.values = d\n' + |
|
129 | 129 | 'selection[0].value = "z"'); |
|
130 | 130 | this.execute_cell_then(index, function(index){ |
|
131 | 131 | |
|
132 | 132 | // Verify that selecting a combobox option updates all of the others. |
|
133 | 133 | this.test.assert(verify_selection(this, 4), 'Item added to selection widget.'); |
|
134 | 134 | }); |
|
135 | 135 | }); No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now