# HG changeset patch # User Simon Descarpentries # Date 1395769121 -3600 # Node ID 09640f41fed19d3c7e0d43cf5024000ec1bc732a # Parent c35e699107850143d5cd390e1c130d4964aefc47 Adapt tests to test_suite fixture, including empty text list diff -r c35e69910785 -r 09640f41fed1 test-suite/tests/tests.js --- a/test-suite/tests/tests.js Mon Mar 24 17:49:39 2014 +0100 +++ b/test-suite/tests/tests.js Tue Mar 25 18:38:41 2014 +0100 @@ -1,16 +1,15 @@ // " Vim settings -// set tabstop=4 " number of spaces in a tab -// set softtabstop=4 " as above -// set shiftwidth=4 " as above +// set tabstop=4 " number of spaces in a tab +// set softtabstop=4 " as above +// set shiftwidth=4 " as above // check that public texts still work while unlogged // check that non public texts are unavailable // Are the public texts displayed in the login page ? -var w = __karma__.config.w, - z = {}; +var w = __karma__.config.w; const non_visible = false, no_tagline = false; const t = { '#id_workspace_name': 'Test workspace name', @@ -26,6 +25,8 @@ '#id_custom_css': "h2 { font-family: Test_Sopinspace !important; }", '#id_custom_font': 'Test_Sopinspace_custom_font', '#id_custom_titles_font': 'Test_Sopinspace_custom_titles_font', + 'text_nb': 0, + 'user_nb': 4 }; @@ -126,29 +127,6 @@ })); }); - suite ('reading settings', function () { - test_page_loading ('/settings/', 'Settings'); - test_readz_field ('#id_workspace_name'); - test_readz_field ('#id_workspace_tagline'); - test_readz_field ('#id_workspace_registration'); - test_readz_field ('#id_workspace_registration_moderation'); - test_readz_field ('#id_workspace_role_model'); - test_readz_field ('#id_workspace_category_1'); - test_readz_field ('#id_workspace_category_2'); - test_readz_field ('#id_workspace_category_3'); - test_readz_field ('#id_workspace_category_4'); - test_readz_field ('#id_workspace_category_5'); - test_page_loading ('/settings/design/', 'Settings'); - test_readz_field ('#id_custom_css'); - test_readz_field ('#id_custom_font'); - test_readz_field ('#id_custom_titles_font'); - /*test ('display z', dsl(function () { - elt ('#main-tabs').text (function (t) { - console.log ('z '+JSON.stringify(z)); - }); - }));*/ - }); - suite ('setting settings to test-values', function () { test_page_loading ('/settings/', 'Settings'); test_fill_settings (t); @@ -157,7 +135,7 @@ elt ('#settings input[type="submit"]').click (); browser.waitForPageLoad (); })); - test_page_loading ('/settings/', 'Settings'); + test_page_loading ('/settings/', 'Settings'); test_text ('#content h1.main_title a[href="/"]', t['#id_workspace_name']); test_page_loading ('/settings/design/', 'Settings'); test_fill_design (t); @@ -165,20 +143,12 @@ elt ('#settings input[type="submit"]').click (); browser.waitForPageLoad (); })); - }); + }); suite ('admin dashboard page conformity', function () { test_page_loading ('/', 'Dashboard\n - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN); - test ('get text and user nb', dsl(function () { - element ('span.metadata:eq(0)').text (function (metadata) { - var r = metadata.match (/(\d+) texts, (\d+) users/); - if (r.length != 3) throw 'expected 3 matches got '+r.length; - z.text_nb = r[1]; - z.user_nb = r[2]; - }); - })); - test_default_tabs (); + test_default_tabs (t.text_nb, t.user_nb); test_count ('table.dash_table', 5); test_text ('table.dash_table th:eq(0)', 'Actions'); test_match ('table.dash_table:eq(0) a:eq(0)[href="/create/content/"]', /\sCreate a text/); @@ -201,10 +171,106 @@ test_unlogged_footer (); }); - suite ('texts list page conformity', function () { + suite ('empty texts list page conformity', function () { test_page_loading ('/text/', 'Texts\n - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN); - test_default_tabs (); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#text ul.sub_list:eq(0) a', 3); + test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text'); + test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text'); + test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text'); + test_match ('#text', /No texts yet/m); + test_count ('#texts_form :input', 0); + }); + + suite ('create a text page conformity', function () { + test_page_loading ('/create/content/', 'Create a text - '+t['#id_workspace_name']); + test_logged_header (w.USER_ADMIN); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#text ul.sub_list:eq(0) a', 3); + test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list'); + test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text'); + test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text'); + test_count ('#text form[action="."]:eq(0) :input', 6); + test_form_field ('text', 'id_title', 'text', 0, 'Title', true); + test_form_field ('text', 'id_format', 'select', 1, 'Format', true); + test_form_field ('text', 'id_content', 'textarea', 2, 'Content', true); + test_form_field ('text', 'id_tags', 'text', 3, 'Tags'); + test_val ('#text :input:eq(4)[type=submit]', 'Save'); + test_val ('#text :input:eq(5)#cancel_button[type=button]', 'Cancel'); + test_count ('select#id_format option', 3); + test_text ('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', non_visible); + test_text ('select#id_format option:eq(1)[value="rst"]', 'rst', non_visible); + test_text ('select#id_format option:eq(2)[value="html"]', 'html', non_visible); + test_count ('#markItUpId_content li', 20); // How many buttons are in the WYSIWYG editor toolbar ? + test_unlogged_footer (); + + test ('submit empty fields', dsl(function () { + elt ('#text input[type="submit"]').click (); + browser.waitForPageLoad (); + })); + test_count ('div.help_text span.error-text', 2); + test_form_field ('text div.error', 'id_title', 'text', 0, 'Title', true); + test_form_field ('text div.error', 'id_content', 'textarea', 1, 'Content', true); + }); + + suite ('upload text page conformity', function () { + test_page_loading ('/create/upload/', 'Upload a text - '+t['#id_workspace_name']); + test_logged_header (w.USER_ADMIN); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#text ul.sub_list:eq(0) a', 3); + test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list'); + test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/content/"]', 'Create a text'); + test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text'); + test_count ('#text form[action="."]:eq(0) :input', 6); + test_form_field ('text', 'id_title', 'text', 0, 'Title'); + test_form_field ('text', 'id_format', 'select', 1, 'Format', true); + test_form_field ('text', 'id_tags', 'text', 2, 'Tags'); + test_form_field ('text', 'id_file', 'file', 3, 'Upload file'); + test_val ('#text :input:eq(4)[type=submit]', 'Save'); + test_val ('#text :input:eq(5)#cancel_button[type=button]', 'Cancel'); + test_count ('select#id_format option', 3); + test_text ('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', non_visible); + test_text ('select#id_format option:eq(1)[value="rst"]', 'rst', non_visible); + test_text ('select#id_format option:eq(2)[value="html"]', 'html', non_visible); + test_unlogged_footer (); + + test ('submit empty fields', dsl(function () { + elt ('#text input[type="submit"]').click (); + browser.waitForPageLoad (); + })); + test_count ('div.help_text span.error-text', 1); + test_form_field ('text div.error', 'id_file', 'file', 0, 'Upload file'); + test_match ('#text div.help_text:eq(3) span.error-text:eq(0)', /You should specify a file to upload/m); + }); + + suite ('import a co-mented text page conformity', function () { + test_page_loading ('/create/import/', 'Import a co-mented text - '+t['#id_workspace_name']); + test_logged_header (w.USER_ADMIN); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#text ul.sub_list:eq(0) a', 3); + test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list'); + test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/content/"]', 'Create a text'); + test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/upload/"]', 'Upload a text'); + test_count ('#text form[action="."]:eq(0) :input', 3); + test_form_field ('text', 'id_file', 'file', 0, 'Upload XML file', true); + test_val ('#text :input:eq(1)[type=submit]', 'Save'); + test_val ('#text :input:eq(2)#cancel_button[type=button]', 'Cancel'); + test_unlogged_footer (); + + test ('submit empty fields', dsl(function () { + elt ('#text input[type="submit"]').click (); + browser.waitForPageLoad (); + })); + test_count ('div.help_text span.error-text', 1); + test_form_field ('text div.error', 'id_file', 'file', 0, 'Upload XML file', true); + test_match ('#text div.help_text:eq(0) span.error-text:eq(0)', /You should specify a file to upload/m); + }); + + suite.skip ('texts list page conformity', function () { + test_page_loading ('/text/', 'Texts\n - '+t['#id_workspace_name']); + test_logged_header (w.USER_ADMIN); + test_default_tabs (t.text_nb, t.user_nb); test_count ('#text ul.sub_list:eq(0) a', 3); test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text'); test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text'); @@ -212,19 +278,8 @@ // TOTEST : filter by tag test_count ('form#filter_form[action="."] :input', 1); test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible); - test ('#texts_form input count', dsl (function () { - elt ('form#texts_form[action="."] :input').count (function (c) { - var n = 3 + z.text_nb % 10; - if (c != n) throw 'expected computed '+n+' to equal got '+c; - }); - })); - test ('#paginator "of #" value', dsl (function () { - elt ('span#paginator').text (function (t) { - var r = t.match (/\s\d+-\d+ of (\d+)\s/m); - if (r.length != 2) throw 'expected 2 matches got '+r.length; - if (r[1] != z.text_nb) throw 'expected paginator total ('+r[1]+') to be '+z.text_nb; - }); - })); + test_count ('#texts_form :input', 3 + t.text_nb % 10); + test_match ('#paginator', new RegExp ('\\s\\d+-\\d+ of '+t.text_nb+'\\s','m')); // TOTEST : pagination // TOTEST : Bulk Actions -> Apply does enable test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', non_visible); @@ -240,178 +295,83 @@ test_unlogged_footer (); }); - suite ('create a text page conformity', function () { - test_page_loading ('/create/content/', 'Create a text - '+t['#id_workspace_name']); - test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#text ul.sub_list:eq(0) a', 3); - test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list'); - test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text'); - test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text'); - test_count ('#text form[action="."]:eq(0) :input', 6); - test_form_field ('text', 'id_title', 'text', 0, 'Title', true); - test_form_field ('text', 'id_format', 'select', 1, 'Format', true); - test_form_field ('text', 'id_content', 'textarea', 2, 'Content', true); - test_form_field ('text', 'id_tags', 'text', 3, 'Tags'); - test_val ('#text :input:eq(4)[type=submit]', 'Save'); - test_val ('#text :input:eq(5)#cancel_button[type=button]', 'Cancel'); - test_count ('select#id_format option', 3); - test_text ('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', non_visible); - test_text ('select#id_format option:eq(1)[value="rst"]', 'rst', non_visible); - test_text ('select#id_format option:eq(2)[value="html"]', 'html', non_visible); - test_count ('#markItUpId_content li', 20); // How many buttons are in the WYSIWYG editor toolbar ? - test_unlogged_footer (); - - test ('submit empty fields', dsl(function () { - elt ('#text input[type="submit"]').click (); - browser.waitForPageLoad (); - })); - test_count ('div.help_text span.error-text', 2); - test_form_field ('text div.error', 'id_title', 'text', 0, 'Title', true); - test_form_field ('text div.error', 'id_content', 'textarea', 1, 'Content', true); - }); - - suite ('upload text page conformity', function () { - test_page_loading ('/create/upload/', 'Upload a text - '+t['#id_workspace_name']); - test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#text ul.sub_list:eq(0) a', 3); - test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list'); - test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/content/"]', 'Create a text'); - test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text'); - test_count ('#text form[action="."]:eq(0) :input', 6); - test_form_field ('text', 'id_title', 'text', 0, 'Title'); - test_form_field ('text', 'id_format', 'select', 1, 'Format', true); - test_form_field ('text', 'id_tags', 'text', 2, 'Tags'); - test_form_field ('text', 'id_file', 'file', 3, 'Upload file'); - test_val ('#text :input:eq(4)[type=submit]', 'Save'); - test_val ('#text :input:eq(5)#cancel_button[type=button]', 'Cancel'); - test_count ('select#id_format option', 3); - test_text ('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', non_visible); - test_text ('select#id_format option:eq(1)[value="rst"]', 'rst', non_visible); - test_text ('select#id_format option:eq(2)[value="html"]', 'html', non_visible); - test_unlogged_footer (); - - test ('submit empty fields', dsl(function () { - elt ('#text input[type="submit"]').click (); - browser.waitForPageLoad (); - })); - test_count ('div.help_text span.error-text', 1); - test_form_field ('text div.error', 'id_file', 'file', 0, 'Upload file'); - test_match ('#text div.help_text:eq(3) span.error-text:eq(0)', /You should specify a file to upload/m); - }); - - suite ('import a co-mented text page conformity', function () { - test_page_loading ('/create/import/', 'Import a co-mented text - '+t['#id_workspace_name']); - test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#text ul.sub_list:eq(0) a', 3); - test_text ('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list'); - test_text ('#text ul.sub_list:eq(0) a:eq(1)[href="/create/content/"]', 'Create a text'); - test_text ('#text ul.sub_list:eq(0) a:eq(2)[href="/create/upload/"]', 'Upload a text'); - test_count ('#text form[action="."]:eq(0) :input', 3); - test_form_field ('text', 'id_file', 'file', 0, 'Upload XML file', true); - test_val ('#text :input:eq(1)[type=submit]', 'Save'); - test_val ('#text :input:eq(2)#cancel_button[type=button]', 'Cancel'); - test_unlogged_footer (); - - test ('submit empty fields', dsl(function () { - elt ('#text input[type="submit"]').click (); - browser.waitForPageLoad (); - })); - test_count ('div.help_text span.error-text', 1); - test_form_field ('text div.error', 'id_file', 'file', 0, 'Upload XML file', true); - test_match ('#text div.help_text:eq(0) span.error-text:eq(0)', /You should specify a file to upload/m); - }); - suite ('edit profile page conformity', function () { - test_page_loading ('/profile/', 'Your profile [(]'+w.USER_ADMIN+'[)]\n - '+t['#id_workspace_name']); + test_page_loading ('/profile/', 'Your profile [(]'+w.USER_ADMIN+'[)]\n - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN, no_tagline); - test_count ('#content ul.sub_list:eq(0) a', 1); - test_text ('#content ul.sub_list:eq(0) a:eq(0)[href="/profile-pw/"]', 'Password'); - test_count ('form#profile[action="."]:eq(0) :input', 5); + test_count ('#content ul.sub_list:eq(0) a', 1); + test_text ('#content ul.sub_list:eq(0) a:eq(0)[href="/profile-pw/"]', 'Password'); + test_count ('form#profile[action="."]:eq(0) :input', 5); test_form_field ('profile', 'id_email', 'text', 0, 'E-mail address', true); test_form_field ('profile', 'id_first_name','text', 1, 'First name'); test_form_field ('profile', 'id_last_name', 'text', 2, 'Last name'); test_form_field ('profile', 'id_tags', 'text', 3, 'Tags'); test_val ('#profile :input:eq(4)[type=submit]', 'Save'); - test_unlogged_footer (); - }); + test_unlogged_footer (); + }); suite ('edit password page conformity', function () { - test_page_loading ('/profile-pw/', 'Your profile [(]'+w.USER_ADMIN+'[)]\n - '+t['#id_workspace_name']); + test_page_loading ('/profile-pw/', 'Your profile [(]'+w.USER_ADMIN+'[)]\n - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN, no_tagline); - test_count ('#content ul.sub_list:eq(0) a', 1); - test_text ('#content ul.sub_list:eq(0) a:eq(0)[href="/profile/"]', 'Profile'); - test_count ('form#profile[action="."]:eq(0) :input', 4); + test_count ('#content ul.sub_list:eq(0) a', 1); + test_text ('#content ul.sub_list:eq(0) a:eq(0)[href="/profile/"]', 'Profile'); + test_count ('form#profile[action="."]:eq(0) :input', 4); test_form_field ('profile', 'id_old_password', 'password', 0, 'Old password', true); test_form_field ('profile', 'id_new_password1', 'password', 1, 'New password', true); test_form_field ('profile', 'id_new_password2', 'password', 2, 'New password confirmation', true); test_val ('#profile :input:eq(3)[type=submit]', 'Save'); - test_unlogged_footer (); - }); + test_unlogged_footer (); + }); - suite ('people list page conformity', function () { - test_page_loading ('/user/', 'People\' list\n - '+t['#id_workspace_name']); - test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#user ul.sub_list:eq(0) a', 2); - test_text ('#user ul.sub_list:eq(0) a:eq(0)[href="/user/add/"]', 'Add a new user'); - test_text ('#user ul.sub_list:eq(0) a:eq(1)[href="/user/mass-add/"]', 'Add users in bulk'); - // TOTEST : filter by tag -> commentator user should be tagged commentator - test_count ('form#filter_form[action="."] :input', 1); + suite ('people list page conformity', function () { + test_page_loading ('/user/', 'People\' list\n - '+t['#id_workspace_name']); + test_logged_header (w.USER_ADMIN); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#user ul.sub_list:eq(0) a', 2); + test_text ('#user ul.sub_list:eq(0) a:eq(0)[href="/user/add/"]', 'Add a new user'); + test_text ('#user ul.sub_list:eq(0) a:eq(1)[href="/user/mass-add/"]', 'Add users in bulk'); + // TOTEST : filter by tag -> commentator user should be tagged commentator + test_count ('form#filter_form[action="."] :input', 1); test_text ('#filter_form a[href="?display=1"]', 'Display suspended users'); - test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible); - // TOTEST : pagination - // TOTEST : Bulk Actions -> Apply does enable - test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', '- Bulk Actions -', non_visible); - test_text ('select#bulk_actions option:eq(1)[value="disable"]', 'Suspend access', non_visible); - test_text ('select#bulk_actions option:eq(2)[value="enable"]', 'Enable access', non_visible); - test_text ('select#bulk_actions option:eq(3)[value="role_1"]', 'Change role to Manager', non_visible); - test_text ('select#bulk_actions option:eq(4)[value="role_2"]', 'Change role to Editor', non_visible); - test_text ('select#bulk_actions option:eq(5)[value="role_3"]', 'Change role to Moderator', non_visible); - test_text ('select#bulk_actions option:eq(6)[value="role_4"]', 'Change role to Commentator', non_visible); - test_text ('select#bulk_actions option:eq(7)[value="role_5"]', 'Change role to Observer', non_visible); - test_val ('form#user_form input#apply[type=button][disabled]', 'Apply'); - test_count ('table.large_table:eq(1) th', 6); - test_val ('table.large_table:eq(1) th:eq(0) input#all_check[type="checkbox"]', 'on'); - test_text ('table.large_table:eq(1) th:eq(1) a[href="?order=user__username"]', 'User'); - test_text ('table.large_table:eq(1) th:eq(2) a[href="?order=user__email"]', 'Email'); - test_text ('table.large_table:eq(1) th:eq(3) a[href="?order=-user__date_joined"]', 'Date joined'); - test_text ('table.large_table:eq(1) th:eq(4) a[href="?order=role__name"]', 'Role'); - test_text ('table.large_table:eq(1) th:eq(5)', 'Last week activity'); + test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible); + // TOTEST : pagination + // TOTEST : Bulk Actions -> Apply does enable + test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', '- Bulk Actions -', non_visible); + test_text ('select#bulk_actions option:eq(1)[value="disable"]', 'Suspend access', non_visible); + test_text ('select#bulk_actions option:eq(2)[value="enable"]', 'Enable access', non_visible); + test_text ('select#bulk_actions option:eq(3)[value="role_1"]', 'Change role to Manager', non_visible); + test_text ('select#bulk_actions option:eq(4)[value="role_2"]', 'Change role to Editor', non_visible); + test_text ('select#bulk_actions option:eq(5)[value="role_3"]', 'Change role to Moderator', non_visible); + test_text ('select#bulk_actions option:eq(6)[value="role_4"]', 'Change role to Commentator', non_visible); + test_text ('select#bulk_actions option:eq(7)[value="role_5"]', 'Change role to Observer', non_visible); + test_val ('form#user_form input#apply[type=button][disabled]', 'Apply'); + test_count ('table.large_table:eq(1) th', 6); + test_val ('table.large_table:eq(1) th:eq(0) input#all_check[type="checkbox"]', 'on'); + test_text ('table.large_table:eq(1) th:eq(1) a[href="?order=user__username"]', 'User'); + test_text ('table.large_table:eq(1) th:eq(2) a[href="?order=user__email"]', 'Email'); + test_text ('table.large_table:eq(1) th:eq(3) a[href="?order=-user__date_joined"]', 'Date joined'); + test_text ('table.large_table:eq(1) th:eq(4) a[href="?order=role__name"]', 'Role'); + test_text ('table.large_table:eq(1) th:eq(5)', 'Last week activity'); test_text ('table.large_table:eq(1) tr:last a[href="/user/-/edit/"]', 'Anonymous users'); test_text ('table.large_table:eq(1) a.main_object_title[href="/profile/"]', w.USER_ADMIN); test_text ('table.large_table:eq(1) div.hidden-user-actions a[href="/profile/"]', 'Your profile'); // TOTEST presence of commentator and editor user - test_unlogged_footer (); - }); + test_unlogged_footer (); + }); suite ('check user number', function () { - test_page_loading ('/user/?display=1', 'People\' list\n - '+t['#id_workspace_name']); - test ('#user_form input count', dsl (function () { - elt ('form#user_form[action="."] :input').count (function (c) { - var n = 6 + (z.user_nb % 10) * 2; - if (c != n) throw 'expected computed '+n+' to equal got '+c; - }); - })); - test ('#paginator "of #" value', dsl (function () { - elt ('span#paginator').text (function (t) { - var r = t.match (/\s\d+-\d+ of (\d+)\s/m); - if (r.length != 2) throw 'expected 2 matches got '+r.length; - if (r[1] != z.user_nb) throw 'expected paginator total ('+r[1]+') to be '+z.user_nb; - }); - })); - }); + test_page_loading ('/user/?display=1', 'People\' list\n - '+t['#id_workspace_name']); + test_count ('#user_form :input', 6 + (t.user_nb % 10) * 2); + test_match ('#paginator', new RegExp ('\\s\\d+-\\d+ of '+t.user_nb+'\\s','m')); + }); suite ('add a user page conformity', function () { - test_page_loading ('/user/add/', 'Add a new user\n - '+t['#id_workspace_name']); + test_page_loading ('/user/add/', 'Add a new user\n - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#user ul.sub_list:eq(0) a', 2); - test_text ('#user ul.sub_list:eq(0) a:eq(0)[href="/user/"]', 'Users\' list'); - test_text ('#user ul.sub_list:eq(0) a:eq(1)[href="/user/mass-add/"]', 'Add users in bulk'); - test_count ('#user form[action="."]:eq(0) :input', 8); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#user ul.sub_list:eq(0) a', 2); + test_text ('#user ul.sub_list:eq(0) a:eq(0)[href="/user/"]', 'Users\' list'); + test_text ('#user ul.sub_list:eq(0) a:eq(1)[href="/user/mass-add/"]', 'Add users in bulk'); + test_count ('#user form[action="."]:eq(0) :input', 8); test_form_field ('user', 'id_email', 'text', 0, 'E-mail address', true); test_form_field ('user', 'id_first_name', 'text', 1, 'First name'); test_form_field ('user', 'id_last_name', 'text', 2, 'Last name'); @@ -419,15 +379,15 @@ test_form_field ('user', 'id_role', 'select', 4, 'Workspace level role'); test_form_field ('user', 'id_note', 'textarea', 5, 'Note'); test_count ('select#id_role option', 6); - test_text ('select#id_role option:eq(0)[value][selected]', '---------', non_visible); - test_text ('select#id_role option:eq(1)[value="1"]', 'Manager', non_visible); - test_text ('select#id_role option:eq(2)[value="2"]', 'Editor', non_visible); - test_text ('select#id_role option:eq(3)[value="3"]', 'Moderator', non_visible); - test_text ('select#id_role option:eq(4)[value="4"]', 'Commentator', non_visible); - test_text ('select#id_role option:eq(5)[value="5"]', 'Observer', non_visible); + test_text ('select#id_role option:eq(0)[value][selected]', '---------', non_visible); + test_text ('select#id_role option:eq(1)[value="1"]', 'Manager', non_visible); + test_text ('select#id_role option:eq(2)[value="2"]', 'Editor', non_visible); + test_text ('select#id_role option:eq(3)[value="3"]', 'Moderator', non_visible); + test_text ('select#id_role option:eq(4)[value="4"]', 'Commentator', non_visible); + test_text ('select#id_role option:eq(5)[value="5"]', 'Observer', non_visible); test_val ('#user :input:eq(6)[type=submit]', 'Add user'); test_val ('#user :input:eq(7)#cancel_button[type=button]', 'Cancel'); - test_unlogged_footer (); + test_unlogged_footer (); test ('submit empty fields', dsl(function () { elt ('#user input[type="submit"]').click (); @@ -437,31 +397,31 @@ test_form_field ('user div.error', 'id_email', 'text', 0, 'E-mail address', true); test_match ('#user div.help_text:eq(0) span.error-text:eq(0)', /This field is required/m); // X TOTEST add user (pending) - }); + }); suite ('add users in bulk page conformity', function () { - test_page_loading ('/user/mass-add/', 'Add users in bulk\n - '+t['#id_workspace_name']); + test_page_loading ('/user/mass-add/', 'Add users in bulk\n - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#user ul.sub_list:eq(0) a', 2); - test_text ('#user ul.sub_list:eq(0) a:eq(0)[href="/user/"]', 'Users\' list'); - test_text ('#user ul.sub_list:eq(0) a:eq(1)[href="/user/add/"]', 'Add a new user'); - test_count ('#user form[action="."]:eq(0) :input', 6); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#user ul.sub_list:eq(0) a', 2); + test_text ('#user ul.sub_list:eq(0) a:eq(0)[href="/user/"]', 'Users\' list'); + test_text ('#user ul.sub_list:eq(0) a:eq(1)[href="/user/add/"]', 'Add a new user'); + test_count ('#user form[action="."]:eq(0) :input', 6); test_form_field ('user', 'id_email', 'textarea', 0, 'Emails', true); test_form_field ('user', 'id_tags', 'text', 1, 'Tags'); test_form_field ('user', 'id_role', 'select', 2, 'Workspace level role'); test_form_field ('user', 'id_note', 'textarea', 3, 'Note'); test_count ('select#id_role option', 6); - test_text ('select#id_role option:eq(0)[value][selected]', '---------', non_visible); - test_text ('select#id_role option:eq(1)[value="1"]', 'Manager', non_visible); - test_text ('select#id_role option:eq(2)[value="2"]', 'Editor', non_visible); - test_text ('select#id_role option:eq(3)[value="3"]', 'Moderator', non_visible); - test_text ('select#id_role option:eq(4)[value="4"]', 'Commentator', non_visible); - test_text ('select#id_role option:eq(5)[value="5"]', 'Observer', non_visible); + test_text ('select#id_role option:eq(0)[value][selected]', '---------', non_visible); + test_text ('select#id_role option:eq(1)[value="1"]', 'Manager', non_visible); + test_text ('select#id_role option:eq(2)[value="2"]', 'Editor', non_visible); + test_text ('select#id_role option:eq(3)[value="3"]', 'Moderator', non_visible); + test_text ('select#id_role option:eq(4)[value="4"]', 'Commentator', non_visible); + test_text ('select#id_role option:eq(5)[value="5"]', 'Observer', non_visible); test_val ('#user :input:eq(4)[type=submit]', 'Add users'); test_val ('#user :input:eq(5)#cancel_button[type=button]', 'Cancel'); // X TOTEST add users (pending) -> can't be deleted - test_unlogged_footer (); + test_unlogged_footer (); test ('submit empty fields', dsl(function () { elt ('#user input[type="submit"]').click (); @@ -470,22 +430,22 @@ test_count ('div.help_text span.error-text', 1); test_form_field ('user div.error', 'id_email', 'textarea', 0, 'Emails', true); test_match ('#user div.help_text:eq(0) span.error-text:eq(0)', /This field is required/m); - }); + }); suite ('settings page conformity', function () { - test_page_loading ('/settings/', 'Settings - '+t['#id_workspace_name']); + test_page_loading ('/settings/', 'Settings - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#settings ul.sub_list:eq(0) a', 1); - test_text ('#settings ul.sub_list:eq(0) a:eq(0)[href="/settings/design/"]', 'Appearance'); - test_count ('#settings form[action="."]:eq(0) :input', 12); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#settings ul.sub_list:eq(0) a', 1); + test_text ('#settings ul.sub_list:eq(0) a:eq(0)[href="/settings/design/"]', 'Appearance'); + test_count ('#settings form[action="."]:eq(0) :input', 12); test_form_field ('settings', 'id_workspace_name', 'text', 0, 'Workspace name'); test_form_field ('settings', 'id_workspace_tagline', 'text', 1, 'Workspace tagline'); test_form_field ('settings', 'id_workspace_registration', 'checkbox', 2, 'Workspace registration'); test_form_field ('settings', 'id_workspace_registration_moderation', 'checkbox', 3, 'Workspace registration moderation'); test_form_field ('settings', 'id_workspace_role_model', 'select', 4, 'Role model'); - test_text ('select#id_workspace_role_model option:eq(0)[selected][value="generic"]', 'Generic', non_visible); - test_text ('select#id_workspace_role_model option:eq(1)[value="teacher"]', 'Class (education)', non_visible); + test_text ('select#id_workspace_role_model option:eq(0)[selected][value="generic"]', 'Generic', non_visible); + test_text ('select#id_workspace_role_model option:eq(1)[value="teacher"]', 'Class (education)', non_visible); test_form_field ('settings', 'id_workspace_category_1', 'text', 5, 'Label for the first category of comments'); test_form_field ('settings', 'id_workspace_category_2', 'text', 6, 'Label for the second category of comments'); test_form_field ('settings', 'id_workspace_category_3', 'text', 7, 'Label for the third category of comments'); @@ -495,15 +455,15 @@ test_val ('#settings :input:eq(11)#cancel_button[type=button]', 'Cancel'); // TOTEST Workspace registration feature (with newly accessible page) test_unlogged_footer (); - }); + }); suite ('settings design page conformity', function () { - test_page_loading ('/settings/design/', 'Settings - '+t['#id_workspace_name']); + test_page_loading ('/settings/design/', 'Settings - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN); - test_default_tabs (); - test_count ('#settings ul.sub_list:eq(0) a', 1); - test_text ('#settings ul.sub_list:eq(0) a:eq(0)[href="/settings/"]', 'General'); - test_count ('#settings form[action="."]:eq(0) :input', 7); + test_default_tabs (t.text_nb, t.user_nb); + test_count ('#settings ul.sub_list:eq(0) a', 1); + test_text ('#settings ul.sub_list:eq(0) a:eq(0)[href="/settings/"]', 'General'); + test_count ('#settings form[action="."]:eq(0) :input', 7); test_form_field ('settings', 'id_workspace_logo_file', 'file', 0, 'Workspace logo'); test_form_field ('settings', 'id_custom_css', 'textarea', 1, 'Custom CSS rules'); test_form_field ('settings', 'id_custom_font', 'text', 2, 'Custom font'); @@ -512,12 +472,12 @@ test_val ('#settings :input:eq(5)#cancel_button[type=button]', 'Cancel'); test_val ('#settings :input:eq(6)#delete_logo_button[type=submit]', 'Delete logo'); test_unlogged_footer (); - }); + }); suite ('followup page conformity', function () { test_page_loading ('/followup/', 'Followup\n - '+t['#id_workspace_name']); test_logged_header (w.USER_ADMIN); - test_default_tabs (); + test_default_tabs (t.text_nb, t.user_nb); test_text ('#followup a:eq(0)[href="/help/#public_private_feed"]', '?'); test_match ('#followup a:eq(1)[href$="/feed/"]', new RegExp (w.WORKSPACE_URL+'feed/', 'm')); test_text ('#followup a:eq(2)[href="/help/#public_private_feed"]', '?'); @@ -544,44 +504,17 @@ // tester que si Text preferences -> custom -> #textcontainer.custom font: Test_Sopinspace_custom_font // #textcontainer #add_comment_btn span -> #textcontainer font-family: Test_Sopinspace - suite ('settings restoration', function () { - test_page_loading ('/settings/', 'Settings'); - test_fill_settings (z); - test ('Restore settings ', dsl (function () { - elt ('#settings input[type="submit"]').click (); - browser.waitForPageLoad (); - })); - test_page_loading ('/settings/design/', 'Settings'); - test_fill_design (z); - test ('Restore design settings ', dsl (function () { - elt ('#settings input[type="submit"]').click (); - browser.waitForPageLoad (); - })); - // next instruction must be a page loading - // test_page_loading ('/settings/', 'Settings'); - }); - }); -function test_default_tabs () { +function test_default_tabs (text_nb, user_nb) { test_count ('#main-tabs a', 5); test_text ('#main-tabs li:nth-of-type(1) a[href="/"]', 'Dashboard'); test_match ('#main-tabs li:nth-of-type(2) a[href="/text/"]', /^Texts \(\d+\) $/); test_match ('#main-tabs li:nth-of-type(3) a[href="/user/"]', /^People \(\d+\)$/); test_text ('#main-tabs li:nth-of-type(4) a[href="/settings/"]', 'Settings'); test_text ('#main-tabs li:nth-of-type(5) a[href="/followup/"]', 'Followup'); - test ('right tab nb', dsl(function () { - elt ('#main-tabs a[href="/text/"]').text (function (t) { - var r = t.match (/^Texts \((\d+)\) $/); - if (r.length != 2) throw 'for Texts expected 2 matches got '+r.length; - if (z.text_nb != r[1]) throw 'expected tab text nb ('+r[1]+') to be '+z.text_nb; - }); - elt ('#main-tabs a[href="/user/"]').text (function (t) { - var r = t.match (/^People \((\d+)\)$/); - if (r.length != 2) throw 'for People expected 2 matches got '+r.length; - if (z.user_nb != r[1]) throw 'expected tab people nb ('+r[1]+') to be '+z.user_nb; - }); - })); + test_match ('#main-tabs a[href="/text/"]', new RegExp ('^Texts\\s*\\('+text_nb+'\\)\\s*$')); + test_match ('#main-tabs a[href="/user/"]', new RegExp ('^People\\s*\\('+user_nb+'\\)\\s*$')); } function test_logged_header (username, is_tagline) { @@ -622,15 +555,7 @@ test_text ('#footer a:nth-of-type(10)[href="/i18n/setlang/bg/"]', 'Български'); } -function test_readz_field (field_id) { - test ('get '+field_id, dsl(function () { - element (field_id).val (function (v) { - z[field_id] = v; - }); - })); -} - -function test_fill_field (field_id, stored) { +function test_fill_field (field_id, stored) { test ('set '+field_id, dsl(function () { input (field_id).enter (stored[field_id]); })); @@ -655,6 +580,7 @@ test_fill_field ('#id_custom_titles_font', s); } + function test_i18n () { test ('can change lang to french', dsl(function () { element ('#footer a[href="/i18n/setlang/fr/"]').click (); @@ -683,8 +609,8 @@ } /** Test if the selected DOM element is defined or has a given value : .val() - * s : CSS selector - * e : expected value, if omited, test existence + * s : CSS selector + * e : expected value, if omited, test existence */ function test_val (s, e) { e = typeof e == 'undefined' ? '' : e; // .val() returns defined ? '' : undefined; // if no value @@ -694,9 +620,9 @@ } /** Test if the selected DOM element has the given text : .text() - * s : CSS selector - * e : expected value - * v : should we test a visible value ? + * s : CSS selector + * e : expected value + * v : should we test a visible value ? */ function test_text (s, e, v) { v = typeof v == 'undefined' ? true : v; @@ -706,8 +632,8 @@ } /** Test if the selected DOM element .text() value match the given regexp - * s : CSS selector - * r : regexp to match + * s : CSS selector + * r : regexp to match */ function test_match (s, r) { test (s+' text match '+r, dsl(function () { @@ -716,8 +642,8 @@ } /** Count selector occurences - * s : CSS selector - * e : expected count + * s : CSS selector + * e : expected count */ function test_count (s, e) { test (s+' count is '+e, dsl(function () { @@ -747,8 +673,8 @@ } /** Ensure the given element is visible - * s : CSS selector of the DOM element to check - * v : should the element being visible + * s : CSS selector of the DOM element to check + * v : should the element being visible */ function elt (s, v) { return element (s + (v ? ':visible' : ''));