src/cm/scripts/test-suite/tests/tests.js
changeset 578 1793daa8df8a
parent 577 65fab7b5ce5e
child 579 869f02c75687
equal deleted inserted replaced
577:65fab7b5ce5e 578:1793daa8df8a
     4 // try to login
     4 // try to login
     5 
     5 
     6 // create texts and co-ments
     6 // create texts and co-ments
     7 // collect newly created URLs
     7 // collect newly created URLs
     8 
     8 
       
     9 // Get workspace name, public texts…
       
    10 
     9 // unlog
    11 // unlog
    10 
    12 
    11 // check that public texts still work while unlogged
    13 // check that public texts still work while unlogged
       
    14 // check that non public texts are unavailable
    12 
    15 
    13 // check that non public texts are unavailable
    16 // Is the workspace name correctly displayed ? 
       
    17 // Are the public texts displayed in the login page ?
       
    18 
       
    19 // var w = require ('./workspace.info.js');
       
    20 
       
    21 var admin_username = 'siltaar';
       
    22 var admin_password = 'oaueoaue';
    14 
    23 
    15 describe ('comt', function () {
    24 describe ('comt', function () {
    16 
    25 
    17 	this.timeout(150000);
    26 	this.timeout(150000);
    18 
    27 
       
    28 	describe ('help page', function () {
       
    29 		it_checks_page_loading ('/help/', 'Help');
       
    30 		it_checks_unlogged_header ();
       
    31 		it_checks_unlogged_footer ();
       
    32 	});
       
    33 
       
    34 	describe ('contact page', function () {
       
    35 		it_checks_page_loading ('/contact/', 'Contact');
       
    36 		it_checks_unlogged_header ();
       
    37 
       
    38 		it ('should have a contact form', dsl(function () {
       
    39 			expect (elt ('#profile[action="."]').val ()).toBeDefined ();
       
    40 		}));
       
    41 
       
    42 		it_checks_form_field ('id_name', 'text', 'Your name', true);
       
    43 		it_checks_form_field ('id_email', 'text', 'Your email address', true);
       
    44 		it_checks_form_field ('id_title', 'text', 'Subject of the message', true);
       
    45 		it_checks_form_field ('id_body', 'textarea', 'Body of the message', true);
       
    46 		it_checks_form_field ('id_copy', 'checkbox', 'Send me a copy of the email', false);
       
    47 
       
    48 		it ('should have some submit and cancel buttons', dsl(function () {
       
    49 			expect (elt ('#profile input[type=submit]').val ()).toBe ('Send');
       
    50 			expect (elt ('input#cancel_button[type=button]').val ()).toBe ('Cancel');
       
    51 		}));
       
    52 
       
    53 		it_checks_unlogged_footer ();
       
    54 	});
       
    55 
       
    56 	describe ('reset password page', function () {
       
    57 		it_checks_page_loading ('/password_reset/', 'Reset my password');
       
    58 		it_checks_unlogged_header ();
       
    59 
       
    60 		it ('should have a contact form', dsl(function () {
       
    61 			expect (elt ('#profile[action="."]').val ()).toBeDefined ();
       
    62 		}));
       
    63 
       
    64 		it_checks_form_field ('id_email', 'text', 'E-mail', true);
       
    65 
       
    66 		it ('should have a submit button', dsl(function () {
       
    67 			expect (elt ('#profile input[type=submit]').val ()).toBe ('Reset my password');
       
    68 		}));
       
    69 
       
    70 		it_checks_unlogged_footer ();
       
    71 	});
       
    72 
    19 	describe ('login page', function () {
    73 	describe ('login page', function () {
    20 		it ('should load', dsl(function () {
    74 		it_checks_page_loading ('/', 'Home');
    21 			// here we are in Karma page
    75 		it_checks_unlogged_header ();
    22 			browser.navigateTo ('/');
       
    23 
    76 
    24 			/*element ('title').text (function (page_title) {
    77 		it ('should have a #login form', dsl(function () {
    25 				// here we got a value from the test iframe
    78 			expect (elt ('#login[action="/login/"]').val ()).toBeDefined ();
    26 				if (typeof page_title != 'string') throw 'page_title not a string, network problem ?';
    79 		}));
    27 				if (!/(Accueil|Home) - Workspace/.test (page_title)) throw 'got page '+page_title+' instead';
       
    28 			});*/
       
    29 
    80 
    30 			expect (element ('title').text ()).toBeDefined ();
    81 		it_checks_form_field ('id_username', 'text', 'Username', true);
    31 			expect (element ('title').text ()).toMatch (/Home/);
    82 		it_checks_form_field ('id_password', 'password', 'Password', true);
    32 
    83 
       
    84 		it ('should have a login button and reset password links', dsl(function () {
       
    85 			expect (elt ('#login input[type=submit]').val ()).toBe ('Login');
       
    86 			expect (elt ('#login a[href="/password_reset/"]').text ()).toBe ('Forgot password?');
    33 		}));
    87 		}));
    34 		it ('should have 2 links in #header_controls', dsl(function () {
       
    35 			expect (element ('#header_controls a').count ()).toBe (2);
       
    36 		}));
       
    37 		it ('should have a Home link in #header_controls', dsl(function () {
       
    38 			expect (element ('#header_controls a[href="/"]').val ()).toBeDefined ();
       
    39 			// to display the tested value :
       
    40 			//element ('#header_controls a[href="/"]').text ( function (txt) { console.log (txt); });
       
    41 			// returns defined ? "" : undefined;
       
    42 		}));
       
    43 		it ('should have a Login link in #header_controls', dsl(function () {
       
    44 			expect (element ('#header_controls a[href="/login/"]').val ()).toBeDefined ();
       
    45 		}));
       
    46 		it ('should not have a XXX link in #header_controls', dsl(function () {
       
    47 			expect (element ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined ();
       
    48 		}));
       
    49 				// with visible homepage and login links
       
    50 			// it should have a title
       
    51 				// with workspace name in it… ?
       
    52 			// it may have public texts
       
    53 				// 0-5
       
    54 				// do we announce the right number of texts ?
       
    55 			// it should have a login form
       
    56 				// with labels
       
    57 				// with red stars
       
    58 				// green button
       
    59 				// forgoten password link
       
    60 			// it should have a footer
       
    61 				// with contact link, powered by co-ment logo, help link, languages links
       
    62 
    88 
    63 			// we should try the links
    89 		it_checks_unlogged_footer ();
    64 			// we should try urls as not logged to check the access avoidance
       
    65 
    90 
    66 		it ('should log in', dsl(function () {
    91 		it ('should log an admin in', dsl(function () {
    67 			browser.navigateTo ('/');
    92 			input ('#id_username').enter (admin_username);
    68 			input ('#id_username').enter ('siltaar');
    93 			input ('#id_password').enter (admin_password);
    69 			input ('#id_password').enter ('oaueoaue');
    94 			elt ('#login input[type=submit]').click ();
    70 			element ('#login input[type=submit]').click ();
    95 			browser.waitForPageLoad ();
    71 			browser.waitForPageLoad ()
    96 			// Must be done here in this 'it' block
    72 			browser.navigateTo ('/');
    97 			browser.navigateTo ('/');
    73 			expect (element ('title').text ()).toMatch (/Dashboard/m);
    98 			expect (element ('title').text ()).toMatch (/Dashboard/m);
    74 
       
    75 		}));
    99 		}));
    76 	});
   100 	});
       
   101 
       
   102 	describe ('admin dashboard', function () {
       
   103 //		it_checks_page_loading ('/', 'Dashboard');
       
   104 		it_checks_logged_header (admin_username);
       
   105 		it_checks_unlogged_footer ();
       
   106 	});
    77 });
   107 });
       
   108 
       
   109 function it_checks_page_loading (url, title) {
       
   110 	it ('should load', dsl(function () {
       
   111 		// here we are in Karma page
       
   112 		browser.navigateTo (url);
       
   113 		expect (element ('title').text ()).toMatch (new RegExp (title,'m'));
       
   114 		element ('title').text (function (page_title) { // The same test with more vanilla javascript
       
   115 			// here we got a value from the test iframe
       
   116 			if (!(new RegExp (title, 'm').test (page_title))) throw 'got page '+page_title+' instead';
       
   117 		});
       
   118 	}));
       
   119 }
       
   120 
       
   121 function it_checks_logged_header (username) {
       
   122 	it ('should have 6 links in #header_controls', dsl(function () {
       
   123 		expect (elt ('#header_controls a').count ()).toBe (6);
       
   124 	}));
       
   125 	it ('should display current connected username', dsl(function () {
       
   126 		expect (elt ('#header_controls b').text ()).toBe (username);
       
   127 	}));
       
   128 		it ('should have a Home link', dsl(function () {
       
   129 		expect (elt ('#header_controls a:nth-of-type(1)[href="/"]').text ()).toBe ('Home');
       
   130 	}));
       
   131 /*		it ('should have a Login link', dsl(function () {
       
   132 		expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login');
       
   133 		expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login');
       
   134 		expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login');
       
   135 		expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login');
       
   136 		expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login');
       
   137 		}));*/
       
   138 }
       
   139 
       
   140 function it_checks_unlogged_header () {
       
   141 	it ('should have 2 links', dsl(function () {
       
   142 		expect (elt ('#header_controls a').count ()).toBe (2);
       
   143 		expect (elt ('#header_controls a[href="/"]').val ()).toBeDefined ();
       
   144 		// to display the tested value :
       
   145 		//elt ('#header_controls a[href="/"]').text ( function (txt) { console.log (txt); });
       
   146 		// it returns defined ? "" : undefined;
       
   147 		expect (elt ('#header_controls a[href="/"]').text ()).toBe ('Home');
       
   148 		expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login');
       
   149 		expect (elt ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined ();
       
   150 	}));
       
   151 }
       
   152 
       
   153 function it_checks_unlogged_footer () {
       
   154 	it ('should have >= 9 links in #footer', dsl(function () {
       
   155 		expect (elt ('#footer a').count ()).toBeGreaterThan (8);
       
   156 		expect (elt ('#footer a[href="/contact/"]').text ()).toBe ('Contact');
       
   157 		expect (elt ('#footer #comentlink[href="http://www.co-ment.com"]').text ()).toMatch (/Powered by/m);
       
   158 		expect (elt ('#footer a[href="/help/"]').text ()).toBe ('Help');
       
   159 	}));
       
   160 }
       
   161 
       
   162 function it_checks_form_field (id, type, label, mandatory) {
       
   163 	it ('should have a '+label+' field', dsl(function () {
       
   164 		var s = type == 'textarea' ? 'textarea#'+id : 'input#'+id+'[type='+type+']';
       
   165 		expect (elt (s).val ()).toBeDefined ();
       
   166 		expect (elt ('label[for='+id+']').text ()).toBe (label);
       
   167 
       
   168 		if (mandatory)
       
   169 			expect (elt ('label[for='+id+'] + span.required_star').val ()).toBeDefined ();
       
   170 	}));
       
   171 }
       
   172 
       
   173 function elt (selector) {
       
   174 	return element (selector + ':visible');
       
   175 }