120 test_text ('table.dash_table th:eq(4) span.em', 'Activities'); |
129 test_text ('table.dash_table th:eq(4) span.em', 'Activities'); |
121 test_unlogged_footer (); |
130 test_unlogged_footer (); |
122 }); |
131 }); |
123 |
132 |
124 suite ('texts list', function () { |
133 suite ('texts list', function () { |
125 test_page_loading ('/text/', 'Texts'); |
134 test_page_loading ('/text/', 'Texts'); |
126 test_logged_header (w.USER_ADMIN); |
135 test_logged_header (w.USER_ADMIN); |
127 test_default_tabs (); |
136 test_default_tabs (); |
128 test_count ('#text ul.sub_list:eq(0) a', 3); |
137 test_count ('#text ul.sub_list:eq(0) a', 3); |
129 test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text'); |
138 test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text'); |
130 test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text'); |
139 test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text'); |
131 test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text'); |
140 test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text'); |
132 // TOTEST : filter by tag |
141 // TOTEST : filter by tag |
133 test_count ('form#filter_form[action="."] :input', 1); |
142 test_count ('form#filter_form[action="."] :input', 1); |
134 test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible); |
143 test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible); |
135 test ('#texts_form input count', dsl (function () { |
144 test ('#texts_form input count', dsl (function () { |
136 elt ('form#texts_form[action="."] :input').count (function (c) { |
145 elt ('form#texts_form[action="."] :input').count (function (c) { |
137 var n = 3 + text_nb % 10; |
146 var n = 3 + z.text_nb % 10; |
138 if (c != n) throw 'expected computed '+n+' to equal got '+c; |
147 if (c != n) throw 'expected computed '+n+' to equal got '+c; |
139 }); |
148 }); |
140 })); |
149 })); |
141 test ('#paginator "of #" value', dsl (function () { |
150 test ('#paginator "of #" value', dsl (function () { |
142 elt ('span#paginator').text (function (t) { |
151 elt ('span#paginator').text (function (t) { |
143 var r = t.match (/\s\d+-\d+ of (\d+)\s/m); |
152 var r = t.match (/\s\d+-\d+ of (\d+)\s/m); |
144 if (r.length != 2) throw 'expected 2 matches got '+r.length; |
153 if (r.length != 2) throw 'expected 2 matches got '+r.length; |
145 if (r[1] != text_nb) throw 'expected paginator total ('+r[1]+') to be '+text_nb; |
154 if (r[1] != z.text_nb) throw 'expected paginator total ('+r[1]+') to be '+z.text_nb; |
146 }); |
155 }); |
147 })); |
156 })); |
148 // TOTEST : pagination |
157 // TOTEST : pagination |
149 // TOTEST : Bulk Actions -> Apply does enable |
158 // TOTEST : Bulk Actions -> Apply does enable |
150 test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', non_visible); |
159 test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', non_visible); |
158 test_text ('table.large_table:eq(1) th:eq(4)', '# comments'); |
167 test_text ('table.large_table:eq(1) th:eq(4)', '# comments'); |
159 test_text ('table.large_table:eq(1) th:eq(5)', 'Last week activity'); |
168 test_text ('table.large_table:eq(1) th:eq(5)', 'Last week activity'); |
160 test_unlogged_footer (); |
169 test_unlogged_footer (); |
161 }); |
170 }); |
162 |
171 |
|
172 suite ('people list', function () { |
|
173 test_page_loading ('/user/', 'People'); |
|
174 test_logged_header (w.USER_ADMIN); |
|
175 test_default_tabs (); |
|
176 test_count ('#user ul.sub_list:eq(0) a', 2); |
|
177 test_text ('#user ul.sub_list:eq(0) a:eq(0)[href="/user/add/"]', 'Add a new user'); |
|
178 test_text ('#user ul.sub_list:eq(0) a:eq(1)[href="/user/mass-add/"]', 'Add users in bulk'); |
|
179 // TOTEST : filter by tag |
|
180 test_count ('form#filter_form[action="."] :input', 1); |
|
181 test_text ('#filter_form a[href="?display=1"]', 'Display suspended users'); |
|
182 test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible); |
|
183 test ('#user_form input count', dsl (function () { |
|
184 elt ('form#user_form[action="."] :input').count (function (c) { |
|
185 var n = 6 + (z.user_nb % 10) * 2; |
|
186 if (c != n) throw 'expected computed '+n+' to equal got '+c; |
|
187 }); |
|
188 })); |
|
189 test ('#paginator "of #" value', dsl (function () { |
|
190 elt ('span#paginator').text (function (t) { |
|
191 var r = t.match (/\s\d+-\d+ of (\d+)\s/m); |
|
192 if (r.length != 2) throw 'expected 2 matches got '+r.length; |
|
193 if (r[1] != z.user_nb) throw 'expected paginator total ('+r[1]+') to be '+z.user_nb; |
|
194 }); |
|
195 })); |
|
196 // TOTEST : pagination |
|
197 // TOTEST : Bulk Actions -> Apply does enable |
|
198 test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', '- Bulk Actions -', non_visible); |
|
199 test_text ('select#bulk_actions option:eq(1)[value="disable"]', 'Suspend access', non_visible); |
|
200 test_text ('select#bulk_actions option:eq(2)[value="enable"]', 'Enable access', non_visible); |
|
201 test_text ('select#bulk_actions option:eq(3)[value="role_1"]', 'Change role to Manager', non_visible); |
|
202 test_text ('select#bulk_actions option:eq(4)[value="role_2"]', 'Change role to Editor', non_visible); |
|
203 test_text ('select#bulk_actions option:eq(5)[value="role_3"]', 'Change role to Moderator', non_visible); |
|
204 test_text ('select#bulk_actions option:eq(6)[value="role_4"]', 'Change role to Commentator', non_visible); |
|
205 test_text ('select#bulk_actions option:eq(7)[value="role_5"]', 'Change role to Observer', non_visible); |
|
206 test_val ('form#user_form input#apply[type=button][disabled]', 'Apply'); |
|
207 test_count ('table.large_table:eq(1) th', 6); |
|
208 test_val ('table.large_table:eq(1) th:eq(0) input#all_check[type="checkbox"]', 'on'); |
|
209 test_text ('table.large_table:eq(1) th:eq(1) a[href="?order=user__username"]', 'User'); |
|
210 test_text ('table.large_table:eq(1) th:eq(2) a[href="?order=user__email"]', 'Email'); |
|
211 test_text ('table.large_table:eq(1) th:eq(3) a[href="?order=-user__date_joined"]', 'Date joined'); |
|
212 test_text ('table.large_table:eq(1) th:eq(4) a[href="?order=role__name"]', 'Role'); |
|
213 test_text ('table.large_table:eq(1) th:eq(5)', 'Last week activity'); |
|
214 test_text ('table.large_table:eq(1) tr:last a[href="/user/-/edit/"]', 'Anonymous users'); |
|
215 test_text ('table.large_table:eq(1) a.main_object_title[href="/profile/"]', w.USER_ADMIN); |
|
216 test_text ('table.large_table:eq(1) div.hidden-user-actions a[href="/profile/"]', 'Your profile'); |
|
217 test_unlogged_footer (); |
|
218 }); |
|
219 |
|
220 suite ('settings conformity', function () { |
|
221 test_page_loading ('/settings/', 'Settings'); |
|
222 test_logged_header (w.USER_ADMIN); |
|
223 test_default_tabs (); |
|
224 test_count ('#settings ul.sub_list:eq(0) a', 1); |
|
225 test_text ('#settings ul.sub_list:eq(0) a:eq(0)[href="/settings/design/"]', 'Appearance'); |
|
226 test_count ('#settings form[action="."]:eq(0) :input', 12); |
|
227 test_form_field ('settings', 'id_workspace_name', 'text', 0, 'Workspace name'); |
|
228 test_form_field ('settings', 'id_workspace_tagline', 'text', 1, 'Workspace tagline'); |
|
229 test_form_field ('settings', 'id_workspace_registration', 'checkbox', 2, 'Workspace registration'); |
|
230 test_form_field ('settings', 'id_workspace_registration_moderation', 'checkbox', 3, 'Workspace registration moderation'); |
|
231 test_form_field ('settings', 'id_workspace_role_model', 'select', 4, 'Role model'); |
|
232 test_text ('select#id_workspace_role_model option:eq(0)[selected][value="generic"]', 'Generic', non_visible); |
|
233 test_text ('select#id_workspace_role_model option:eq(1)[value="teacher"]', 'Class (education)', non_visible); |
|
234 test_form_field ('settings', 'id_workspace_category_1', 'text', 5, 'Label for the first category of comments'); |
|
235 test_form_field ('settings', 'id_workspace_category_2', 'text', 6, 'Label for the second category of comments'); |
|
236 test_form_field ('settings', 'id_workspace_category_3', 'text', 7, 'Label for the third category of comments'); |
|
237 test_form_field ('settings', 'id_workspace_category_4', 'text', 8, 'Label for the fourth category of comments'); |
|
238 test_form_field ('settings', 'id_workspace_category_5', 'text', 9, 'Label for the fifth category of comments'); |
|
239 test_val ('#settings :input:eq(10)[type=submit]', 'Save'); |
|
240 test_val ('#settings :input:eq(11)#cancel_button[type=button]', 'Cancel'); |
|
241 test_unlogged_footer (); |
|
242 }); |
|
243 |
|
244 suite ('settings reading', function () { |
|
245 test_readz_field ('#id_workspace_name'); |
|
246 test_readz_field ('#id_workspace_tagline'); |
|
247 test_readz_field ('#id_workspace_registration'); |
|
248 test_readz_field ('#id_workspace_registration_moderation'); |
|
249 test_readz_field ('#id_workspace_role_model'); |
|
250 test_readz_field ('#id_workspace_category_1'); |
|
251 test_readz_field ('#id_workspace_category_2'); |
|
252 test_readz_field ('#id_workspace_category_3'); |
|
253 test_readz_field ('#id_workspace_category_4'); |
|
254 test_readz_field ('#id_workspace_category_5'); |
|
255 /* test ('display z', dsl(function () { |
|
256 elt ('#main-tabs').text (function (t) { |
|
257 console.log ('z '+JSON.stringify(z)); |
|
258 }); |
|
259 }));*/ |
|
260 }); |
|
261 |
|
262 suite ('settings restoration', function () { |
|
263 test_fill_settings (t); |
|
264 test_val ('#id_workspace_name', t['#id_workspace_name']); |
|
265 test ('Save test settings ', dsl (function () { |
|
266 elt ('#settings input[type="submit"]').click (); |
|
267 browser.waitForPageLoad (); |
|
268 })); |
|
269 test_page_loading ('/settings/', 'Settings'); |
|
270 test_text ('#content h1.main_title a[href="/"]', t['#id_workspace_name']); |
|
271 }); |
|
272 |
163 suite ('followup', function () { |
273 suite ('followup', function () { |
164 test_logged_header (w.USER_ADMIN); |
274 test_page_loading ('/followup/', 'Followup'); |
165 test_default_tabs (); |
275 test_logged_header (w.USER_ADMIN); |
166 test_page_loading ('/followup/', 'Followup'); |
276 test_default_tabs (); |
167 test_text ('#followup a:eq(0)[href="/help/#public_private_feed"]', '?'); |
277 test_text ('#followup a:eq(0)[href="/help/#public_private_feed"]', '?'); |
168 test_match ('#followup a:eq(1)[href$="/feed/"]', new RegExp (w.WORKSPACE_URL+'feed/', 'm')); |
278 test_match ('#followup a:eq(1)[href$="/feed/"]', new RegExp (w.WORKSPACE_URL+'feed/', 'm')); |
169 test_text ('#followup a:eq(2)[href="/help/#public_private_feed"]', '?'); |
279 test_text ('#followup a:eq(2)[href="/help/#public_private_feed"]', '?'); |
170 test_count ('form#followup_form[action="."] :input', 3); |
280 test_count ('form#followup_form[action="."] :input', 3); |
171 test_val ('form#followup_form input[type=submit]', '(Activate private feed|Reset private feed url)'); |
281 test_val ('form#followup_form input[type=submit]', '(Activate private feed|Reset private feed url)'); |
302 |
423 |
303 /** Test Django form field presence |
424 /** Test Django form field presence |
304 */ |
425 */ |
305 function test_form_field (form_id, field_id, type, position, label, mandatory) { |
426 function test_form_field (form_id, field_id, type, position, label, mandatory) { |
306 test ('has a '+label+' form field', dsl(function () { |
427 test ('has a '+label+' form field', dsl(function () { |
307 var s = type == 'textarea' ? 'textarea#'+field_id : 'input#'+field_id+'[type='+type+']'; |
428 var s = ''; |
|
429 switch (type) { |
|
430 case 'textarea':s = 'textarea#'+field_id; break; |
|
431 case 'select': s = 'select#'+field_id; break; |
|
432 default: s = 'input#'+field_id+'[type="'+type+'"]'; |
|
433 } |
|
434 // var s = type == 'textarea' ? 'textarea#'+field_id : 'input#'+field_id+'[type='+type+']'; |
308 expect (elt (s).val ()).toBeDefined (); |
435 expect (elt (s).val ()).toBeDefined (); |
309 expect (elt ('#'+form_id+' :input:eq('+position+')#'+field_id).val ()).toBeDefined (); |
436 expect (elt ('#'+form_id+' :input:eq('+position+')#'+field_id).val ()).toBeDefined (); |
310 expect (elt ('label[for='+field_id+']').text ()).toBe (label); |
437 expect (elt ('label[for='+field_id+']').text ()).toBe (label); |
311 |
438 |
312 if (mandatory) |
439 if (mandatory) |
313 expect (elt ('label[for='+field_id+'] + span.required_star').val ()).toBeDefined (); |
440 expect (elt ('label[for='+field_id+'] + span.required_star').val ()).toBeDefined (); |
314 })); |
441 })); |
315 } |
442 } |
316 |
443 |
|
444 function test_readz_field (field_id) { |
|
445 test ('get '+field_id, dsl(function () { |
|
446 element (field_id).val (function (v) { |
|
447 z[field_id] = v; |
|
448 }); |
|
449 })); |
|
450 } |
|
451 |
|
452 function test_fill_field (field_id, stored) { |
|
453 test ('set '+field_id, dsl(function () { |
|
454 input (field_id).enter (stored[field_id]); |
|
455 })); |
|
456 } |
|
457 |
|
458 function test_fill_settings (s) { |
|
459 test_fill_field ('#id_workspace_name', s); |
|
460 test_fill_field ('#id_workspace_tagline', s); |
|
461 test_fill_field ('#id_workspace_registration', s); |
|
462 test_fill_field ('#id_workspace_registration_moderation', s); |
|
463 test_fill_field ('#id_workspace_role_model', s); |
|
464 test_fill_field ('#id_workspace_category_1', s); |
|
465 test_fill_field ('#id_workspace_category_2', s); |
|
466 test_fill_field ('#id_workspace_category_3', s); |
|
467 test_fill_field ('#id_workspace_category_4', s); |
|
468 test_fill_field ('#id_workspace_category_5', s); |
|
469 } |
|
470 |
317 /** Ensure the given element is visible |
471 /** Ensure the given element is visible |
318 * s : CSS selector of the DOM element to check |
472 * s : CSS selector of the DOM element to check |
319 * v : should the element being visible |
473 * v : should the element being visible |
320 */ |
474 */ |
321 function elt (s, v) { |
475 function elt (s, v) { |