1
0

loginSpec.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @copyright 2018 Julius Härtl <jus@bitgrid.net>
  3. *
  4. * @author 2018 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. const helper = require('../helper.js');
  23. const config = require('../config.js');
  24. describe('login', function () {
  25. before(async () => await helper.init(this));
  26. after(async () => await helper.exit());
  27. /**
  28. * Test login page rendering
  29. */
  30. config.resolutions.forEach(function (resolution) {
  31. it('login-page.' + resolution.title, async function () {
  32. return helper.takeAndCompare(this, '/', async (page) => {
  33. // make sure the cursor is not blinking in the login field
  34. await page.$eval('body', function (e) {
  35. $('#user').blur();
  36. });
  37. return await helper.delay(100);
  38. }, {viewport: resolution});
  39. });
  40. it('login-page.forgot.' + resolution.title, async function () {
  41. return helper.takeAndCompare(this, undefined, async (page) => {
  42. const lostPassword = await page.$('#lost-password');
  43. await lostPassword.click();
  44. await helper.delay(500);
  45. await page.$eval('body', function (e) {
  46. $('#user').blur();
  47. });
  48. }, {viewport: resolution});
  49. });
  50. });
  51. /**
  52. * Perform login
  53. */
  54. config.resolutions.forEach(function (resolution) {
  55. it('login-success.' + resolution.title, async function () {
  56. this.timeout(30000);
  57. await helper.resetBrowser();
  58. return helper.takeAndCompare(this, '/', async function (page) {
  59. await page.waitForSelector('input#user');
  60. await page.type('#user', 'admin');
  61. await page.type('#password', 'admin');
  62. const inputElement = await page.$('input[type=submit]');
  63. await inputElement.click();
  64. await page.waitForNavigation({waitUntil: 'networkidle2'});
  65. await page.waitForSelector('#header');
  66. await page.$eval('body', function (e) {
  67. // force relative timestamp to fixed value, since it breaks screenshot diffing
  68. $('.live-relative-timestamp').removeClass('live-relative-timestamp').text('5 minutes ago');
  69. });
  70. return await helper.delay(100);
  71. }, {viewport: resolution});
  72. })
  73. });
  74. });