# HG changeset patch # User Simon Descarpentries # Date 1392748078 -3600 # Node ID 869f02c75687a91771085e5e98f3b8d614a498b9 # Parent 1793daa8df8ae8de23fa95aee6ca33efbf1ff1d5 daily progress : suite/test style, config from single config file, attempt to test i18n in footer diff -r 1793daa8df8a -r 869f02c75687 src/cm/scripts/test-suite/karma.conf.js --- a/src/cm/scripts/test-suite/karma.conf.js Mon Feb 17 19:18:42 2014 +0100 +++ b/src/cm/scripts/test-suite/karma.conf.js Tue Feb 18 19:27:58 2014 +0100 @@ -26,6 +26,12 @@ proxies: { '/': w.WORKSPACE_URL }, + client: { + mocha: { + ui: 'tdd' + }, + w: w // SID: exports the variable in the test execution browser window + }, // test results reporter to use : 'dots', 'progress', 'junit', 'growl', 'coverage' reporters: ['progress'], // web server port diff -r 1793daa8df8a -r 869f02c75687 src/cm/scripts/test-suite/tests/tests.js --- a/src/cm/scripts/test-suite/tests/tests.js Mon Feb 17 19:18:42 2014 +0100 +++ b/src/cm/scripts/test-suite/tests/tests.js Tue Feb 18 19:27:58 2014 +0100 @@ -1,5 +1,3 @@ - -// console.log ('args '+args); // try to login @@ -16,98 +14,102 @@ // Is the workspace name correctly displayed ? // Are the public texts displayed in the login page ? -// var w = require ('./workspace.info.js'); +var w = __karma__.config.w; -var admin_username = 'siltaar'; -var admin_password = 'oaueoaue'; - -describe ('comt', function () { +suite ('comt', function () { this.timeout(150000); - describe ('help page', function () { - it_checks_page_loading ('/help/', 'Help'); - it_checks_unlogged_header (); - it_checks_unlogged_footer (); - }); + suite ('contact page', function () { + test_page_loading ('/contact/', 'Contact'); + test_unlogged_header (); - describe ('contact page', function () { - it_checks_page_loading ('/contact/', 'Contact'); - it_checks_unlogged_header (); - - it ('should have a contact form', dsl(function () { + test ('has a contact form', dsl(function () { expect (elt ('#profile[action="."]').val ()).toBeDefined (); })); - it_checks_form_field ('id_name', 'text', 'Your name', true); - it_checks_form_field ('id_email', 'text', 'Your email address', true); - it_checks_form_field ('id_title', 'text', 'Subject of the message', true); - it_checks_form_field ('id_body', 'textarea', 'Body of the message', true); - it_checks_form_field ('id_copy', 'checkbox', 'Send me a copy of the email', false); + test_form_field ('id_name', 'text', 'Your name', true); + test_form_field ('id_email', 'text', 'Your email address', true); + test_form_field ('id_title', 'text', 'Subject of the message', true); + test_form_field ('id_body', 'textarea', 'Body of the message', true); + test_form_field ('id_copy', 'checkbox', 'Send me a copy of the email', false); - it ('should have some submit and cancel buttons', dsl(function () { + test ('has some submit and cancel buttons', dsl(function () { expect (elt ('#profile input[type=submit]').val ()).toBe ('Send'); expect (elt ('input#cancel_button[type=button]').val ()).toBe ('Cancel'); })); - it_checks_unlogged_footer (); + test_unlogged_footer (); + + // To avoid bugging in loading the 2nd page + test ('just get back to /', dsl(function () { + browser.navigateTo ('/'); + })); }); - describe ('reset password page', function () { - it_checks_page_loading ('/password_reset/', 'Reset my password'); - it_checks_unlogged_header (); + suite ('help page', function () { + test_page_loading ('/help/', 'Help'); + test_unlogged_header (); + test_unlogged_footer (); + }); - it ('should have a contact form', dsl(function () { + suite ('reset password page', function () { + test_page_loading ('/password_reset/', 'Reset my password'); + test_unlogged_header (); + + test ('has a contact form', dsl(function () { expect (elt ('#profile[action="."]').val ()).toBeDefined (); })); - it_checks_form_field ('id_email', 'text', 'E-mail', true); + test_form_field ('id_email', 'text', 'E-mail', true); - it ('should have a submit button', dsl(function () { + test ('has a submit button', dsl(function () { expect (elt ('#profile input[type=submit]').val ()).toBe ('Reset my password'); })); - it_checks_unlogged_footer (); + test_unlogged_footer (); }); - describe ('login page', function () { - it_checks_page_loading ('/', 'Home'); - it_checks_unlogged_header (); + suite ('login page', function () { + test_page_loading ('/', 'Home'); + test_unlogged_header (); - it ('should have a #login form', dsl(function () { + test ('has a #login form', dsl(function () { expect (elt ('#login[action="/login/"]').val ()).toBeDefined (); })); - it_checks_form_field ('id_username', 'text', 'Username', true); - it_checks_form_field ('id_password', 'password', 'Password', true); + test_form_field ('id_username', 'text', 'Username', true); + test_form_field ('id_password', 'password', 'Password', true); - it ('should have a login button and reset password links', dsl(function () { + test ('has a login button and reset password links', dsl(function () { expect (elt ('#login input[type=submit]').val ()).toBe ('Login'); expect (elt ('#login a[href="/password_reset/"]').text ()).toBe ('Forgot password?'); })); - it_checks_unlogged_footer (); + test_unlogged_footer (); - it ('should log an admin in', dsl(function () { - input ('#id_username').enter (admin_username); - input ('#id_password').enter (admin_password); + test ('logs an admin in', dsl(function () { + input ('#id_username').enter (w.USER_ADMIN); + input ('#id_password').enter (w.PASS_ADMIN); elt ('#login input[type=submit]').click (); + // Must be done here in this test() block browser.waitForPageLoad (); - // Must be done here in this 'it' block browser.navigateTo ('/'); expect (element ('title').text ()).toMatch (/Dashboard/m); })); }); - describe ('admin dashboard', function () { -// it_checks_page_loading ('/', 'Dashboard'); - it_checks_logged_header (admin_username); - it_checks_unlogged_footer (); + suite ('admin dashboard', function () { + // Should starts with : + test_page_loading ('/', 'Dashboard'); + // But its the last thing we did in the previous test + test_logged_header (w.USER_ADMIN); + test_unlogged_footer (); }); }); -function it_checks_page_loading (url, title) { - it ('should load', dsl(function () { +function test_page_loading (url, title) { + test ('loads', dsl(function () { // here we are in Karma page browser.navigateTo (url); expect (element ('title').text ()).toMatch (new RegExp (title,'m')); @@ -118,49 +120,57 @@ })); } -function it_checks_logged_header (username) { - it ('should have 6 links in #header_controls', dsl(function () { +function test_logged_header (username) { + test ('has 6 links in #header_controls', dsl(function () { expect (elt ('#header_controls a').count ()).toBe (6); })); - it ('should display current connected username', dsl(function () { + test ('displays current connected user name', dsl(function () { expect (elt ('#header_controls b').text ()).toBe (username); })); - it ('should have a Home link', dsl(function () { + test ('has links', dsl(function () { expect (elt ('#header_controls a:nth-of-type(1)[href="/"]').text ()).toBe ('Home'); + expect (elt ('#header_controls a:nth-of-type(2)[href="/create/content/"]').text ()).toBe ('Create a text'); + expect (elt ('#header_controls a:nth-of-type(3)[href="/create/upload/"]').text ()).toBe ('Upload a text'); + expect (elt ('#header_controls a:nth-of-type(4)[href="/create/import/"]').text ()).toBe ('Import a co-mented text'); + expect (elt ('#header_controls a:nth-of-type(5)[href="/profile/"]').text ()).toBe ('Profile'); + expect (elt ('#header_controls a:nth-of-type(6)[href="/logout/"]').text ()).toBe ('Logout'); })); -/* it ('should have a Login link', dsl(function () { - expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); - expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); - expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); - expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); - expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); - }));*/ } -function it_checks_unlogged_header () { - it ('should have 2 links', dsl(function () { +function test_unlogged_header () { + test ('has 2 links', dsl(function () { expect (elt ('#header_controls a').count ()).toBe (2); expect (elt ('#header_controls a[href="/"]').val ()).toBeDefined (); // to display the tested value : //elt ('#header_controls a[href="/"]').text ( function (txt) { console.log (txt); }); - // it returns defined ? "" : undefined; + // test returns defined ? "" : undefined; expect (elt ('#header_controls a[href="/"]').text ()).toBe ('Home'); expect (elt ('#header_controls a[href="/login/"]').text ()).toBe ('Login'); expect (elt ('#header_controls a[href="/xxx/"]').val ()).not ().toBeDefined (); })); } -function it_checks_unlogged_footer () { - it ('should have >= 9 links in #footer', dsl(function () { +function test_unlogged_footer (url) { + test ('has >= 9 links in #footer', dsl(function () { expect (elt ('#footer a').count ()).toBeGreaterThan (8); expect (elt ('#footer a[href="/contact/"]').text ()).toBe ('Contact'); expect (elt ('#footer #comentlink[href="http://www.co-ment.com"]').text ()).toMatch (/Powered by/m); expect (elt ('#footer a[href="/help/"]').text ()).toBe ('Help'); })); +/* test ('can change lang to french', dsl(function () { + element ('#footer a[href="/i18n/setlang/fr/"]').click (); +// browser.waitForPageLoad (); +// browser.navigateTo ('/'); + expect (elt ('#footer a[href="/help/"]').text ()).toBe ('Aide'); + element ('#footer a[href="/i18n/setlang/en/"]').click (); +// browser.waitForPageLoad (); +// browser.navigateTo ('/'); + }));*/ } -function it_checks_form_field (id, type, label, mandatory) { - it ('should have a '+label+' field', dsl(function () { +/* Test Django form field presence */ +function test_form_field (id, type, label, mandatory) { + test ('has a '+label+' field', dsl(function () { var s = type == 'textarea' ? 'textarea#'+id : 'input#'+id+'[type='+type+']'; expect (elt (s).val ()).toBeDefined (); expect (elt ('label[for='+id+']').text ()).toBe (label);