test-suite/tests/001_comt_test_utils.js
changeset 638 61dc5370b351
parent 637 71d87ca43d6a
child 641 8f7dafe42d15
equal deleted inserted replaced
637:71d87ca43d6a 638:61dc5370b351
       
     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  * Constants and variables
       
     9  */
       
    10 
       
    11 var test_comt = { 'text_nb': 0,	'user_nb': 4 };
       
    12 
       
    13 const C = { 'HIDDEN': false,
       
    14 	'NO_TAGLINE': false,
       
    15 	'WAIT_PAGE_LOAD': true,
       
    16 	'W': __karma__.config.W,
       
    17 	'#id_workspace_name':	'Test workspace name',
       
    18 	'#id_workspace_tagline':	'Test workspace tagline',
       
    19 	'#id_workspace_registration':			'on',	// registration
       
    20 	'#id_workspace_registration_moderation':'on',	// registration moderation
       
    21 	'#id_workspace_role_model': 'generic',
       
    22 	'#id_workspace_category_1': 'ws_cat_1',
       
    23 	'#id_workspace_category_2': 'ws_cat_2',
       
    24 	'#id_workspace_category_3': 'ws_cat_3',
       
    25 	'#id_workspace_category_4': 'ws_cat_4',
       
    26 	'#id_workspace_category_5': 'ws_cat_5',
       
    27 	'#id_custom_css': "h2 {  font-family: Test_Sopinspace !important; }",
       
    28 	'#id_custom_font': 'Test_Sopinspace_custom_font',
       
    29 	'#id_custom_titles_font': 'Test_Sopinspace_custom_titles_font'
       
    30 };
       
    31 
       
    32 
       
    33 /**
       
    34  * COMT test API
       
    35  */
       
    36 
       
    37 function test_comt_login (user, pass) {
       
    38 	test ('with '+user+' - '+pass, dsl(function () {
       
    39 		browser.navigateTo ('/');
       
    40 		input ('#id_username').enter (user);
       
    41 		input ('#id_password').enter (pass);
       
    42 		elt ('#login input[type=submit]').click ();
       
    43 		browser.waitForPageLoad (); // Must be done here in this test() block
       
    44 		browser.navigateTo ('/');
       
    45 		expect (element ('title').text ()).toMatch (/Dashboard/m);
       
    46 	}));
       
    47 }
       
    48 
       
    49 function test_comt_logout () {
       
    50 	test_page_loading ('/logout/', 'Home - '+C['#id_workspace_name']);
       
    51 };
       
    52 
       
    53 function test_comt_create_text (t) {
       
    54 	test_page_loading	('/create/content/', 'Create a text - '+C['#id_workspace_name']);
       
    55 	test ('test creation', dsl(function () {
       
    56 		dropdownlist ('#id_format').option (t['#id_format']);
       
    57 	}));
       
    58 
       
    59 	test_fill_field ('#id_title', t);
       
    60 	test ('fill content', dsl(function (){
       
    61 		elt ('#id_content').val (t['#id_content']);
       
    62 	}));
       
    63 
       
    64 	test_fill_field ('#id_tags', t);
       
    65 	test_click	 ('#save_button', C.WAIT_PAGE_LOAD);
       
    66 	test_comt.text_nb++;
       
    67 }
       
    68 
       
    69 
       
    70 /**
       
    71  * Other factorized tests
       
    72  */
       
    73 
       
    74 
       
    75 
       
    76 function test_comt_default_tabs (txt_nb, usr_nb) {
       
    77 	test_count	('#main-tabs a', 5);
       
    78 	test_text	('#main-tabs li:nth-of-type(1) a[href="/"]',			'Dashboard');
       
    79 	test_match	('#main-tabs li:nth-of-type(2) a[href="/text/"]',		/^Texts \(\d+\) $/);
       
    80 	test_match	('#main-tabs li:nth-of-type(3) a[href="/user/"]',		/^People  \(\d+\)$/);
       
    81 	test_text	('#main-tabs li:nth-of-type(4) a[href="/settings/"]',	'Settings');
       
    82 	test_text	('#main-tabs li:nth-of-type(5) a[href="/followup/"]',	'Followup');
       
    83 	test_match	('#main-tabs a[href="/text/"]', new RegExp ('^Texts\\s*\\('+txt_nb+'\\)\\s*$'));
       
    84 	test_match	('#main-tabs a[href="/user/"]', new RegExp ('^People\\s*\\('+usr_nb+'\\)\\s*$'));
       
    85 }
       
    86 
       
    87 function test_comt_logged_header (username, is_tagline) {
       
    88 	is_tagline = typeof is_tagline == 'undefined' ? true : is_tagline;
       
    89 
       
    90 	test_text	('#header_controls b', username)
       
    91 	test_count	('#header_controls a', 6);
       
    92 	test_text	('#header_controls a:nth-of-type(1)[href="/"]',					'Home');
       
    93 	test_text	('#header_controls a:nth-of-type(2)[href="/create/content/"]',	'Create a text');
       
    94 	test_text	('#header_controls a:nth-of-type(3)[href="/create/upload/"]',	'Upload a text');
       
    95 	test_text	('#header_controls a:nth-of-type(4)[href="/create/import/"]',	'Import a co-mented text');
       
    96 	test_text	('#header_controls a:nth-of-type(5)[href="/profile/"]',			'Profile');
       
    97 	test_text	('#header_controls a:nth-of-type(6)[href="/logout/"]',			'Logout');
       
    98 	test_text	('#content h1.main_title a[href="/"]',							C['#id_workspace_name']);
       
    99 
       
   100 	if (is_tagline) {
       
   101 		test_match	('#content h1.main_title  + div', new RegExp (C['#id_workspace_tagline'], 'm'));
       
   102 	}
       
   103 }
       
   104 
       
   105 function test_comt_fill_settings (s) {
       
   106 	test_fill_field ('#id_workspace_name', s);
       
   107 	test_fill_field ('#id_workspace_tagline', s);
       
   108 	test_fill_field ('#id_workspace_registration', s);
       
   109 	test_fill_field ('#id_workspace_registration_moderation', s);
       
   110 	test_fill_field ('#id_workspace_role_model', s);
       
   111 	test_fill_field ('#id_workspace_category_1', s);
       
   112 	test_fill_field ('#id_workspace_category_2', s);
       
   113 	test_fill_field ('#id_workspace_category_3', s);
       
   114 	test_fill_field ('#id_workspace_category_4', s);
       
   115 	test_fill_field ('#id_workspace_category_5', s);
       
   116 }
       
   117 
       
   118 function test_comt_fill_design (s) {
       
   119 	test_fill_field ('#id_custom_css', s);
       
   120 	test_fill_field ('#id_custom_font', s);
       
   121 	test_fill_field ('#id_custom_titles_font', s);
       
   122 }
       
   123 
       
   124 /** Test if it's possible to change lang to the specified :
       
   125  *  c : lang code
       
   126  *  l : help label
       
   127  */
       
   128 function test_comt_i18n (c, l) {
       
   129     test ('to '+c, dsl(function () {
       
   130         element ('#footer a[href="/i18n/setlang/'+c+'/"]').click ();
       
   131         browser.navigateTo ('/');
       
   132         expect (elt ('#footer a[href="/help/"]').text ()).toMatch (new RegExp (l, 'm'));
       
   133     }));
       
   134 }
       
   135