test-suite/tests/tests.js
changeset 624 3dd70d01cec2
parent 623 09640f41fed1
child 625 eb52900a0bbf
equal deleted inserted replaced
623:09640f41fed1 624:3dd70d01cec2
     1 
       
     2 // " Vim settings
       
     3 // set tabstop=4		  " number of spaces in a tab
       
     4 // set softtabstop=4	  " as above
       
     5 // set shiftwidth=4		  " as above
       
     6 
       
     7 
       
     8 // check that public texts still work while unlogged
       
     9 // check that non public texts are unavailable
       
    10 // Are the public texts displayed in the login page ?
       
    11 
       
    12 var w = __karma__.config.w;
       
    13 const non_visible = false, no_tagline = false;
       
    14 const t = {
       
    15 	'#id_workspace_name':	'Test workspace name',
       
    16 	'#id_workspace_tagline':	'Test workspace tagline',
       
    17 	'#id_workspace_registration':		'on',		// registration
       
    18 	'#id_workspace_registration_moderation':	'on',		// registration moderation
       
    19 	'#id_workspace_role_model':	'generic',
       
    20 	'#id_workspace_category_1':	'ws_cat_1',
       
    21 	'#id_workspace_category_2':	'ws_cat_2',
       
    22 	'#id_workspace_category_3':	'ws_cat_3',
       
    23 	'#id_workspace_category_4':	'ws_cat_4',
       
    24 	'#id_workspace_category_5':	'ws_cat_5',
       
    25 	'#id_custom_css': "h2 {  font-family: Test_Sopinspace !important; }",
       
    26 	'#id_custom_font': 'Test_Sopinspace_custom_font',
       
    27 	'#id_custom_titles_font': 'Test_Sopinspace_custom_titles_font',
       
    28 	'text_nb': 0,
       
    29 	'user_nb': 4
       
    30 };
       
    31 
       
    32 
       
    33 suite ('comt', function () {
       
    34 
       
    35 	this.timeout(150000);
       
    36 
       
    37 	suite ('contact page conformity', function () {
       
    38 		test_page_loading ('/contact/', 'Contact');
       
    39 		test_unlogged_header ();
       
    40 		test_val	('form#profile[action="."]'); // the form exists
       
    41 		test_count	('form#profile :input', 7); // it has no more than 5 labels (may be no more fields)
       
    42 		test_form_field ('profile', 'id_name', 'text', 0, 'Your name', true); // the field id_name is…
       
    43 		test_form_field ('profile', 'id_email', 'text', 1, 'Your email address', true);
       
    44 		test_form_field ('profile', 'id_title', 'text', 2, 'Subject of the message', true);
       
    45 		test_form_field ('profile', 'id_body', 'textarea', 3, 'Body of the message', true);
       
    46 		test_form_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false);
       
    47 		test_val	('#profile input[type=submit]','Send'); // test that a the .val() of the element is
       
    48 		test_val	('input#cancel_button[type=button]', 'Cancel');
       
    49 		test_unlogged_footer ();
       
    50 		test		('to check that toBeDefined test still works', dsl(function () {
       
    51 			expect (elt ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined ();
       
    52 		}));
       
    53 		test		('get back to / to avoid bugging next page load', dsl(function () {
       
    54 			browser.navigateTo ('/');
       
    55 		}));
       
    56 	});
       
    57 
       
    58 	suite ('help page conformity', function () {
       
    59 		test_page_loading ('/help/', 'Help');
       
    60 		test_unlogged_header ();
       
    61 		test_unlogged_footer ();
       
    62 	});
       
    63 
       
    64 	suite ('contact page mandatory field test', function () {
       
    65 		test_page_loading ('/contact/', 'Contact');
       
    66 
       
    67 		test ('submit empty fields', dsl(function () {
       
    68 			elt ('#profile input[type="submit"]').click ();
       
    69 			browser.waitForPageLoad ();
       
    70 		}));
       
    71 		test_count ('div.help_text span.error-text', 4);
       
    72 		test_form_field ('profile div.error', 'id_name', 'text', 0, 'Your name', true); // the field id_name is…
       
    73 		test_form_field ('profile div.error', 'id_email', 'text', 1, 'Your email address', true);
       
    74 		test_form_field ('profile div.error', 'id_title', 'text', 2, 'Subject of the message', true);
       
    75 		test_form_field ('profile div.error', 'id_body', 'textarea', 3, 'Body of the message', true);
       
    76 		test_form_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false);
       
    77 	});
       
    78 
       
    79 	suite ('reset password page conformity', function () {
       
    80 		test_page_loading ('/password_reset/', 'Reset my password');
       
    81 		test_unlogged_header ();
       
    82 		test_val	('form#profile[action="."]');
       
    83 		test_count	('form#profile :input', 3);
       
    84 		test_form_field ('profile', 'id_email', 'text', 1, 'E-mail', true);
       
    85 		test_val	('#profile input[type=submit]', 'Reset my password');
       
    86 		test_unlogged_footer ();
       
    87 
       
    88 		test ('submit empty fields', dsl(function () {
       
    89 			elt ('#profile input[type="submit"]').click ();
       
    90 			browser.waitForPageLoad ();
       
    91 		}));
       
    92 
       
    93 		test_count ('div.help_text span.error-text', 1);
       
    94 		test_form_field ('profile div.error', 'id_email', 'text', 0, 'E-mail', true);
       
    95 	});
       
    96 
       
    97 	suite ('login page conformity', function () {
       
    98 		test_page_loading ('/', 'Home');
       
    99 		test_unlogged_header ();
       
   100 		test_val	('form#login[action="/login/"]');
       
   101 		test_count	('form#login[action="/login/"] :input', 3);
       
   102 		test_form_field ('login', 'id_username', 'text', 0, 'Username', true);
       
   103 		test_form_field ('login', 'id_password', 'password', 1, 'Password', true);
       
   104 		test_val	('form#login input[type=submit]', 'Login');
       
   105 		test_text	('form#login a[href="/password_reset/"]', 'Forgot password?');
       
   106 		test_unlogged_footer ();
       
   107 		// test_i18n ();
       
   108 
       
   109 		test ('get back to / to avoid bugging next page load', dsl(function () {
       
   110 			browser.navigateTo ('/');
       
   111 		}));
       
   112 		test_page_loading ('/login/', 'Login');
       
   113 		test ('submit empty fields', dsl(function () {
       
   114 			elt ('#login input[type="submit"]').click ();
       
   115 			browser.waitForPageLoad ();
       
   116 		}));
       
   117 		test_form_field ('login div.error', 'id_username', 'text', 0, 'Username', true);
       
   118 		test_form_field ('login div.error', 'id_password', 'password', 1, 'Password', true);
       
   119 		test ('logs an admin in', dsl(function () {
       
   120 			input ('#id_username').enter (w.USER_ADMIN);
       
   121 			input ('#id_password').enter (w.PASS_ADMIN);
       
   122 			elt ('#login input[type=submit]').click ();
       
   123 			// Must be done here in this test() block
       
   124 			browser.waitForPageLoad ();
       
   125 			browser.navigateTo ('/');
       
   126 			expect (element ('title').text ()).toMatch (/Dashboard/m);
       
   127 		}));
       
   128 	});
       
   129 
       
   130 	suite ('setting settings to test-values', function () {
       
   131 		test_page_loading ('/settings/', 'Settings');
       
   132 		test_fill_settings (t);
       
   133 		test_val ('#id_workspace_name', t['#id_workspace_name']);
       
   134 		test ('Save test settings ', dsl (function () {
       
   135 			elt ('#settings input[type="submit"]').click ();
       
   136 			browser.waitForPageLoad ();
       
   137 		}));
       
   138 		test_page_loading	('/settings/', 'Settings');
       
   139 		test_text ('#content h1.main_title a[href="/"]', t['#id_workspace_name']);
       
   140 		test_page_loading	('/settings/design/', 'Settings');
       
   141 		test_fill_design (t);
       
   142 		test ('Save test design settings ', dsl (function () {
       
   143 			elt ('#settings input[type="submit"]').click ();
       
   144 			browser.waitForPageLoad ();
       
   145 		}));
       
   146 	});
       
   147 
       
   148 	suite ('admin dashboard page conformity', function () {
       
   149 		test_page_loading ('/', 'Dashboard\n - '+t['#id_workspace_name']);
       
   150 		test_logged_header (w.USER_ADMIN);
       
   151 		test_default_tabs (t.text_nb, t.user_nb);
       
   152 		test_count	('table.dash_table', 5);
       
   153 		test_text	('table.dash_table th:eq(0)', 'Actions');
       
   154 		test_match	('table.dash_table:eq(0) a:eq(0)[href="/create/content/"]', /\sCreate a text/);
       
   155 		test_text	('table.dash_table:eq(0) a:eq(1).tip[href="#"]', '\xa0');
       
   156 		test_match	('table.dash_table:eq(0) a:eq(2)[href="/create/upload/"]', /\sUpload a text/);
       
   157 		test_text	('table.dash_table:eq(0) a:eq(3).tip[href="#"]', '\xa0');
       
   158 		test_match	('table.dash_table:eq(0) a:eq(4)[href="/create/import/"]', /\sImport a co-mented text/);
       
   159 		test_text	('table.dash_table:eq(0) a:eq(5).tip[href="#"]', '\xa0');
       
   160 		test_match	('table.dash_table:eq(0) a:eq(6)[href="/user/add/"]', /\sInvite user/);
       
   161 		test_match	('table.dash_table:eq(0) a:eq(7)[href="/profile/"]', /\sEdit your profile/);
       
   162 		test_match	('table.dash_table:eq(0) a:eq(8)[href="/text/"]', /\sView text list/);
       
   163 		test_match	('table.dash_table:eq(0) a:eq(9)[href="/settings/"]', /\sConfigure workspace/);
       
   164 		test_text	('table.dash_table th:eq(1)', 'Recent texts (all)');
       
   165 		test_text	('table.dash_table:eq(1) a:eq(0)[href="/text/"]', 'all');
       
   166 		test_text	('table.dash_table th:eq(2)', 'Recent comments');
       
   167 		test_match	('table.dash_table th:eq(3)', /^Workspace activity\n\s+\(month\/week\/24 hours\)$/m);
       
   168 		test_text	('table.dash_table:eq(3) a:eq(0)[href="?span=month"]', 'month');
       
   169 		test_text	('table.dash_table:eq(3) a:eq(1)[href="?span=day"]', '24 hours');
       
   170 		test_text	('table.dash_table th:eq(4) span.em', 'Activities');
       
   171 		test_unlogged_footer ();
       
   172 	});
       
   173 
       
   174 	suite ('empty texts list page conformity', function () {
       
   175 		test_page_loading	('/text/', 'Texts\n - '+t['#id_workspace_name']);
       
   176 		test_logged_header	(w.USER_ADMIN);
       
   177 		test_default_tabs	(t.text_nb, t.user_nb);
       
   178 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   179 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text');
       
   180 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text');
       
   181 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text');
       
   182 		test_match	('#text', /No texts yet/m);
       
   183 		test_count	('#texts_form :input', 0);
       
   184 	});
       
   185 
       
   186 	suite ('create a text page conformity', function () {
       
   187 		test_page_loading	('/create/content/', 'Create a text - '+t['#id_workspace_name']);
       
   188 		test_logged_header	(w.USER_ADMIN);
       
   189 		test_default_tabs	(t.text_nb, t.user_nb);
       
   190 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   191 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list');
       
   192 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text');
       
   193 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text');
       
   194 		test_count	('#text form[action="."]:eq(0) :input', 6);
       
   195 		test_form_field ('text', 'id_title',	'text', 0, 'Title', true);
       
   196 		test_form_field ('text', 'id_format',	'select', 1, 'Format', true);
       
   197 		test_form_field ('text', 'id_content',	'textarea', 2, 'Content', true);
       
   198 		test_form_field ('text', 'id_tags',		'text', 3, 'Tags');
       
   199 		test_val	('#text :input:eq(4)[type=submit]', 'Save');
       
   200 		test_val	('#text :input:eq(5)#cancel_button[type=button]', 'Cancel');
       
   201 		test_count	('select#id_format option', 3);
       
   202 		test_text	('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', non_visible);
       
   203 		test_text	('select#id_format option:eq(1)[value="rst"]', 'rst', non_visible);
       
   204 		test_text	('select#id_format option:eq(2)[value="html"]', 'html', non_visible);
       
   205 		test_count	('#markItUpId_content li', 20); // How many buttons are in the WYSIWYG editor toolbar ?
       
   206 		test_unlogged_footer ();
       
   207 
       
   208 		test ('submit empty fields', dsl(function () {
       
   209 			elt ('#text input[type="submit"]').click ();
       
   210 			browser.waitForPageLoad ();
       
   211 		}));
       
   212 		test_count ('div.help_text span.error-text', 2);
       
   213 		test_form_field ('text div.error', 'id_title',		'text', 0, 'Title', true);
       
   214 		test_form_field ('text div.error', 'id_content',	'textarea', 1, 'Content', true);
       
   215 	});
       
   216 
       
   217 	suite ('upload text page conformity', function () {
       
   218 		test_page_loading	('/create/upload/', 'Upload a text - '+t['#id_workspace_name']);
       
   219 		test_logged_header	(w.USER_ADMIN);
       
   220 		test_default_tabs	(t.text_nb, t.user_nb);
       
   221 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   222 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list');
       
   223 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/content/"]', 'Create a text');
       
   224 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text');
       
   225 		test_count	('#text form[action="."]:eq(0) :input', 6);
       
   226 		test_form_field ('text', 'id_title',	'text', 0, 'Title');
       
   227 		test_form_field ('text', 'id_format',	'select', 1, 'Format', true);
       
   228 		test_form_field ('text', 'id_tags',		'text', 2, 'Tags');
       
   229 		test_form_field ('text', 'id_file',		'file', 3, 'Upload file');
       
   230 		test_val	('#text :input:eq(4)[type=submit]', 'Save');
       
   231 		test_val	('#text :input:eq(5)#cancel_button[type=button]', 'Cancel');
       
   232 		test_count	('select#id_format option', 3);
       
   233 		test_text	('select#id_format option:eq(0)[value="markdown"][selected]', 'markdown', non_visible);
       
   234 		test_text	('select#id_format option:eq(1)[value="rst"]', 'rst', non_visible);
       
   235 		test_text	('select#id_format option:eq(2)[value="html"]', 'html', non_visible);
       
   236 		test_unlogged_footer ();
       
   237 
       
   238 		test ('submit empty fields', dsl(function () {
       
   239 			elt ('#text input[type="submit"]').click ();
       
   240 			browser.waitForPageLoad ();
       
   241 		}));
       
   242 		test_count ('div.help_text span.error-text', 1);
       
   243 		test_form_field ('text div.error', 'id_file',		'file', 0, 'Upload file');
       
   244 		test_match	('#text div.help_text:eq(3) span.error-text:eq(0)', /You should specify a file to upload/m);
       
   245 	});
       
   246 
       
   247 	suite ('import a co-mented text page conformity', function () {
       
   248 		test_page_loading	('/create/import/', 'Import a co-mented text - '+t['#id_workspace_name']);
       
   249 		test_logged_header	(w.USER_ADMIN);
       
   250 		test_default_tabs	(t.text_nb, t.user_nb);
       
   251 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   252 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/text/"]', 'Text list');
       
   253 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/content/"]', 'Create a text');
       
   254 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/upload/"]', 'Upload a text');
       
   255 		test_count	('#text form[action="."]:eq(0) :input', 3);
       
   256 		test_form_field ('text', 'id_file',	'file', 0, 'Upload XML file', true);
       
   257 		test_val	('#text :input:eq(1)[type=submit]', 'Save');
       
   258 		test_val	('#text :input:eq(2)#cancel_button[type=button]', 'Cancel');
       
   259 		test_unlogged_footer ();
       
   260 
       
   261 		test ('submit empty fields', dsl(function () {
       
   262 			elt ('#text input[type="submit"]').click ();
       
   263 			browser.waitForPageLoad ();
       
   264 		}));
       
   265 		test_count	('div.help_text span.error-text', 1);
       
   266 		test_form_field ('text div.error', 'id_file',		'file', 0, 'Upload XML file', true);
       
   267 		test_match	('#text div.help_text:eq(0) span.error-text:eq(0)', /You should specify a file to upload/m);
       
   268 	});
       
   269 
       
   270 	suite.skip ('texts list page conformity', function () {
       
   271 		test_page_loading	('/text/', 'Texts\n - '+t['#id_workspace_name']);
       
   272 		test_logged_header	(w.USER_ADMIN);
       
   273 		test_default_tabs	(t.text_nb, t.user_nb);
       
   274 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   275 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text');
       
   276 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text');
       
   277 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text');
       
   278 		// TOTEST : filter by tag
       
   279 		test_count	('form#filter_form[action="."] :input', 1);
       
   280 		test_text	('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible);
       
   281 		test_count	('#texts_form :input', 3 + t.text_nb % 10);
       
   282 		test_match	('#paginator', new RegExp ('\\s\\d+-\\d+ of '+t.text_nb+'\\s','m'));
       
   283 		// TOTEST : pagination
       
   284 		// TOTEST : Bulk Actions -> Apply does enable
       
   285 		test_text	('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', non_visible);
       
   286 		test_text	('select#bulk_actions option:eq(1)[value="delete"]', 'Delete', non_visible);
       
   287 		test_val	('form#texts_form input#apply[type=button][disabled]', 'Apply');
       
   288 		test_count	('table.large_table:eq(1) th', 6);
       
   289 		test_val	('table.large_table:eq(1) th:eq(0) input#all_check[type="checkbox"]', 'on');
       
   290 		test_text	('table.large_table:eq(1) th:eq(1) a[href="?order=title"]', 'Text');
       
   291 		test_text	('table.large_table:eq(1) th:eq(2)', 'Author');
       
   292 		test_text	('table.large_table:eq(1) th:eq(3) a[href="?order=-modified"]', 'Modified');
       
   293 		test_text	('table.large_table:eq(1) th:eq(4)', '# comments');
       
   294 		test_text	('table.large_table:eq(1) th:eq(5)', 'Last week activity');
       
   295 		test_unlogged_footer ();
       
   296 	});
       
   297 
       
   298 	suite ('edit profile page conformity', function () {
       
   299 		test_page_loading	('/profile/', 'Your profile [(]'+w.USER_ADMIN+'[)]\n - '+t['#id_workspace_name']);
       
   300 		test_logged_header	(w.USER_ADMIN, no_tagline);
       
   301 		test_count	('#content ul.sub_list:eq(0) a', 1);
       
   302 		test_text	('#content ul.sub_list:eq(0) a:eq(0)[href="/profile-pw/"]', 'Password');
       
   303 		test_count	('form#profile[action="."]:eq(0) :input', 5);
       
   304 		test_form_field ('profile', 'id_email',		'text', 0, 'E-mail address', true);
       
   305 		test_form_field ('profile', 'id_first_name','text', 1, 'First name');
       
   306 		test_form_field ('profile', 'id_last_name',	'text', 2, 'Last name');
       
   307 		test_form_field ('profile', 'id_tags',		'text', 3, 'Tags');
       
   308 		test_val	('#profile :input:eq(4)[type=submit]', 'Save');
       
   309 		test_unlogged_footer ();
       
   310 	});
       
   311 
       
   312 	suite ('edit password page conformity', function () {
       
   313 		test_page_loading	('/profile-pw/', 'Your profile [(]'+w.USER_ADMIN+'[)]\n - '+t['#id_workspace_name']);
       
   314 		test_logged_header	(w.USER_ADMIN, no_tagline);
       
   315 		test_count	('#content ul.sub_list:eq(0) a', 1);
       
   316 		test_text	('#content ul.sub_list:eq(0) a:eq(0)[href="/profile/"]', 'Profile');
       
   317 		test_count	('form#profile[action="."]:eq(0) :input', 4);
       
   318 		test_form_field ('profile', 'id_old_password',	'password', 0, 'Old password', true);
       
   319 		test_form_field ('profile', 'id_new_password1', 'password', 1, 'New password', true);
       
   320 		test_form_field ('profile', 'id_new_password2',	'password', 2, 'New password confirmation', true);
       
   321 		test_val	('#profile :input:eq(3)[type=submit]', 'Save');
       
   322 		test_unlogged_footer ();
       
   323 	});
       
   324 
       
   325 	suite ('people list page conformity', function () {
       
   326 		test_page_loading	('/user/', 'People\' list\n - '+t['#id_workspace_name']);
       
   327 		test_logged_header	(w.USER_ADMIN);
       
   328 		test_default_tabs	(t.text_nb, t.user_nb);
       
   329 		test_count	('#user ul.sub_list:eq(0) a', 2);
       
   330 		test_text	('#user ul.sub_list:eq(0) a:eq(0)[href="/user/add/"]', 'Add a new user');
       
   331 		test_text	('#user ul.sub_list:eq(0) a:eq(1)[href="/user/mass-add/"]', 'Add users in bulk');
       
   332 		// TOTEST : filter by tag -> commentator user should be tagged commentator
       
   333 		test_count	('form#filter_form[action="."] :input', 1);
       
   334 		test_text	('#filter_form a[href="?display=1"]', 'Display suspended users');
       
   335 		test_text	('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible);
       
   336 		// TOTEST : pagination
       
   337 		// TOTEST : Bulk Actions -> Apply does enable
       
   338 		test_text	('select#bulk_actions option:eq(0)[selected][value="-1"]', '- Bulk Actions -', non_visible);
       
   339 		test_text	('select#bulk_actions option:eq(1)[value="disable"]', 'Suspend access', non_visible);
       
   340 		test_text	('select#bulk_actions option:eq(2)[value="enable"]', 'Enable access', non_visible);
       
   341 		test_text	('select#bulk_actions option:eq(3)[value="role_1"]', 'Change role to Manager', non_visible);
       
   342 		test_text	('select#bulk_actions option:eq(4)[value="role_2"]', 'Change role to Editor', non_visible);
       
   343 		test_text	('select#bulk_actions option:eq(5)[value="role_3"]', 'Change role to Moderator', non_visible);
       
   344 		test_text	('select#bulk_actions option:eq(6)[value="role_4"]', 'Change role to Commentator', non_visible);
       
   345 		test_text	('select#bulk_actions option:eq(7)[value="role_5"]', 'Change role to Observer', non_visible);
       
   346 		test_val	('form#user_form input#apply[type=button][disabled]', 'Apply');
       
   347 		test_count	('table.large_table:eq(1) th', 6);
       
   348 		test_val	('table.large_table:eq(1) th:eq(0) input#all_check[type="checkbox"]', 'on');
       
   349 		test_text	('table.large_table:eq(1) th:eq(1) a[href="?order=user__username"]', 'User');
       
   350 		test_text	('table.large_table:eq(1) th:eq(2) a[href="?order=user__email"]', 'Email');
       
   351 		test_text	('table.large_table:eq(1) th:eq(3) a[href="?order=-user__date_joined"]', 'Date joined');
       
   352 		test_text	('table.large_table:eq(1) th:eq(4) a[href="?order=role__name"]', 'Role');
       
   353 		test_text	('table.large_table:eq(1) th:eq(5)', 'Last week activity');
       
   354 		test_text	('table.large_table:eq(1) tr:last a[href="/user/-/edit/"]', 'Anonymous users');
       
   355 		test_text	('table.large_table:eq(1) a.main_object_title[href="/profile/"]', w.USER_ADMIN);
       
   356 		test_text	('table.large_table:eq(1) div.hidden-user-actions a[href="/profile/"]', 'Your profile');
       
   357 		// TOTEST presence of commentator and editor user
       
   358 		test_unlogged_footer ();
       
   359 	});
       
   360 
       
   361 	suite ('check user number', function () {
       
   362 		test_page_loading	('/user/?display=1', 'People\' list\n - '+t['#id_workspace_name']);
       
   363 		test_count	('#user_form :input', 6 + (t.user_nb % 10) * 2);
       
   364 		test_match	('#paginator', new RegExp ('\\s\\d+-\\d+ of '+t.user_nb+'\\s','m'));
       
   365 	});
       
   366 
       
   367 	suite ('add a user page conformity', function () {
       
   368 		test_page_loading	('/user/add/', 'Add a new user\n - '+t['#id_workspace_name']);
       
   369 		test_logged_header	(w.USER_ADMIN);
       
   370 		test_default_tabs	(t.text_nb, t.user_nb);
       
   371 		test_count	('#user ul.sub_list:eq(0) a', 2);
       
   372 		test_text	('#user ul.sub_list:eq(0) a:eq(0)[href="/user/"]', 'Users\' list');
       
   373 		test_text	('#user ul.sub_list:eq(0) a:eq(1)[href="/user/mass-add/"]', 'Add users in bulk');
       
   374 		test_count	('#user form[action="."]:eq(0) :input', 8);
       
   375 		test_form_field ('user', 'id_email',		'text', 0, 'E-mail address', true);
       
   376 		test_form_field ('user', 'id_first_name',	'text', 1, 'First name');
       
   377 		test_form_field ('user', 'id_last_name',	'text', 2, 'Last name');
       
   378 		test_form_field ('user', 'id_tags',			'text', 3, 'Tags');
       
   379 		test_form_field ('user', 'id_role',			'select', 4, 'Workspace level role');
       
   380 		test_form_field ('user', 'id_note',			'textarea', 5, 'Note');
       
   381 		test_count	('select#id_role option', 6);
       
   382 		test_text	('select#id_role option:eq(0)[value][selected]', '---------', non_visible);
       
   383 		test_text	('select#id_role option:eq(1)[value="1"]', 'Manager', non_visible);
       
   384 		test_text	('select#id_role option:eq(2)[value="2"]', 'Editor', non_visible);
       
   385 		test_text	('select#id_role option:eq(3)[value="3"]', 'Moderator', non_visible);
       
   386 		test_text	('select#id_role option:eq(4)[value="4"]', 'Commentator', non_visible);
       
   387 		test_text	('select#id_role option:eq(5)[value="5"]', 'Observer', non_visible);
       
   388 		test_val	('#user :input:eq(6)[type=submit]', 'Add user');
       
   389 		test_val	('#user :input:eq(7)#cancel_button[type=button]', 'Cancel');
       
   390 		test_unlogged_footer ();
       
   391 
       
   392 		test ('submit empty fields', dsl(function () {
       
   393 			elt ('#user input[type="submit"]').click ();
       
   394 			browser.waitForPageLoad ();
       
   395 		}));
       
   396 		test_count	('div.help_text span.error-text', 1);
       
   397 		test_form_field ('user div.error', 'id_email', 'text', 0, 'E-mail address', true);
       
   398 		test_match	('#user div.help_text:eq(0) span.error-text:eq(0)', /This field is required/m);
       
   399 		// X TOTEST add user (pending)
       
   400 	});
       
   401 
       
   402 	suite ('add users in bulk page conformity', function () {
       
   403 		test_page_loading	('/user/mass-add/', 'Add users in bulk\n - '+t['#id_workspace_name']);
       
   404 		test_logged_header	(w.USER_ADMIN);
       
   405 		test_default_tabs	(t.text_nb, t.user_nb);
       
   406 		test_count	('#user ul.sub_list:eq(0) a', 2);
       
   407 		test_text	('#user ul.sub_list:eq(0) a:eq(0)[href="/user/"]', 'Users\' list');
       
   408 		test_text	('#user ul.sub_list:eq(0) a:eq(1)[href="/user/add/"]', 'Add a new user');
       
   409 		test_count	('#user form[action="."]:eq(0) :input', 6);
       
   410 		test_form_field ('user', 'id_email',		'textarea', 0, 'Emails', true);
       
   411 		test_form_field ('user', 'id_tags',			'text',		1, 'Tags');
       
   412 		test_form_field ('user', 'id_role',			'select',	2, 'Workspace level role');
       
   413 		test_form_field ('user', 'id_note',			'textarea', 3, 'Note');
       
   414 		test_count	('select#id_role option', 6);
       
   415 		test_text	('select#id_role option:eq(0)[value][selected]', '---------', non_visible);
       
   416 		test_text	('select#id_role option:eq(1)[value="1"]', 'Manager', non_visible);
       
   417 		test_text	('select#id_role option:eq(2)[value="2"]', 'Editor', non_visible);
       
   418 		test_text	('select#id_role option:eq(3)[value="3"]', 'Moderator', non_visible);
       
   419 		test_text	('select#id_role option:eq(4)[value="4"]', 'Commentator', non_visible);
       
   420 		test_text	('select#id_role option:eq(5)[value="5"]', 'Observer', non_visible);
       
   421 		test_val	('#user :input:eq(4)[type=submit]', 'Add users');
       
   422 		test_val	('#user :input:eq(5)#cancel_button[type=button]', 'Cancel');
       
   423 		// X TOTEST add users (pending) -> can't be deleted
       
   424 		test_unlogged_footer ();
       
   425 
       
   426 		test ('submit empty fields', dsl(function () {
       
   427 			elt ('#user input[type="submit"]').click ();
       
   428 			browser.waitForPageLoad ();
       
   429 		}));
       
   430 		test_count	('div.help_text span.error-text', 1);
       
   431 		test_form_field ('user div.error', 'id_email', 'textarea', 0, 'Emails', true);
       
   432 		test_match	('#user div.help_text:eq(0) span.error-text:eq(0)', /This field is required/m);
       
   433 	});
       
   434 
       
   435 	suite ('settings page conformity', function () {
       
   436 		test_page_loading	('/settings/', 'Settings - '+t['#id_workspace_name']);
       
   437 		test_logged_header	(w.USER_ADMIN);
       
   438 		test_default_tabs	(t.text_nb, t.user_nb);
       
   439 		test_count	('#settings ul.sub_list:eq(0) a', 1);
       
   440 		test_text	('#settings ul.sub_list:eq(0) a:eq(0)[href="/settings/design/"]', 'Appearance');
       
   441 		test_count	('#settings form[action="."]:eq(0) :input', 12);
       
   442 		test_form_field ('settings', 'id_workspace_name', 'text', 0, 'Workspace name');
       
   443 		test_form_field ('settings', 'id_workspace_tagline', 'text', 1, 'Workspace tagline');
       
   444 		test_form_field ('settings', 'id_workspace_registration', 'checkbox', 2, 'Workspace registration');
       
   445 		test_form_field ('settings', 'id_workspace_registration_moderation', 'checkbox', 3, 'Workspace registration moderation');
       
   446 		test_form_field ('settings', 'id_workspace_role_model', 'select', 4, 'Role model');
       
   447 		test_text	('select#id_workspace_role_model option:eq(0)[selected][value="generic"]', 'Generic', non_visible);
       
   448 		test_text	('select#id_workspace_role_model option:eq(1)[value="teacher"]', 'Class (education)', non_visible);
       
   449 		test_form_field ('settings', 'id_workspace_category_1', 'text', 5, 'Label for the first category of comments');
       
   450 		test_form_field ('settings', 'id_workspace_category_2', 'text', 6, 'Label for the second category of comments');
       
   451 		test_form_field ('settings', 'id_workspace_category_3', 'text', 7, 'Label for the third category of comments');
       
   452 		test_form_field ('settings', 'id_workspace_category_4', 'text', 8, 'Label for the fourth category of comments');
       
   453 		test_form_field ('settings', 'id_workspace_category_5', 'text', 9, 'Label for the fifth category of comments');
       
   454 		test_val	('#settings :input:eq(10)[type=submit]', 'Save');
       
   455 		test_val	('#settings :input:eq(11)#cancel_button[type=button]', 'Cancel');
       
   456 		// TOTEST Workspace registration feature (with newly accessible page)
       
   457 		test_unlogged_footer ();
       
   458 	});
       
   459 
       
   460 	suite ('settings design page conformity', function () {
       
   461 		test_page_loading	('/settings/design/', 'Settings - '+t['#id_workspace_name']);
       
   462 		test_logged_header	(w.USER_ADMIN);
       
   463 		test_default_tabs	(t.text_nb, t.user_nb);
       
   464 		test_count	('#settings ul.sub_list:eq(0) a', 1);
       
   465 		test_text	('#settings ul.sub_list:eq(0) a:eq(0)[href="/settings/"]', 'General');
       
   466 		test_count	('#settings form[action="."]:eq(0) :input', 7);
       
   467 		test_form_field ('settings', 'id_workspace_logo_file', 'file', 0, 'Workspace logo');
       
   468 		test_form_field ('settings', 'id_custom_css', 'textarea', 1, 'Custom CSS rules');
       
   469 		test_form_field ('settings', 'id_custom_font', 'text', 2, 'Custom font');
       
   470 		test_form_field ('settings', 'id_custom_titles_font', 'text', 3, 'Custom font for titles');
       
   471 		test_val	('#settings :input:eq(4)[type=submit]', 'Save');
       
   472 		test_val	('#settings :input:eq(5)#cancel_button[type=button]', 'Cancel');
       
   473 		test_val	('#settings :input:eq(6)#delete_logo_button[type=submit]', 'Delete logo');
       
   474 		test_unlogged_footer ();
       
   475 	});
       
   476 
       
   477 	suite ('followup page conformity', function () {
       
   478 		test_page_loading	('/followup/', 'Followup\n - '+t['#id_workspace_name']);
       
   479 		test_logged_header	(w.USER_ADMIN);
       
   480 		test_default_tabs	(t.text_nb, t.user_nb);
       
   481 		test_text	('#followup a:eq(0)[href="/help/#public_private_feed"]', '?');
       
   482 		test_match	('#followup a:eq(1)[href$="/feed/"]', new RegExp (w.WORKSPACE_URL+'feed/', 'm'));
       
   483 		test_text	('#followup a:eq(2)[href="/help/#public_private_feed"]', '?');
       
   484 		test_count	('form#followup_form[action="."] :input', 3);
       
   485 		test_val	('form#followup_form input[type=submit]', '(Activate private feed|Reset private feed url)');
       
   486 		test_val	('form#followup_form input#workspace_notify_check[type=checkbox]', 'on');
       
   487 		test_val	('form#followup_form input#own_notify_check[type=checkbox]', 'on');
       
   488 	
       
   489 		// X TOTEST qu'une fois cliqué, le bouton a le nvo label, et qu'une adresse est disponible
       
   490 		// X TOTEST que si on reclique l'adresse est changée
       
   491 
       
   492 		test_unlogged_footer ();
       
   493 	});
       
   494 
       
   495 	// vérifier les valeurs de settings sauvées
       
   496 	// Tester les champs obligatoires
       
   497 	// Tester les créations de textes
       
   498 	// Tester les liens masqués des textes listés si bien créés
       
   499 	// Tester suppression de text
       
   500 	// Tester bulk actions sur les textes
       
   501 
       
   502 	// tester l'affichage d'un texte
       
   503 	// tester que : #textcontainer.custom h1 font: Test_Sopinspace_custom_titles_font
       
   504 	// tester que si Text preferences -> custom -> #textcontainer.custom font: Test_Sopinspace_custom_font
       
   505 	// #textcontainer #add_comment_btn span -> #textcontainer font-family: Test_Sopinspace
       
   506 
       
   507 });
       
   508 
       
   509 function test_default_tabs (text_nb, user_nb) {
       
   510 	test_count	('#main-tabs a', 5);
       
   511 	test_text	('#main-tabs li:nth-of-type(1) a[href="/"]',			'Dashboard');
       
   512 	test_match	('#main-tabs li:nth-of-type(2) a[href="/text/"]',		/^Texts \(\d+\) $/);
       
   513 	test_match	('#main-tabs li:nth-of-type(3) a[href="/user/"]',		/^People  \(\d+\)$/);
       
   514 	test_text	('#main-tabs li:nth-of-type(4) a[href="/settings/"]',	'Settings');
       
   515 	test_text	('#main-tabs li:nth-of-type(5) a[href="/followup/"]',	'Followup');
       
   516 	test_match	('#main-tabs a[href="/text/"]', new RegExp ('^Texts\\s*\\('+text_nb+'\\)\\s*$'));
       
   517 	test_match	('#main-tabs a[href="/user/"]', new RegExp ('^People\\s*\\('+user_nb+'\\)\\s*$'));
       
   518 }
       
   519 
       
   520 function test_logged_header (username, is_tagline) {
       
   521 	is_tagline = typeof is_tagline == 'undefined' ? true : is_tagline;
       
   522 
       
   523 	test_text	('#header_controls b', username)
       
   524 	test_count	('#header_controls a', 6);
       
   525 	test_text	('#header_controls a:nth-of-type(1)[href="/"]',					'Home');
       
   526 	test_text	('#header_controls a:nth-of-type(2)[href="/create/content/"]',	'Create a text');
       
   527 	test_text	('#header_controls a:nth-of-type(3)[href="/create/upload/"]',	'Upload a text');
       
   528 	test_text	('#header_controls a:nth-of-type(4)[href="/create/import/"]',	'Import a co-mented text');
       
   529 	test_text	('#header_controls a:nth-of-type(5)[href="/profile/"]',			'Profile');
       
   530 	test_text	('#header_controls a:nth-of-type(6)[href="/logout/"]',			'Logout');
       
   531 	test_text	('#content h1.main_title a[href="/"]',							t['#id_workspace_name']);
       
   532 
       
   533 	if (is_tagline) {
       
   534 		test_match	('#content h1.main_title  + div', new RegExp (t['#id_workspace_tagline'], 'm'));
       
   535 	}
       
   536 }
       
   537 
       
   538 function test_unlogged_header () {
       
   539 	test_count	('#header_controls a', 2);
       
   540 	test_text	('#header_controls a[href="/"]',		'Home');
       
   541 	test_text	('#header_controls a[href="/login/"]',	'Login');
       
   542 }
       
   543 
       
   544 function test_unlogged_footer (url) {
       
   545 	test_count	('#footer a', 10);
       
   546 	test_text	('#footer a:nth-of-type(1)[href="/contact/"]',				'Contact');
       
   547 	test_match	('#footer #comentlink[href="http://www.co-ment.com"]',		/Powered by/m);
       
   548 	test_text	('#footer a:nth-of-type(3)[href="/help/"]',					'Help');
       
   549 	test_text	('#footer a:nth-of-type(4)[href="/i18n/setlang/fr/"]',		'Français');
       
   550 	test_text	('#footer a:nth-of-type(5)[href="/i18n/setlang/es/"]',		'Español');
       
   551 	test_text	('#footer a:nth-of-type(6)[href="/i18n/setlang/it/"]',		'Italiano');
       
   552 	test_text	('#footer a:nth-of-type(7)[href="/i18n/setlang/de/"]',		'Deutsch');
       
   553 	test_text	('#footer a:nth-of-type(8)[href="/i18n/setlang/pt_BR/"]',	'Português Brasileiro');
       
   554 	test_text	('#footer a:nth-of-type(9)[href="/i18n/setlang/nb/"]',		'Norsk');
       
   555 	test_text	('#footer a:nth-of-type(10)[href="/i18n/setlang/bg/"]',		'Български');
       
   556 }
       
   557 
       
   558 function test_fill_field (field_id, stored) { 
       
   559 	test ('set '+field_id, dsl(function () {
       
   560 		input (field_id).enter (stored[field_id]);
       
   561 	}));
       
   562 }
       
   563 
       
   564 function test_fill_settings (s) {
       
   565 	test_fill_field ('#id_workspace_name', s);
       
   566 	test_fill_field ('#id_workspace_tagline', s);
       
   567 	test_fill_field ('#id_workspace_registration', s);
       
   568 	test_fill_field ('#id_workspace_registration_moderation', s);
       
   569 	test_fill_field ('#id_workspace_role_model', s);
       
   570 	test_fill_field ('#id_workspace_category_1', s);
       
   571 	test_fill_field ('#id_workspace_category_2', s);
       
   572 	test_fill_field ('#id_workspace_category_3', s);
       
   573 	test_fill_field ('#id_workspace_category_4', s);
       
   574 	test_fill_field ('#id_workspace_category_5', s);
       
   575 }
       
   576 
       
   577 function test_fill_design (s) {
       
   578 	test_fill_field ('#id_custom_css', s);
       
   579 	test_fill_field ('#id_custom_font', s);
       
   580 	test_fill_field ('#id_custom_titles_font', s);
       
   581 }
       
   582 
       
   583 
       
   584 function test_i18n () {
       
   585 	test ('can change lang to french', dsl(function () {
       
   586 		element ('#footer a[href="/i18n/setlang/fr/"]').click ();
       
   587 //		browser.waitForPageLoad ();
       
   588 //		browser.navigateTo ('/');
       
   589 //		browser.reload ();
       
   590 		expect (elt ('#footer a[href="/help/"]').text ()).toBe ('Aide');
       
   591 		element ('#footer a[href="/i18n/setlang/en/"]').click ();
       
   592 //		browser.waitForPageLoad ();
       
   593 //		browser.navigateTo ('/');
       
   594 	}));
       
   595 }
       
   596 
       
   597 function test_page_loading (url, title) {
       
   598 	test (url+' loads', dsl(function () {
       
   599 		// here we are in Karma page
       
   600 		browser.navigateTo (url);
       
   601 		expect (element ('title').text ()).toMatch (new RegExp (title,'m'));
       
   602 		// The same test agin vaniller javascript
       
   603 		element ('title').text (function (page_title) {
       
   604 			// here we got a value from the test iframe
       
   605 			// to display the tested value : console.log (page_title);
       
   606 			if (!(new RegExp (title, 'm').test (page_title))) throw 'got page '+page_title+' instead';
       
   607 		});
       
   608 	}));
       
   609 }
       
   610 
       
   611 /** Test if the selected DOM element is defined or has a given value : .val()
       
   612  *	s : CSS selector
       
   613  *	e : expected value, if omited, test existence
       
   614  */
       
   615 function test_val (s, e) {
       
   616 	e = typeof e == 'undefined' ? '' : e; // .val() returns defined ? '' : undefined; // if no value
       
   617 	test (s+' is '+e, dsl(function () {
       
   618 		expect (elt (s).val ()).toMatch (new RegExp (e, 'm'));
       
   619 	}));
       
   620 }
       
   621 
       
   622 /** Test if the selected DOM element has the given text : .text()
       
   623  *	s : CSS selector
       
   624  *	e : expected value
       
   625  *	v : should we test a visible value ?
       
   626  */
       
   627 function test_text (s, e, v) {
       
   628 	v = typeof v == 'undefined' ? true : v;
       
   629 	test (s+' has text '+e, dsl(function () {
       
   630 		expect (elt (s, v).text ()).toBe (e);
       
   631 	}));
       
   632 }
       
   633 
       
   634 /** Test if the selected DOM element .text() value match the given regexp
       
   635  *	s : CSS selector
       
   636  *	r : regexp to match
       
   637  */
       
   638 function test_match (s, r) {
       
   639 	test (s+' text match '+r, dsl(function () {
       
   640 		expect (elt (s).text ()).toMatch (r);
       
   641 	}));
       
   642 }
       
   643 
       
   644 /** Count selector occurences
       
   645  *	s : CSS selector
       
   646  *	e : expected count
       
   647  */
       
   648 function test_count (s, e) {
       
   649 	test (s+' count is '+e, dsl(function () {
       
   650 		expect (elt (s).count ()).toBe (e);
       
   651 	}));
       
   652 }
       
   653 
       
   654 /** Test Django form field presence
       
   655  */
       
   656 function test_form_field (form_id, field_id, type, position, label, mandatory) {
       
   657 	test ('has a '+label+' form field', dsl(function () {
       
   658 		var s = '';
       
   659 
       
   660 		switch (type) {
       
   661 			case 'textarea':s = 'textarea#'+field_id; break;
       
   662 			case 'select':	s = 'select#'+field_id; break;
       
   663 			default:		s = 'input#'+field_id+'[type="'+type+'"]';
       
   664 		}
       
   665 
       
   666 		expect (elt (s).val ()).toBeDefined ();
       
   667 		expect (elt ('#'+form_id+' :input:eq('+position+')#'+field_id).val ()).toBeDefined ();
       
   668 		expect (elt ('label[for='+field_id+']').text ()).toBe (label);
       
   669 
       
   670 		if (mandatory)
       
   671 			expect (elt ('label[for='+field_id+'] + span.required_star').val ()).toBeDefined ();
       
   672 	}));
       
   673 }
       
   674 
       
   675 /** Ensure the given element is visible
       
   676  *	s : CSS selector of the DOM element to check
       
   677  *	v : should the element being visible
       
   678  */
       
   679 function elt (s, v) {
       
   680 	return element (s + (v ? ':visible' : ''));
       
   681 }