test-suite/tests/002_comt-logged-admin.js
changeset 637 71d87ca43d6a
parent 636 a8ab808d33c3
equal deleted inserted replaced
636:a8ab808d33c3 637:71d87ca43d6a
     3 // set tabstop=4		  " number of spaces in a tab
     3 // set tabstop=4		  " number of spaces in a tab
     4 // set softtabstop=4	  " as above
     4 // set softtabstop=4	  " as above
     5 // set shiftwidth=4		  " as above
     5 // set shiftwidth=4		  " as above
     6 
     6 
     7 var w = __karma__.config.w,
     7 var w = __karma__.config.w,
     8 	t = {'text_nb': 0, 'user_nb': 4},
     8 	t = {'text_nb': 0, 'user_nb': 4};
     9 	long_text = '';
       
    10 
       
    11 for (var i = 20; i--;)
       
    12 	long_text += 'Contenu du troisième texte.<br/>Sur <b>plusieurs</b> lignes<br/>';
       
    13 
     9 
    14 const hidden = false,
    10 const hidden = false,
    15 	no_tagline = false,
    11 	no_tagline = false,
    16 	wait_page_load = true,
    12 	wait_page_load = true,
    17 	c = {
    13 	c = {
    25 	'#id_workspace_category_3':	'ws_cat_3',
    21 	'#id_workspace_category_3':	'ws_cat_3',
    26 	'#id_workspace_category_4':	'ws_cat_4',
    22 	'#id_workspace_category_4':	'ws_cat_4',
    27 	'#id_workspace_category_5':	'ws_cat_5',
    23 	'#id_workspace_category_5':	'ws_cat_5',
    28 	'#id_custom_css': "h2 {  font-family: Test_Sopinspace !important; }",
    24 	'#id_custom_css': "h2 {  font-family: Test_Sopinspace !important; }",
    29 	'#id_custom_font': 'Test_Sopinspace_custom_font',
    25 	'#id_custom_font': 'Test_Sopinspace_custom_font',
    30 	'#id_custom_titles_font': 'Test_Sopinspace_custom_titles_font',
    26 	'#id_custom_titles_font': 'Test_Sopinspace_custom_titles_font'
    31 	'texts':	[
       
    32 		{
       
    33 			'#id_title':	'Text One Sopinspace-Test éléguant',
       
    34 			'#id_format':	'markdown',
       
    35 			'#id_content':	'Contenu du premier texte.\nSur plusieurs lignes\nPour tester un cas réaliste',
       
    36 			'#id_tags':		'test_text, Text Premier'
       
    37 		},
       
    38 		{
       
    39 			'#id_title':	'Text Two Sopinspace-Test éléguant',
       
    40 			'#id_format':	'rst',
       
    41 			'#id_content':	'Contenu du deuxième texte.\nSur plusieurs lignes aussi\nPour tester un cas réaliste',
       
    42 			'#id_tags':		'test_text, Text Second'
       
    43 		},
       
    44 		{
       
    45 			'#id_title':	'Text Three Sopinspace-Test éléguant',
       
    46 			'#id_format':	'html',
       
    47 			'#id_content':	long_text,
       
    48 			'#id_tags':		'test_text, Text Troisième'
       
    49 		}
       
    50 	]
       
    51 };
    27 };
    52 
    28 
    53 suite ('comt logged admin', function () {
    29 suite ('comt logged admin', function () {
    54 
    30 
    55 	this.timeout(200000);
    31 	this.timeout(20000);
    56 
    32 
    57 	suite ('logs as an admin', function () {
    33 	suite ('logs as an admin', function () {
    58 		test ('logs an admin in', dsl(function () {
    34 		test ('with '+w.USER_ADMIN+' - '+w.PASS_ADMIN, dsl(function () {
    59 			browser.navigateTo ('/');
    35 			browser.navigateTo ('/');
    60 			input ('#id_username').enter (w.USER_ADMIN);
    36 			input ('#id_username').enter (w.USER_ADMIN);
    61 			input ('#id_password').enter (w.PASS_ADMIN);
    37 			input ('#id_password').enter (w.PASS_ADMIN);
    62 			elt ('#login input[type=submit]').click ();
    38 			elt ('#login input[type=submit]').click ();
    63 			browser.waitForPageLoad (); // Must be done here in this test() block
    39 			browser.waitForPageLoad (); // Must be done here in this test() block
   102 		test_text	('table.dash_table:eq(3) a:eq(1)[href="?span=day"]', '24 hours');
    78 		test_text	('table.dash_table:eq(3) a:eq(1)[href="?span=day"]', '24 hours');
   103 		test_text	('table.dash_table th:eq(4) span.em', 'Activities');
    79 		test_text	('table.dash_table th:eq(4) span.em', 'Activities');
   104 		test_unlogged_footer ();
    80 		test_unlogged_footer ();
   105 	});
    81 	});
   106 
    82 
   107 	suite ('empty texts list page conformity', function () {
       
   108 		test_page_loading	('/text/', 'Texts\n - '+c['#id_workspace_name']);
       
   109 		test_logged_header	(w.USER_ADMIN);
       
   110 		test_default_tabs	(t.text_nb, t.user_nb);
       
   111 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   112 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text');
       
   113 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text');
       
   114 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text');
       
   115 		test_match	('#text', /No texts yet/m);
       
   116 		test_count	('#texts_form :input', 0);
       
   117 	});
       
   118 
       
   119 	suite ('create a text page conformity', function () {
    83 	suite ('create a text page conformity', function () {
   120 		test_page_loading	('/create/content/', 'Create a text - '+c['#id_workspace_name']);
    84 		test_page_loading	('/create/content/', 'Create a text - '+c['#id_workspace_name']);
   121 		test_logged_header	(w.USER_ADMIN);
    85 		test_logged_header	(w.USER_ADMIN);
   122 		test_default_tabs	(t.text_nb, t.user_nb);
    86 		test_default_tabs	(t.text_nb, t.user_nb);
   123 		test_count	('#text ul.sub_list:eq(0) a', 3);
    87 		test_count	('#text ul.sub_list:eq(0) a', 3);
   184 		test_unlogged_footer ();
   148 		test_unlogged_footer ();
   185 		test_click	('#text input[type="submit"]', wait_page_load);
   149 		test_click	('#text input[type="submit"]', wait_page_load);
   186 		test_count	('div.help_text span.error-text', 1);
   150 		test_count	('div.help_text span.error-text', 1);
   187 		test_field	('text div.error', 'id_file',		'file', 0, 'Upload XML file', true);
   151 		test_field	('text div.error', 'id_file',		'file', 0, 'Upload XML file', true);
   188 		test_match	('#text div.help_text:eq(0) span.error-text:eq(0)', /You should specify a file to upload/m);
   152 		test_match	('#text div.help_text:eq(0) span.error-text:eq(0)', /You should specify a file to upload/m);
   189 	});
       
   190 
       
   191 	suite ('create texts', function () {
       
   192 		for (var j=4; j--;)
       
   193 			for (var i=3; i--;)
       
   194 				 create_text (i);
       
   195 	});
       
   196 
       
   197 	// check that public texts still worwhile unlogged
       
   198 	// check that non public texts are unavailable
       
   199 	// Are the public texts displayed in the login page ?
       
   200 
       
   201 	// vérifier les valeurs de settings sauvées
       
   202 	// Tester les liens masqués des textes listés si bien créés
       
   203 	// Tester suppression de text
       
   204 	// Tester bulk actions sur les textes
       
   205 
       
   206 	// tester l'affichage d'un texte
       
   207 	// tester que : #textcontainer.custom h1 font: Test_Sopinspace_custom_titles_font
       
   208 	// tester que si Text preferences -> custom -> #textcontainer.custom font: Test_Sopinspace_custom_font
       
   209 	// #textcontainer #add_comment_btn span -> #textcontainer font-family: Test_Sopinspace
       
   210 
       
   211 	suite ('texts list page conformity', function () {
       
   212 		test_page_loading	('/text/', 'Texts\n - '+c['#id_workspace_name']);
       
   213 		test_logged_header	(w.USER_ADMIN);
       
   214 		test_default_tabs	(t.text_nb, t.user_nb);
       
   215 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   216 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text');
       
   217 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text');
       
   218 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text');
       
   219 		test_count	('form#filter_form[action="."] :input', 1);
       
   220 		test_text	('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', hidden);
       
   221 		test_page_loading ('/text/?tag_selected=Text+Troisième', 'Texts\n - '+c['#id_workspace_name']);
       
   222 		test_count	('#texts_form :input', 4 + 3);
       
   223 		test_match	('#paginator', /\s1-4 of 4\s/m);
       
   224 
       
   225 		for (var i=4; i--;) {
       
   226 			test_text	('a.main_object_title:eq('+i+')', c.texts[2]['#id_title']);
       
   227 			test_match	('.tag_list:eq('+i+')', /tags: test_text Text Troisième /);
       
   228 			test_text	('.tag_list:eq('+i+') a:eq(0)[href="?tag_selected=test_text"]', 'test_text');
       
   229 			test_text	('.tag_list:eq('+i+') a:eq(1)[href="?tag_selected=Text+Troisi%C3%A8me"]','Text Troisième');
       
   230 			test_text	('#text .hidden-text-actions:eq('+i+') a:eq(0)[href^="/text/"][href$="/view/"]', 'View');
       
   231 			test_text	('#text .hidden-text-actions:eq('+i+') a:eq(1)[href^="/text/"][href$="/edit/"]', 'Edit');
       
   232 			test_text	('#text .hidden-text-actions:eq('+i+') a:eq(2)[href$="#"][id*=delete]', 'Delete');
       
   233 			test_text	('#text .hidden-text-actions:eq('+i+') a:eq(3)[href^="/text/"][href$="/share/"]', 'Users');
       
   234 			test_text	('#text .hidden-text-actions:eq('+i+') a:eq(4)[href^="/text/"][href$="/settings/"]', 'Settings');
       
   235 			test_text	('#text a[title="Edit user"][href^="/user/"][href$="/edit/"]:eq('+i+')', 'admin');
       
   236 			test_text	('#text table[summary="text list"] tr:eq('+(i+1)+') td:eq(4)', '0');
       
   237 		}
       
   238 
       
   239 		test_page_loading ('/text/', 'Texts\n - '+c['#id_workspace_name']);
       
   240 		test_count	('#texts_form :input', (t.text_nb < 10 ? t.text_nb : 10) + 3);
       
   241 		test_match	('#paginator', new RegExp ('\\s1-10 of '+t.text_nb+'\\s','m'));
       
   242 		test_text	('#paginator a:eq(0)[href="?page=2"]', '»');
       
   243 		test_text	('#paginator a:eq(1)[href="?paginate=0"]', 'all');
       
   244 		test_click	('#paginator a:eq(0)[href="?page=2"]');
       
   245 		test_match	('#paginator', new RegExp ('\\s11-12 of '+t.text_nb+'\\s','m'));
       
   246 		test_count	('#texts_form :input', t.text_nb % 10 + 3);
       
   247 		test_click	('#paginator a:eq(0)[href="?page=1"]');
       
   248 		test_match	('#paginator', new RegExp ('\\s1-10 of '+t.text_nb+'\\s','m'));
       
   249 		test_count	('#texts_form :input', (t.text_nb < 10 ? t.text_nb : 10) + 3);
       
   250 		test_click	('#paginator a:eq(1)[href="?paginate=0&page=1"]');
       
   251 		test_match	('#paginator', /\s\(paginate\)\s/m);
       
   252 		test_count	('#texts_form :input', t.text_nb + 3);
       
   253 		test_click	('#paginator a:eq(0)[href="?paginate=&page=1"]');
       
   254 		test_count	('#texts_form :input', (t.text_nb < 10 ? t.text_nb : 10) + 3);
       
   255 		test_match	('#paginator', new RegExp ('\\s1-10 of '+t.text_nb+'\\s','m'));
       
   256 		test_page_loading	('/text/', 'Texts\n - '+c['#id_workspace_name']);
       
   257 		test_text	('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', hidden);
       
   258 		test_text	('select#bulk_actions option:eq(1)[value="delete"]', 'Delete', hidden);
       
   259 		test_val	('form#texts_form input#apply[type=button][disabled]', 'Apply');
       
   260 		test_count	('table.large_table:eq(1) th', 6);
       
   261 		test_val	('table.large_table:eq(1) th:eq(0) input#all_check[type="checkbox"]', 'on');
       
   262 		test_text	('table.large_table:eq(1) th:eq(1) a[href="?order=title"]', 'Text');
       
   263 		test_text	('table.large_table:eq(1) th:eq(2)', 'Author');
       
   264 		test_text	('table.large_table:eq(1) th:eq(3) a[href="?order=-modified"]', 'Modified');
       
   265 		test_text	('table.large_table:eq(1) th:eq(4)', '# comments');
       
   266 		test_text	('table.large_table:eq(1) th:eq(5)', 'Last week activity');
       
   267 		test_page_loading ('/text/?page=2', 'Texts\n - '+c['#id_workspace_name']);
       
   268 		test		('choose bulk action Delete', dsl(function () { input ('#bulk_actions').option ('delete'); }));
       
   269 		test_click	('#all_check');
       
   270 		test_count	('form#texts_form input:checked', t.text_nb % 10 + 1);
       
   271 		test_val	('form#texts_form input#apply[type=button]:not([disabled])', 'Apply');
       
   272 		// test_click	('#texts_form #apply'); // can't click on the confirm dialog
       
   273 		test_submit	('#texts_form');
       
   274 		test_page_loading ('/text/', 'Texts\n - '+c['#id_workspace_name']);
       
   275 		t.text_nb -= 2;
       
   276 		test_count	('form#texts_form :input', t.text_nb + 3);
       
   277 		test_match	('#paginator', new RegExp ('\\s1-10 of '+t.text_nb+'\\s','m'));
       
   278 		// TOTEST : unitary delete 
       
   279 
       
   280 		test_unlogged_footer ();
       
   281 	});
   153 	});
   282 
   154 
   283 	suite ('edit profile page conformity', function () {
   155 	suite ('edit profile page conformity', function () {
   284 		test_page_loading	('/profile/', 'Your profile \\('+w.USER_ADMIN+'\\)\n - '+c['#id_workspace_name']);
   156 		test_page_loading	('/profile/', 'Your profile \\('+w.USER_ADMIN+'\\)\n - '+c['#id_workspace_name']);
   285 		test_logged_header	(w.USER_ADMIN, no_tagline);
   157 		test_logged_header	(w.USER_ADMIN, no_tagline);
   517 function test_fill_design (s) {
   389 function test_fill_design (s) {
   518 	test_fill_field ('#id_custom_css', s);
   390 	test_fill_field ('#id_custom_css', s);
   519 	test_fill_field ('#id_custom_font', s);
   391 	test_fill_field ('#id_custom_font', s);
   520 	test_fill_field ('#id_custom_titles_font', s);
   392 	test_fill_field ('#id_custom_titles_font', s);
   521 }
   393 }
   522 
       
   523 function create_text (i) {
       
   524 	test_page_loading	('/create/content/', 'Create a text - '+c['#id_workspace_name']);
       
   525 	test ('test creation', dsl(function () {
       
   526 		dropdownlist ('#id_format').option (c['texts'][i]['#id_format']);
       
   527 	}));
       
   528 
       
   529 	test_fill_field ('#id_title', c['texts'][i]);
       
   530 	test ('fill content', dsl(function (){
       
   531 		elt ('#id_content').val (c['texts'][i]['#id_content']);
       
   532 	}));
       
   533 
       
   534 	test_fill_field ('#id_tags', c['texts'][i]);
       
   535 	test_click	 ('#save_button', wait_page_load);
       
   536 	t.text_nb++;
       
   537 }