# HG changeset patch # User Simon Descarpentries # Date 1397501484 -7200 # Node ID a8ab808d33c31748b23b509a45f8f9042fbf3664 # Parent 57d3834c5c0110f48ca6c062a61425179d92e424 Test bulk text deletion with new karma-e2e-dsl tweaked version diff -r 57d3834c5c01 -r a8ab808d33c3 test-suite/README.txt --- a/test-suite/README.txt Mon Apr 14 11:05:01 2014 +0200 +++ b/test-suite/README.txt Mon Apr 14 20:51:24 2014 +0200 @@ -17,7 +17,8 @@ -------------- apt-get install npm sudo ln /usr/bin/nodejs /usr/bin/node # /usr/share/doc/nodejs/README.Debian -sudo npm install -g karma karma-mocha karma-e2e-dsl # goes here /usr/local/lib/node_modules/ +sudo npm install -g karma karma-mocha # install things in /usr/local/lib/node_modules/ +sudo npm install -g git://github.com/Siltaar/karma-e2e-dsl # to get the improved karma-e2e-dsl Starting comt : diff -r 57d3834c5c01 -r a8ab808d33c3 test-suite/tests/000_test_helpers.js --- a/test-suite/tests/000_test_helpers.js Mon Apr 14 11:05:01 2014 +0200 +++ b/test-suite/tests/000_test_helpers.js Mon Apr 14 20:51:24 2014 +0200 @@ -29,7 +29,17 @@ })); } -/** Test if the selected DOM element is defined or has a given value : .val() +/** Test if the selected DOM element .text() value match the given regexp + * s : CSS selector + * r : regexp to match + */ +function test_match (s, r) { + test (s+' text match '+r, dsl(function () { + expect (elt (s).text ()).toMatch (r); + })); +} + +/** Test if the selected DOM element has a given value : .val() * s : CSS selector * e : expected value, if omited, test existence */ @@ -40,6 +50,9 @@ })); } +/** + * + */ function test_exist (s) { test_val (s); } @@ -56,16 +69,6 @@ })); } -/** Test if the selected DOM element .text() value match the given regexp - * s : CSS selector - * r : regexp to match - */ -function test_match (s, r) { - test (s+' text match '+r, dsl(function () { - expect (elt (s).text ()).toMatch (r); - })); -} - /** Count selector occurences * s : CSS selector * e : expected count @@ -109,27 +112,32 @@ } /** - * Click somewhere + * Click on something * s : selector of the item to click on + * w : should we wait for a page to load in the browser after the click * v : is the element visible or not */ -function test_click (s, v) { - test ('click '+s, dsl(function () { - elt (s, v).click (); - })); +function test_click (s, w, v) { + var t = 'click '+ w ? 'to submit form ' : ''; + test (t+s, dsl(function () { + elt (s, v).click (); + if (w) + browser.waitForPageLoad (); + })); } /** - * Submit a form - * s : selector of the submit button + * Send submit event to the given form + * s : selector of the form to submit */ function test_submit (s) { - test ('submit '+s, dsl(function () { - elt (s).click (); + test ('send submit event to '+s, dsl(function () { + elt (s).submit (); browser.waitForPageLoad (); })); } + /** * Reload a page */ diff -r 57d3834c5c01 -r a8ab808d33c3 test-suite/tests/001_comt-unlogged-prelude.js --- a/test-suite/tests/001_comt-unlogged-prelude.js Mon Apr 14 11:05:01 2014 +0200 +++ b/test-suite/tests/001_comt-unlogged-prelude.js Mon Apr 14 20:51:24 2014 +0200 @@ -4,6 +4,8 @@ // set softtabstop=4 " as above // set shiftwidth=4 " as above +const wait_page_load = true; + suite ('comt unlogged prelude', function () { this.timeout(20000); @@ -13,11 +15,11 @@ test_unlogged_header (); test_exist ('form#profile[action="."]'); // the form exists test_count ('form#profile :input', 7); // it has no more than 5 labels (may be no more fields) - test_field ('profile', 'id_name', 'text', 0, 'Your name', true); // the field id_name is… - test_field ('profile', 'id_email', 'text', 1, 'Your email address', true); - test_field ('profile', 'id_title', 'text', 2, 'Subject of the message', true); - test_field ('profile', 'id_body', 'textarea', 3, 'Body of the message', true); - test_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false); + test_field ('profile', 'id_name', 'text', 0, 'Your name', true); // the field id_name is… + test_field ('profile', 'id_email', 'text', 1, 'Your email address', true); + test_field ('profile', 'id_title', 'text', 2, 'Subject of the message', true); + test_field ('profile', 'id_body', 'textarea', 3, 'Body of the message', true); + test_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false); test_val ('#profile input[type=submit]','Send'); // test that a the .val() of the element is test_val ('input#cancel_button[type=button]', 'Cancel'); test_unlogged_footer (); @@ -48,33 +50,33 @@ suite ('contact page mandatory field test', function () { test_page_loading ('/contact/', 'Contact'); - test_submit('#profile input[type="submit"]'); - test_count ('div.help_text span.error-text', 4); - test_field ('profile div.error', 'id_name', 'text', 0, 'Your name', true); // the field id_name is… - test_field ('profile div.error', 'id_email', 'text', 1, 'Your email address', true); - test_field ('profile div.error', 'id_title', 'text', 2, 'Subject of the message', true); - test_field ('profile div.error', 'id_body', 'textarea', 3, 'Body of the message', true); - test_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false); + test_click ('#profile input[type="submit"]', wait_page_load); + test_count ('div.help_text span.error-text', 4); + test_field ('profile div.error', 'id_name', 'text', 0, 'Your name', true); // the field id_name is… + test_field ('profile div.error', 'id_email', 'text', 1, 'Your email address', true); + test_field ('profile div.error', 'id_title', 'text', 2, 'Subject of the message', true); + test_field ('profile div.error', 'id_body', 'textarea', 3, 'Body of the message', true); + test_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false); }); suite ('reset password page conformity', function () { test_page_loading ('/password_reset/', 'Reset my password'); test_unlogged_header (); test_count ('form#profile :input', 3); - test_field ('profile', 'id_email', 'text', 1, 'E-mail', true); + test_field ('profile', 'id_email', 'text', 1, 'E-mail', true); test_val ('#profile input[type=submit]', 'Reset my password'); test_unlogged_footer (); - test_submit('#profile input[type="submit"]'); - test_count ('div.help_text span.error-text', 1); - test_field ('profile div.error', 'id_email', 'text', 0, 'E-mail', true); + test_click ('#profile input[type="submit"]', wait_page_load); + test_count ('div.help_text span.error-text', 1); + test_field ('profile div.error', 'id_email', 'text', 0, 'E-mail', true); }); suite ('login page conformity', function () { test_page_loading ('/', 'Home'); test_unlogged_header (); test_count ('form#login[action="/login/"] :input', 3); - test_field ('login', 'id_username', 'text', 0, 'Username', true); - test_field ('login', 'id_password', 'password', 1, 'Password', true); + test_field ('login', 'id_username', 'text', 0, 'Username', true); + test_field ('login', 'id_password', 'password', 1, 'Password', true); test_val ('form#login input[type=submit]', 'Login'); test_text ('form#login a[href="/password_reset/"]', 'Forgot password?'); test_unlogged_footer (); @@ -84,9 +86,9 @@ browser.navigateTo ('/'); })); test_page_loading ('/login/', 'Login'); - test_submit('#login input[type="submit"]'); - test_field ('login div.error', 'id_username', 'text', 0, 'Username', true); - test_field ('login div.error', 'id_password', 'password', 1, 'Password', true); + test_click ('#login input[type="submit"]', wait_page_load); + test_field ('login div.error', 'id_username', 'text', 0, 'Username', true); + test_field ('login div.error', 'id_password', 'password', 1, 'Password', true); }); }); diff -r 57d3834c5c01 -r a8ab808d33c3 test-suite/tests/002_comt-logged-admin.js --- a/test-suite/tests/002_comt-logged-admin.js Mon Apr 14 11:05:01 2014 +0200 +++ b/test-suite/tests/002_comt-logged-admin.js Mon Apr 14 20:51:24 2014 +0200 @@ -11,8 +11,9 @@ for (var i = 20; i--;) long_text += 'Contenu du troisième texte.
Sur plusieurs lignes
'; -const non_visible = false, +const hidden = false, no_tagline = false, + wait_page_load = true, c = { '#id_workspace_name': 'Test workspace name', '#id_workspace_tagline': 'Test workspace tagline', @@ -51,7 +52,7 @@ suite ('comt logged admin', function () { - this.timeout(20000); + this.timeout(200000); suite ('logs as an admin', function () { test ('logs an admin in', dsl(function () { @@ -68,13 +69,13 @@ suite ('setting settings to test-values', function () { test_page_loading ('/settings/', 'Settings'); test_fill_settings (c); - test_val ('#id_workspace_name', c['#id_workspace_name']); - test_submit ('#settings input[type="submit"]'); + test_val ('#id_workspace_name', c['#id_workspace_name']); + test_click ('#settings input[type="submit"]', wait_page_load); test_page_loading ('/settings/', 'Settings'); - test_text ('#content h1.main_title a[href="/"]', c['#id_workspace_name']); + test_text ('#content h1.main_title a[href="/"]', c['#id_workspace_name']); test_page_loading ('/settings/design/', 'Settings'); test_fill_design (c); - test_submit ('#settings input[type="submit"]'); + test_click ('#settings input[type="submit"]', wait_page_load); }); suite ('admin dashboard page conformity', function () { @@ -131,13 +132,13 @@ 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_text ('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', hidden); + test_text ('select#id_format option:eq(1)[value="rst"]', 'rst', hidden); + test_text ('select#id_format option:eq(2)[value="html"]', 'html', hidden); test_count ('.markdown #markItUpId_content li', 20); // How many buttons in the WYSIWYG editor toolbar ? test_unlogged_footer (); - test_submit('#text input[type="submit"]'); - test_count ('div.help_text span.error-text', 2); + test_click ('#text input[type="submit"]', wait_page_load); + test_count ('div.help_text span.error-text', 2); test_field ('text div.error', 'id_title', 'text', 0, 'Title', true); test_field ('text div.error', 'id_content', 'textarea', 1, 'Content', true); }); @@ -158,12 +159,12 @@ 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_text ('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', hidden); + test_text ('select#id_format option:eq(1)[value="rst"]', 'rst', hidden); + test_text ('select#id_format option:eq(2)[value="html"]', 'html', hidden); test_unlogged_footer (); - test_submit('#text input[type="submit"]'); - test_count ('div.help_text span.error-text', 1); + test_click ('#text input[type="submit"]', wait_page_load); + test_count ('div.help_text span.error-text', 1); test_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); }); @@ -181,7 +182,7 @@ 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('#text input[type="submit"]'); + test_click ('#text input[type="submit"]', wait_page_load); test_count ('div.help_text span.error-text', 1); test_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); @@ -207,7 +208,7 @@ // tester que si Text preferences -> custom -> #textcontainer.custom font: Test_Sopinspace_custom_font // #textcontainer #add_comment_btn span -> #textcontainer font-family: Test_Sopinspace - suite.skip ('texts list page conformity', function () { + suite ('texts list page conformity', function () { test_page_loading ('/text/', 'Texts\n - '+c['#id_workspace_name']); test_logged_header (w.USER_ADMIN); test_default_tabs (t.text_nb, t.user_nb); @@ -216,7 +217,7 @@ 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 ('form#filter_form[action="."] :input', 1); - test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible); + test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', hidden); test_page_loading ('/text/?tag_selected=Text+Troisième', 'Texts\n - '+c['#id_workspace_name']); test_count ('#texts_form :input', 4 + 3); test_match ('#paginator', /\s1-4 of 4\s/m); @@ -253,8 +254,8 @@ test_count ('#texts_form :input', (t.text_nb < 10 ? t.text_nb : 10) + 3); test_match ('#paginator', new RegExp ('\\s1-10 of '+t.text_nb+'\\s','m')); test_page_loading ('/text/', 'Texts\n - '+c['#id_workspace_name']); - test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', non_visible); - test_text ('select#bulk_actions option:eq(1)[value="delete"]', 'Delete', non_visible); + test_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', hidden); + test_text ('select#bulk_actions option:eq(1)[value="delete"]', 'Delete', hidden); test_val ('form#texts_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'); @@ -268,10 +269,10 @@ test_click ('#all_check'); test_count ('form#texts_form input:checked', t.text_nb % 10 + 1); test_val ('form#texts_form input#apply[type=button]:not([disabled])', 'Apply'); -// test_click ('#texts_form #apply'); - test ('submit #texts_form without confirm dialog', dsl(function(){form("#texts_form").submit();})); + // test_click ('#texts_form #apply'); // can't click on the confirm dialog + test_submit ('#texts_form'); test_page_loading ('/text/', 'Texts\n - '+c['#id_workspace_name']); -// t.text_nb -= 2; + t.text_nb -= 2; test_count ('form#texts_form :input', t.text_nb + 3); test_match ('#paginator', new RegExp ('\\s1-10 of '+t.text_nb+'\\s','m')); // TOTEST : unitary delete @@ -280,7 +281,7 @@ }); suite ('edit profile page conformity', function () { - test_page_loading ('/profile/', 'Your profile [(]'+w.USER_ADMIN+'[)]\n - '+c['#id_workspace_name']); + test_page_loading ('/profile/', 'Your profile \\('+w.USER_ADMIN+'\\)\n - '+c['#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'); @@ -316,18 +317,18 @@ // TOTEST : filter by tag -> commentator user should be tagged commentator (to change in fixture) 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); + test_text ('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', hidden); // TOTEST : pagination // TOTEST : Bulk Actions -> Apply does enable // TOTEST display suspended users - 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_text ('select#bulk_actions option:eq(0)[selected][value="-1"]', '- Bulk Actions -', hidden); + test_text ('select#bulk_actions option:eq(1)[value="disable"]', 'Suspend access', hidden); + test_text ('select#bulk_actions option:eq(2)[value="enable"]', 'Enable access', hidden); + test_text ('select#bulk_actions option:eq(3)[value="role_1"]', 'Change role to Manager', hidden); + test_text ('select#bulk_actions option:eq(4)[value="role_2"]', 'Change role to Editor', hidden); + test_text ('select#bulk_actions option:eq(5)[value="role_3"]', 'Change role to Moderator', hidden); + test_text ('select#bulk_actions option:eq(6)[value="role_4"]', 'Change role to Commentator', hidden); + test_text ('select#bulk_actions option:eq(7)[value="role_5"]', 'Change role to Observer', hidden); 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'); @@ -364,16 +365,16 @@ test_field ('user', 'id_role', 'select', 4, 'Workspace level role'); test_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]', '---------', hidden); + test_text ('select#id_role option:eq(1)[value="1"]', 'Manager', hidden); + test_text ('select#id_role option:eq(2)[value="2"]', 'Editor', hidden); + test_text ('select#id_role option:eq(3)[value="3"]', 'Moderator', hidden); + test_text ('select#id_role option:eq(4)[value="4"]', 'Commentator', hidden); + test_text ('select#id_role option:eq(5)[value="5"]', 'Observer', hidden); 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_submit('#user input[type="submit"]'); + test_click ('#user input[type="submit"]', wait_page_load); test_count ('div.help_text span.error-text', 1); test_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); @@ -393,17 +394,17 @@ test_field ('user', 'id_role', 'select', 2, 'Workspace level role'); test_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]', '---------', hidden); + test_text ('select#id_role option:eq(1)[value="1"]', 'Manager', hidden); + test_text ('select#id_role option:eq(2)[value="2"]', 'Editor', hidden); + test_text ('select#id_role option:eq(3)[value="3"]', 'Moderator', hidden); + test_text ('select#id_role option:eq(4)[value="4"]', 'Commentator', hidden); + test_text ('select#id_role option:eq(5)[value="5"]', 'Observer', hidden); 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_submit('#user input[type="submit"]'); + test_click ('#user input[type="submit"]', wait_page_load); test_count ('div.help_text span.error-text', 1); test_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); @@ -421,8 +422,8 @@ test_field ('settings', 'id_workspace_registration', 'checkbox', 2, 'Workspace registration'); test_field ('settings', 'id_workspace_registration_moderation', 'checkbox', 3, 'Workspace registration moderation'); test_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', hidden); + test_text ('select#id_workspace_role_model option:eq(1)[value="teacher"]', 'Class (education)', hidden); test_field ('settings', 'id_workspace_category_1', 'text', 5, 'Label for the first category of comments'); test_field ('settings', 'id_workspace_category_2', 'text', 6, 'Label for the second category of comments'); test_field ('settings', 'id_workspace_category_3', 'text', 7, 'Label for the third category of comments'); @@ -531,6 +532,6 @@ })); test_fill_field ('#id_tags', c['texts'][i]); - test_submit ('#save_button'); + test_click ('#save_button', wait_page_load); t.text_nb++; }