14 // check that non public texts are unavailable |
12 // check that non public texts are unavailable |
15 |
13 |
16 // Is the workspace name correctly displayed ? |
14 // Is the workspace name correctly displayed ? |
17 // Are the public texts displayed in the login page ? |
15 // Are the public texts displayed in the login page ? |
18 |
16 |
19 // var w = require ('./workspace.info.js'); |
17 var w = __karma__.config.w; |
20 |
18 |
21 var admin_username = 'siltaar'; |
19 suite ('comt', function () { |
22 var admin_password = 'oaueoaue'; |
|
23 |
|
24 describe ('comt', function () { |
|
25 |
20 |
26 this.timeout(150000); |
21 this.timeout(150000); |
27 |
22 |
28 describe ('help page', function () { |
23 suite ('contact page', function () { |
29 it_checks_page_loading ('/help/', 'Help'); |
24 test_page_loading ('/contact/', 'Contact'); |
30 it_checks_unlogged_header (); |
25 test_unlogged_header (); |
31 it_checks_unlogged_footer (); |
|
32 }); |
|
33 |
26 |
34 describe ('contact page', function () { |
27 test ('has a contact form', dsl(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 (); |
28 expect (elt ('#profile[action="."]').val ()).toBeDefined (); |
40 })); |
29 })); |
41 |
30 |
42 it_checks_form_field ('id_name', 'text', 'Your name', true); |
31 test_form_field ('id_name', 'text', 'Your name', true); |
43 it_checks_form_field ('id_email', 'text', 'Your email address', true); |
32 test_form_field ('id_email', 'text', 'Your email address', true); |
44 it_checks_form_field ('id_title', 'text', 'Subject of the message', true); |
33 test_form_field ('id_title', 'text', 'Subject of the message', true); |
45 it_checks_form_field ('id_body', 'textarea', 'Body of the message', true); |
34 test_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); |
35 test_form_field ('id_copy', 'checkbox', 'Send me a copy of the email', false); |
47 |
36 |
48 it ('should have some submit and cancel buttons', dsl(function () { |
37 test ('has some submit and cancel buttons', dsl(function () { |
49 expect (elt ('#profile input[type=submit]').val ()).toBe ('Send'); |
38 expect (elt ('#profile input[type=submit]').val ()).toBe ('Send'); |
50 expect (elt ('input#cancel_button[type=button]').val ()).toBe ('Cancel'); |
39 expect (elt ('input#cancel_button[type=button]').val ()).toBe ('Cancel'); |
51 })); |
40 })); |
52 |
41 |
53 it_checks_unlogged_footer (); |
42 test_unlogged_footer (); |
|
43 |
|
44 // To avoid bugging in loading the 2nd page |
|
45 test ('just get back to /', dsl(function () { |
|
46 browser.navigateTo ('/'); |
|
47 })); |
54 }); |
48 }); |
55 |
49 |
56 describe ('reset password page', function () { |
50 suite ('help page', function () { |
57 it_checks_page_loading ('/password_reset/', 'Reset my password'); |
51 test_page_loading ('/help/', 'Help'); |
58 it_checks_unlogged_header (); |
52 test_unlogged_header (); |
|
53 test_unlogged_footer (); |
|
54 }); |
59 |
55 |
60 it ('should have a contact form', dsl(function () { |
56 suite ('reset password page', function () { |
|
57 test_page_loading ('/password_reset/', 'Reset my password'); |
|
58 test_unlogged_header (); |
|
59 |
|
60 test ('has a contact form', dsl(function () { |
61 expect (elt ('#profile[action="."]').val ()).toBeDefined (); |
61 expect (elt ('#profile[action="."]').val ()).toBeDefined (); |
62 })); |
62 })); |
63 |
63 |
64 it_checks_form_field ('id_email', 'text', 'E-mail', true); |
64 test_form_field ('id_email', 'text', 'E-mail', true); |
65 |
65 |
66 it ('should have a submit button', dsl(function () { |
66 test ('has a submit button', dsl(function () { |
67 expect (elt ('#profile input[type=submit]').val ()).toBe ('Reset my password'); |
67 expect (elt ('#profile input[type=submit]').val ()).toBe ('Reset my password'); |
68 })); |
68 })); |
69 |
69 |
70 it_checks_unlogged_footer (); |
70 test_unlogged_footer (); |
71 }); |
71 }); |
72 |
72 |
73 describe ('login page', function () { |
73 suite ('login page', function () { |
74 it_checks_page_loading ('/', 'Home'); |
74 test_page_loading ('/', 'Home'); |
75 it_checks_unlogged_header (); |
75 test_unlogged_header (); |
76 |
76 |
77 it ('should have a #login form', dsl(function () { |
77 test ('has a #login form', dsl(function () { |
78 expect (elt ('#login[action="/login/"]').val ()).toBeDefined (); |
78 expect (elt ('#login[action="/login/"]').val ()).toBeDefined (); |
79 })); |
79 })); |
80 |
80 |
81 it_checks_form_field ('id_username', 'text', 'Username', true); |
81 test_form_field ('id_username', 'text', 'Username', true); |
82 it_checks_form_field ('id_password', 'password', 'Password', true); |
82 test_form_field ('id_password', 'password', 'Password', true); |
83 |
83 |
84 it ('should have a login button and reset password links', dsl(function () { |
84 test ('has a login button and reset password links', dsl(function () { |
85 expect (elt ('#login input[type=submit]').val ()).toBe ('Login'); |
85 expect (elt ('#login input[type=submit]').val ()).toBe ('Login'); |
86 expect (elt ('#login a[href="/password_reset/"]').text ()).toBe ('Forgot password?'); |
86 expect (elt ('#login a[href="/password_reset/"]').text ()).toBe ('Forgot password?'); |
87 })); |
87 })); |
88 |
88 |
89 it_checks_unlogged_footer (); |
89 test_unlogged_footer (); |
90 |
90 |
91 it ('should log an admin in', dsl(function () { |
91 test ('logs an admin in', dsl(function () { |
92 input ('#id_username').enter (admin_username); |
92 input ('#id_username').enter (w.USER_ADMIN); |
93 input ('#id_password').enter (admin_password); |
93 input ('#id_password').enter (w.PASS_ADMIN); |
94 elt ('#login input[type=submit]').click (); |
94 elt ('#login input[type=submit]').click (); |
|
95 // Must be done here in this test() block |
95 browser.waitForPageLoad (); |
96 browser.waitForPageLoad (); |
96 // Must be done here in this 'it' block |
|
97 browser.navigateTo ('/'); |
97 browser.navigateTo ('/'); |
98 expect (element ('title').text ()).toMatch (/Dashboard/m); |
98 expect (element ('title').text ()).toMatch (/Dashboard/m); |
99 })); |
99 })); |
100 }); |
100 }); |
101 |
101 |
102 describe ('admin dashboard', function () { |
102 suite ('admin dashboard', function () { |
103 // it_checks_page_loading ('/', 'Dashboard'); |
103 // Should starts with : |
104 it_checks_logged_header (admin_username); |
104 test_page_loading ('/', 'Dashboard'); |
105 it_checks_unlogged_footer (); |
105 // But its the last thing we did in the previous test |
|
106 test_logged_header (w.USER_ADMIN); |
|
107 test_unlogged_footer (); |
106 }); |
108 }); |
107 }); |
109 }); |
108 |
110 |
109 function it_checks_page_loading (url, title) { |
111 function test_page_loading (url, title) { |
110 it ('should load', dsl(function () { |
112 test ('loads', dsl(function () { |
111 // here we are in Karma page |
113 // here we are in Karma page |
112 browser.navigateTo (url); |
114 browser.navigateTo (url); |
113 expect (element ('title').text ()).toMatch (new RegExp (title,'m')); |
115 expect (element ('title').text ()).toMatch (new RegExp (title,'m')); |
114 element ('title').text (function (page_title) { // The same test with more vanilla javascript |
116 element ('title').text (function (page_title) { // The same test with more vanilla javascript |
115 // here we got a value from the test iframe |
117 // here we got a value from the test iframe |
116 if (!(new RegExp (title, 'm').test (page_title))) throw 'got page '+page_title+' instead'; |
118 if (!(new RegExp (title, 'm').test (page_title))) throw 'got page '+page_title+' instead'; |
117 }); |
119 }); |
118 })); |
120 })); |
119 } |
121 } |
120 |
122 |
121 function it_checks_logged_header (username) { |
123 function test_logged_header (username) { |
122 it ('should have 6 links in #header_controls', dsl(function () { |
124 test ('has 6 links in #header_controls', dsl(function () { |
123 expect (elt ('#header_controls a').count ()).toBe (6); |
125 expect (elt ('#header_controls a').count ()).toBe (6); |
124 })); |
126 })); |
125 it ('should display current connected username', dsl(function () { |
127 test ('displays current connected user name', dsl(function () { |
126 expect (elt ('#header_controls b').text ()).toBe (username); |
128 expect (elt ('#header_controls b').text ()).toBe (username); |
127 })); |
129 })); |
128 it ('should have a Home link', dsl(function () { |
130 test ('has links', dsl(function () { |
129 expect (elt ('#header_controls a:nth-of-type(1)[href="/"]').text ()).toBe ('Home'); |
131 expect (elt ('#header_controls a:nth-of-type(1)[href="/"]').text ()).toBe ('Home'); |
|
132 expect (elt ('#header_controls a:nth-of-type(2)[href="/create/content/"]').text ()).toBe ('Create a text'); |
|
133 expect (elt ('#header_controls a:nth-of-type(3)[href="/create/upload/"]').text ()).toBe ('Upload a text'); |
|
134 expect (elt ('#header_controls a:nth-of-type(4)[href="/create/import/"]').text ()).toBe ('Import a co-mented text'); |
|
135 expect (elt ('#header_controls a:nth-of-type(5)[href="/profile/"]').text ()).toBe ('Profile'); |
|
136 expect (elt ('#header_controls a:nth-of-type(6)[href="/logout/"]').text ()).toBe ('Logout'); |
130 })); |
137 })); |
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 } |
138 } |
139 |
139 |
140 function it_checks_unlogged_header () { |
140 function test_unlogged_header () { |
141 it ('should have 2 links', dsl(function () { |
141 test ('has 2 links', dsl(function () { |
142 expect (elt ('#header_controls a').count ()).toBe (2); |
142 expect (elt ('#header_controls a').count ()).toBe (2); |
143 expect (elt ('#header_controls a[href="/"]').val ()).toBeDefined (); |
143 expect (elt ('#header_controls a[href="/"]').val ()).toBeDefined (); |
144 // to display the tested value : |
144 // to display the tested value : |
145 //elt ('#header_controls a[href="/"]').text ( function (txt) { console.log (txt); }); |
145 //elt ('#header_controls a[href="/"]').text ( function (txt) { console.log (txt); }); |
146 // it returns defined ? "" : undefined; |
146 // test returns defined ? "" : undefined; |
147 expect (elt ('#header_controls a[href="/"]').text ()).toBe ('Home'); |
147 expect (elt ('#header_controls a[href="/"]').text ()).toBe ('Home'); |
148 expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); |
148 expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); |
149 expect (elt ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined (); |
149 expect (elt ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined (); |
150 })); |
150 })); |
151 } |
151 } |
152 |
152 |
153 function it_checks_unlogged_footer () { |
153 function test_unlogged_footer (url) { |
154 it ('should have >= 9 links in #footer', dsl(function () { |
154 test ('has >= 9 links in #footer', dsl(function () { |
155 expect (elt ('#footer a').count ()).toBeGreaterThan (8); |
155 expect (elt ('#footer a').count ()).toBeGreaterThan (8); |
156 expect (elt ('#footer a[href="/contact/"]').text ()).toBe ('Contact'); |
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); |
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'); |
158 expect (elt ('#footer a[href="/help/"]').text ()).toBe ('Help'); |
159 })); |
159 })); |
|
160 /* test ('can change lang to french', dsl(function () { |
|
161 element ('#footer a[href="/i18n/setlang/fr/"]').click (); |
|
162 // browser.waitForPageLoad (); |
|
163 // browser.navigateTo ('/'); |
|
164 expect (elt ('#footer a[href="/help/"]').text ()).toBe ('Aide'); |
|
165 element ('#footer a[href="/i18n/setlang/en/"]').click (); |
|
166 // browser.waitForPageLoad (); |
|
167 // browser.navigateTo ('/'); |
|
168 }));*/ |
160 } |
169 } |
161 |
170 |
162 function it_checks_form_field (id, type, label, mandatory) { |
171 /* Test Django form field presence */ |
163 it ('should have a '+label+' field', dsl(function () { |
172 function test_form_field (id, type, label, mandatory) { |
|
173 test ('has a '+label+' field', dsl(function () { |
164 var s = type == 'textarea' ? 'textarea#'+id : 'input#'+id+'[type='+type+']'; |
174 var s = type == 'textarea' ? 'textarea#'+id : 'input#'+id+'[type='+type+']'; |
165 expect (elt (s).val ()).toBeDefined (); |
175 expect (elt (s).val ()).toBeDefined (); |
166 expect (elt ('label[for='+id+']').text ()).toBe (label); |
176 expect (elt ('label[for='+id+']').text ()).toBe (label); |
167 |
177 |
168 if (mandatory) |
178 if (mandatory) |