src/cm/scripts/test-suite/tests/tests.js
changeset 583 084934fe912e
parent 582 63b489ad02a3
child 594 daf4516b022d
equal deleted inserted replaced
582:63b489ad02a3 583:084934fe912e
    13 
    13 
    14 // Is the workspace name correctly displayed ? 
    14 // Is the workspace name correctly displayed ? 
    15 // Are the public texts displayed in the login page ?
    15 // Are the public texts displayed in the login page ?
    16 
    16 
    17 var w = __karma__.config.w;
    17 var w = __karma__.config.w;
       
    18 const non_visible = false;
       
    19 var text_nb = 0;
       
    20 var user_nb = 0;
       
    21 var pub_text_nb = 0;
       
    22 var workspace_name = '';
       
    23 var workspace_tagline = '';
    18 
    24 
    19 suite ('comt', function () {
    25 suite ('comt', function () {
    20 
    26 
    21 	this.timeout(150000);
    27 	this.timeout(150000);
    22 
    28 
    23 	suite ('contact page', function () {
    29 	suite ('contact page', function () {
    24 		test_page_loading ('/contact/', 'Contact');
    30 		test_page_loading ('/contact/', 'Contact');
    25 		test_unlogged_header ();
    31 		test_unlogged_header ();
    26 		test_val ('form#profile[action="."]'); // the form exists
    32 		test_val	('form#profile[action="."]'); // the form exists
    27 		test_count ('form#profile .label', 5); // it has no more than 5 labels (may be no more fields)
    33 		test_count	('form#profile :input', 7); // it has no more than 5 labels (may be no more fields)
    28 		test_form_field ('profile', 'id_name', 'text', 0, 'Your name', true); // the field id_name is…
    34 		test_form_field ('profile', 'id_name', 'text', 0, 'Your name', true); // the field id_name is…
    29 		test_form_field ('profile', 'id_email', 'text', 1, 'Your email address', true);
    35 		test_form_field ('profile', 'id_email', 'text', 1, 'Your email address', true);
    30 		test_form_field ('profile', 'id_title', 'text', 2, 'Subject of the message', true);
    36 		test_form_field ('profile', 'id_title', 'text', 2, 'Subject of the message', true);
    31 		test_form_field ('profile', 'id_body', 'textarea', 3, 'Body of the message', true);
    37 		test_form_field ('profile', 'id_body', 'textarea', 3, 'Body of the message', true);
    32 		test_form_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false);
    38 		test_form_field ('profile', 'id_copy', 'checkbox', 4, 'Send me a copy of the email', false);
    33 		test_val ('#profile input[type=submit]','Send'); // test that a the .val() of the element is
    39 		test_val	('#profile input[type=submit]','Send'); // test that a the .val() of the element is
    34 		test_val ('input#cancel_button[type=button]', 'Cancel');
    40 		test_val	('input#cancel_button[type=button]', 'Cancel');
    35 		test_unlogged_footer ();
    41 		test_unlogged_footer ();
    36 		test ('to check that toBeDefined test still works', dsl(function () {
    42 		test		('to check that toBeDefined test still works', dsl(function () {
    37 			expect (elt ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined ();
    43 			expect (elt ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined ();
    38 		}));
    44 		}));
    39 		test ('get back to / to avoid bugging next page load', dsl(function () {
    45 		test		('get back to / to avoid bugging next page load', dsl(function () {
    40 			browser.navigateTo ('/');
    46 			browser.navigateTo ('/');
    41 		}));
    47 		}));
    42 	});
    48 	});
    43 
    49 
    44 	suite ('help page', function () {
    50 	suite ('help page', function () {
    48 	});
    54 	});
    49 
    55 
    50 	suite ('reset password page', function () {
    56 	suite ('reset password page', function () {
    51 		test_page_loading ('/password_reset/', 'Reset my password');
    57 		test_page_loading ('/password_reset/', 'Reset my password');
    52 		test_unlogged_header ();
    58 		test_unlogged_header ();
    53 		test_val ('form#profile[action="."]');
    59 		test_val	('form#profile[action="."]');
    54 		test_count ('form#profile .label', 1);
    60 		test_count	('form#profile :input', 3);
    55 		test_form_field ('profile', 'id_email', 'text', 1, 'E-mail', true);
    61 		test_form_field ('profile', 'id_email', 'text', 1, 'E-mail', true);
    56 		test_val ('#profile input[type=submit]', 'Reset my password');
    62 		test_val	('#profile input[type=submit]', 'Reset my password');
    57 		test_unlogged_footer ();
    63 		test_unlogged_footer ();
    58 	});
    64 	});
    59 
    65 
    60 	suite ('login page', function () {
    66 	suite ('login page', function () {
    61 		test_page_loading ('/', 'Home');
    67 		test_page_loading ('/', 'Home');
    62 		test_unlogged_header ();
    68 		test_unlogged_header ();
    63 		test_val ('form#login[action="/login/"]');
    69 		test_val	('form#login[action="/login/"]');
    64 		test_count ('form#login[action="/login/"] .label', 2);
    70 		test_count	('form#login[action="/login/"] :input', 3);
    65 		test_form_field ('login', 'id_username', 'text', 0, 'Username', true);
    71 		test_form_field ('login', 'id_username', 'text', 0, 'Username', true);
    66 		test_form_field ('login', 'id_password', 'password', 1, 'Password', true);
    72 		test_form_field ('login', 'id_password', 'password', 1, 'Password', true);
    67 		test_val ('form#login input[type=submit]', 'Login');
    73 		test_val ('form#login input[type=submit]', 'Login');
    68 		test_text ('form#login a[href="/password_reset/"]', 'Forgot password?');
    74 		test_text	('form#login a[href="/password_reset/"]', 'Forgot password?');
    69 		test_unlogged_footer ();
    75 		test_unlogged_footer ();
    70 		// test_i18n ();
    76 		// test_i18n ();
    71 		test ('logs an admin in', dsl(function () {
    77 		test		('logs an admin in', dsl(function () {
    72 			input ('#id_username').enter (w.USER_ADMIN);
    78 			input ('#id_username').enter (w.USER_ADMIN);
    73 			input ('#id_password').enter (w.PASS_ADMIN);
    79 			input ('#id_password').enter (w.PASS_ADMIN);
    74 			elt ('#login input[type=submit]').click ();
    80 			elt ('#login input[type=submit]').click ();
    75 			// Must be done here in this test() block
    81 			// Must be done here in this test() block
    76 			browser.waitForPageLoad ();
    82 			browser.waitForPageLoad ();
    82 	suite ('admin dashboard', function () {
    88 	suite ('admin dashboard', function () {
    83 		// Should starts with :
    89 		// Should starts with :
    84 		// test_page_loading ('/', 'Dashboard');
    90 		// test_page_loading ('/', 'Dashboard');
    85 		// But its the last thing we did in the previous test
    91 		// But its the last thing we did in the previous test
    86 		test_logged_header (w.USER_ADMIN);
    92 		test_logged_header (w.USER_ADMIN);
       
    93 		test ('get text and user nb', dsl(function () {
       
    94 			element ('span.metadata:eq(0)').text (function (metadata) {
       
    95 				var r = metadata.match (/(\d+) texts, (\d+) users/);
       
    96 				if (r.length != 3) throw 'expected 3 matches got '+r.length;
       
    97 				text_nb = r[1];
       
    98 				user_nb = r[2];
       
    99 			});
       
   100 		}));
    87 		test_default_tabs ();
   101 		test_default_tabs ();
    88 		test_count	('table.dash_table', 5);
   102 		test_count	('table.dash_table', 5);
    89 		test_text	('table.dash_table th:eq(0)', 'Actions');
   103 		test_text	('table.dash_table th:eq(0)', 'Actions');
    90 		test_match	('table.dash_table:eq(0) a:eq(0)[href="/create/content/"]', /\sCreate a text/);
   104 		test_match	('table.dash_table:eq(0) a:eq(0)[href="/create/content/"]', /\sCreate a text/);
    91 		test_text	('table.dash_table:eq(0) a:eq(1).tip[href="#"]', ' ');
   105 		test_text	('table.dash_table:eq(0) a:eq(1).tip[href="#"]', ' ');
   105 		test_text	('table.dash_table:eq(3) a:eq(1)[href="?span=day"]', '24 hours');
   119 		test_text	('table.dash_table:eq(3) a:eq(1)[href="?span=day"]', '24 hours');
   106 		test_text	('table.dash_table th:eq(4) span.em', 'Activities');
   120 		test_text	('table.dash_table th:eq(4) span.em', 'Activities');
   107 		test_unlogged_footer ();
   121 		test_unlogged_footer ();
   108 	});
   122 	});
   109 
   123 
       
   124 	suite ('texts list', function () {
       
   125 		test_page_loading ('/text/', 'Texts');
       
   126 		test_logged_header (w.USER_ADMIN);
       
   127 		test_default_tabs ();
       
   128 		test_count	('#text ul.sub_list:eq(0) a', 3);
       
   129 		test_text	('#text ul.sub_list:eq(0) a:eq(0)[href="/create/content/"]', 'Create a text');
       
   130 		test_text	('#text ul.sub_list:eq(0) a:eq(1)[href="/create/upload/"]', 'Upload a text');
       
   131 		test_text	('#text ul.sub_list:eq(0) a:eq(2)[href="/create/import/"]', 'Import a co-mented text');
       
   132 		// TOTEST : filter by tag
       
   133 		test_count	('form#filter_form[action="."] :input', 1);
       
   134 		test_text	('select#tag_selected option:eq(0)[selected][value="0"]', '- All -', non_visible);
       
   135 		test		('#texts_form input count', dsl (function () {
       
   136 			elt ('form#texts_form[action="."] :input').count (function (c) {
       
   137 				var n = 3 + text_nb % 10;
       
   138 				if (c != n) throw 'expected computed '+n+' to equal got '+c;
       
   139 			});
       
   140 		}));
       
   141 		test		('#paginator "of #" value', dsl (function () {
       
   142 			elt ('span#paginator').text (function (t) {
       
   143 				var r = t.match (/\s\d+-\d+ of (\d+)\s/m);
       
   144 				if (r.length != 2) throw 'expected 2 matches got '+r.length;
       
   145 				if (r[1] != text_nb) throw 'expected paginator total ('+r[1]+') to be '+text_nb;
       
   146 			});
       
   147 		}));
       
   148 		// TOTEST : pagination
       
   149 		// TOTEST : Bulk Actions -> Apply does enable
       
   150 		test_text	('select#bulk_actions option:eq(0)[selected][value="-1"]', 'Bulk Actions', non_visible);
       
   151 		test_text	('select#bulk_actions option:eq(1)[value="delete"]', 'Delete', non_visible);
       
   152 		test_val	('form#texts_form input#apply[type=button][disabled]', 'Apply');
       
   153 		test_count	('table.large_table:eq(1) th', 6);
       
   154 		test_val	('table.large_table:eq(1) th:eq(0) input#all_check[type="checkbox"]', 'on');
       
   155 		test_text	('table.large_table:eq(1) th:eq(1) a[href="?order=title"]', 'Text');
       
   156 		test_text	('table.large_table:eq(1) th:eq(2)', 'Author');
       
   157 		test_text	('table.large_table:eq(1) th:eq(3) a[href="?order=-modified"]', 'Modified');
       
   158 		test_text	('table.large_table:eq(1) th:eq(4)', '# comments');
       
   159 		test_text	('table.large_table:eq(1) th:eq(5)', 'Last week activity');
       
   160 		test_unlogged_footer ();
       
   161 	});
       
   162 
   110 	suite ('followup', function () {
   163 	suite ('followup', function () {
       
   164 		test_logged_header (w.USER_ADMIN);
       
   165 		test_default_tabs ();
   111 		test_page_loading ('/followup/', 'Followup');
   166 		test_page_loading ('/followup/', 'Followup');
   112 		test_text	('#followup a:eq(0)[href="/help/#public_private_feed"]', '?');
   167 		test_text	('#followup a:eq(0)[href="/help/#public_private_feed"]', '?');
   113 		test_match	('#followup a:eq(1)[href$="/feed/"]', new RegExp (w.WORKSPACE_URL+'feed/', 'm'));
   168 		test_match	('#followup a:eq(1)[href$="/feed/"]', new RegExp (w.WORKSPACE_URL+'feed/', 'm'));
   114 		test_text	('#followup a:eq(2)[href="/help/#public_private_feed"]', '?');
   169 		test_text	('#followup a:eq(2)[href="/help/#public_private_feed"]', '?');
   115 		test_count	('form#followup_form[action="."] input', 3);
   170 		test_count	('form#followup_form[action="."] :input', 3);
   116 		test_val	('form#followup_form input[type=submit]', '(Activate private feed|Reset private feed url)');
   171 		test_val	('form#followup_form input[type=submit]', '(Activate private feed|Reset private feed url)');
   117 		test_val	('form#followup_form input#workspace_notify_check[type=checkbox]', 'on');
   172 		test_val	('form#followup_form input#workspace_notify_check[type=checkbox]', 'on');
   118 		test_val	('form#followup_form input#own_notify_check[type=checkbox]', 'on');
   173 		test_val	('form#followup_form input#own_notify_check[type=checkbox]', 'on');
   119 	
   174 	
   120 		// tester qu'une fois cliqué, le bouton à le nvo label, et qu'une adresse est disponible
   175 		// tester qu'une fois cliqué, le bouton à le nvo label, et qu'une adresse est disponible
   121 		// tester que si on reclique l'adresse est changée
   176 		// tester que si on reclique l'adresse est changée
   122 
   177 
       
   178 		test_unlogged_footer ();
   123 	});
   179 	});
   124 });
   180 });
   125 
   181 
   126 function test_default_tabs () {
   182 function test_default_tabs () {
   127 	test_count	('#main-tabs a', 5);
   183 	test_count	('#main-tabs a', 5);
   128 	test_text	('#main-tabs li:nth-of-type(1) a[href="/"]', 'Dashboard');
   184 	test_text	('#main-tabs li:nth-of-type(1) a[href="/"]',			'Dashboard');
   129 	test_match	('#main-tabs li:nth-of-type(2) a[href="/text/"]', /^Texts \(\d+\) $/);
   185 	test_match	('#main-tabs li:nth-of-type(2) a[href="/text/"]',		/^Texts \(\d+\) $/);
   130 	test_match	('#main-tabs li:nth-of-type(3) a[href="/user/"]', /^People  \(\d+\)$/);
   186 	test_match	('#main-tabs li:nth-of-type(3) a[href="/user/"]',		/^People  \(\d+\)$/);
   131 	test_text	('#main-tabs li:nth-of-type(4) a[href="/settings/"]', 'Settings');
   187 	test_text	('#main-tabs li:nth-of-type(4) a[href="/settings/"]',	'Settings');
   132 	test_text	('#main-tabs li:nth-of-type(5) a[href="/followup/"]', 'Followup');
   188 	test_text	('#main-tabs li:nth-of-type(5) a[href="/followup/"]',	'Followup');
       
   189 	test ('right tab nb', dsl(function () {
       
   190 		elt ('#main-tabs a[href="/text/"]').text (function (t) {
       
   191 			var r = t.match (/^Texts \((\d+)\) $/);
       
   192 			if (r.length != 2) throw 'for Texts expected 2 matches got '+r.length;
       
   193 			if (text_nb != r[1]) throw 'expected tab text nb ('+r[1]+') to be '+text_nb;
       
   194 		});
       
   195 		elt ('#main-tabs a[href="/user/"]').text (function (t) {
       
   196 			var r = t.match (/^People  \((\d+)\)$/);
       
   197 			if (r.length != 2) throw 'for People expected 2 matches got '+r.length;
       
   198 			if (user_nb != r[1]) throw 'expected tab people nb ('+r[1]+') to be '+user_nb;
       
   199 		});
       
   200 	}));
   133 }
   201 }
   134 
   202 
   135 function test_logged_header (username) {
   203 function test_logged_header (username) {
   136 	test_text	('#header_controls b', username)
   204 	test_text	('#header_controls b', username)
   137 	test_count	('#header_controls a', 6);
   205 	test_count	('#header_controls a', 6);
   143 	test_text	('#header_controls a:nth-of-type(6)[href="/logout/"]',			'Logout');
   211 	test_text	('#header_controls a:nth-of-type(6)[href="/logout/"]',			'Logout');
   144 }
   212 }
   145 
   213 
   146 function test_unlogged_header () {
   214 function test_unlogged_header () {
   147 	test_count	('#header_controls a', 2);
   215 	test_count	('#header_controls a', 2);
   148 	test_text	('#header_controls a[href="/"]', 'Home');
   216 	test_text	('#header_controls a[href="/"]',		'Home');
   149 	test_text	('#header_controls a[href="/login/"]', 'Login');
   217 	test_text	('#header_controls a[href="/login/"]',	'Login');
   150 }
   218 }
   151 
   219 
   152 function test_unlogged_footer (url) {
   220 function test_unlogged_footer (url) {
   153 	test_count	('#footer a', 9);
   221 	test_count	('#footer a', 9);
   154 	test_text	('#footer a:nth-of-type(1)[href="/contact/"]', 'Contact');
   222 	test_text	('#footer a:nth-of-type(1)[href="/contact/"]',				'Contact');
   155 	test_match	('#footer #comentlink[href="http://www.co-ment.com"]', /Powered by/m);
   223 	test_match	('#footer #comentlink[href="http://www.co-ment.com"]',		/Powered by/m);
   156 	test_text	('#footer a:nth-of-type(3)[href="/help/"]', 'Help');
   224 	test_text	('#footer a:nth-of-type(3)[href="/help/"]',					'Help');
   157 	test_text	('#footer a:nth-of-type(4)[href="/i18n/setlang/fr/"]', 'Français');
   225 	test_text	('#footer a:nth-of-type(4)[href="/i18n/setlang/fr/"]',		'Français');
   158 	test_text	('#footer a:nth-of-type(5)[href="/i18n/setlang/no/"]', 'Norsk');
   226 	test_text	('#footer a:nth-of-type(5)[href="/i18n/setlang/no/"]',		'Norsk');
   159 	test_text	('#footer a:nth-of-type(6)[href="/i18n/setlang/pt_BR/"]', 'Português Brasileiro');
   227 	test_text	('#footer a:nth-of-type(6)[href="/i18n/setlang/pt_BR/"]',	'Português Brasileiro');
   160 	test_text	('#footer a:nth-of-type(7)[href="/i18n/setlang/es/"]', 'Español');
   228 	test_text	('#footer a:nth-of-type(7)[href="/i18n/setlang/es/"]',		'Español');
   161 	test_text	('#footer a:nth-of-type(8)[href="/i18n/setlang/bg/"]', 'Български');
   229 	test_text	('#footer a:nth-of-type(8)[href="/i18n/setlang/bg/"]',		'Български');
   162 	test_text	('#footer a:nth-of-type(9)[href="/i18n/setlang/it/"]', 'Italiano');
   230 	test_text	('#footer a:nth-of-type(9)[href="/i18n/setlang/it/"]',		'Italiano');
   163 }
   231 }
   164 
   232 
   165 function test_i18n () {
   233 function test_i18n () {
   166 	test ('can change lang to french', dsl(function () {
   234 	test ('can change lang to french', dsl(function () {
   167 		element ('#footer a[href="/i18n/setlang/fr/"]').click ();
   235 		element ('#footer a[href="/i18n/setlang/fr/"]').click ();
   174 //		browser.navigateTo ('/');
   242 //		browser.navigateTo ('/');
   175 	}));
   243 	}));
   176 }
   244 }
   177 
   245 
   178 function test_page_loading (url, title) {
   246 function test_page_loading (url, title) {
   179 	test ('loads', dsl(function () {
   247 	test (url+' loads', dsl(function () {
   180 		// here we are in Karma page
   248 		// here we are in Karma page
   181 		browser.navigateTo (url);
   249 		browser.navigateTo (url);
   182 		expect (element ('title').text ()).toMatch (new RegExp (title,'m'));
   250 		expect (element ('title').text ()).toMatch (new RegExp (title,'m'));
   183 		// The same test agin vaniller javascript
   251 		// The same test agin vaniller javascript
   184 		element ('title').text (function (page_title) {
   252 		element ('title').text (function (page_title) {
   201 }
   269 }
   202 
   270 
   203 /** Test if the selected DOM element has the given text : .text()
   271 /** Test if the selected DOM element has the given text : .text()
   204  *  s : CSS selector
   272  *  s : CSS selector
   205  *  e : expected value
   273  *  e : expected value
   206  */
   274  *  v : should we test a visible value ?
   207 function test_text (s, e) {
   275  */
       
   276 function test_text (s, e, v) {
       
   277 	v = typeof v == 'undefined' ? true : v;
   208 	test (s+' has text '+e, dsl(function () {
   278 	test (s+' has text '+e, dsl(function () {
   209 		expect (elt (s).text ()).toBe (e);
   279 		expect (elt (s, v).text ()).toBe (e);
   210 	}));
   280 	}));
   211 }
   281 }
   212 
   282 
   213 /** Test if the selected DOM element .text() value match the given regexp
   283 /** Test if the selected DOM element .text() value match the given regexp
   214  *  s : CSS selector
   284  *  s : CSS selector
   244 	}));
   314 	}));
   245 }
   315 }
   246 
   316 
   247 /** Ensure the given element is visible
   317 /** Ensure the given element is visible
   248  *  s : CSS selector of the DOM element to check
   318  *  s : CSS selector of the DOM element to check
   249  */
   319  *  v : should the element being visible
   250 function elt (s) {
   320  */
   251 	return element (s + ':visible');
   321 function elt (s, v) {
   252 }
   322 	return element (s + (v ? ':visible' : ''));
       
   323 }