|
1 | | -'use strict'; |
2 | | - |
3 | | -var config = browser.params;<% if (filters.mongooseModels) { %> |
4 | | -var UserModel = require(config.serverConfig.root + '/server/api/user/user.model').default;<% } %><% if (filters.sequelizeModels) { %> |
5 | | -var UserModel = require(config.serverConfig.root + '/server/sqldb').User;<% } %> |
| 1 | +const config = browser.params;<% if (filters.mongooseModels) { %> |
| 2 | +import UserModel from '../../../server/api/user/user.model';<% } %><% if (filters.sequelizeModels) { %> |
| 3 | +import {User as UserModel} from '../../../server/sqldb';<% } %> |
| 4 | +import {LoginPage} from './login.po'; |
| 5 | +import {NavbarComponent} from '../../components/navbar/navbar.po'; |
6 | 6 |
|
7 | 7 | describe('Login View', function() { |
8 | | - var page; |
9 | | - |
10 | | - var loadPage = function() { |
11 | | - let promise = browser.get(config.baseUrl + '/login'); |
12 | | - page = require('./login.po'); |
13 | | - return promise; |
14 | | - }; |
15 | | - |
16 | | - var testUser = { |
17 | | - name: 'Test User', |
18 | | - email: 'test@example.com', |
19 | | - password: 'test' |
20 | | - }; |
21 | | - |
22 | | - before(function() { |
23 | | - return UserModel |
24 | | - <% if (filters.mongooseModels) { %>.remove()<% } |
25 | | - if (filters.sequelizeModels) { %>.destroy({ where: {} })<% } %> |
26 | | - .then(function() { |
27 | | - <% if (filters.mongooseModels) { %>return UserModel.create(testUser);<% } |
28 | | - if (filters.sequelizeModels) { %>return UserModel.create(testUser);<% } %> |
29 | | - }) |
30 | | - .then(loadPage); |
31 | | - }); |
32 | | - |
33 | | - after(function() { |
34 | | - <% if (filters.mongooseModels) { %>return UserModel.remove();<% } |
35 | | - if (filters.sequelizeModels) { %>return UserModel.destroy({ where: {} });<% } %> |
36 | | - }); |
37 | | - |
38 | | - it('should include login form with correct inputs and submit button', function() { |
39 | | - <%= expect() %>page.form.email.getAttribute('type')<%= to() %>.eventually.equal('email'); |
40 | | - <%= expect() %>page.form.email.getAttribute('name')<%= to() %>.eventually.equal('email'); |
41 | | - <%= expect() %>page.form.password.getAttribute('type')<%= to() %>.eventually.equal('password'); |
42 | | - <%= expect() %>page.form.password.getAttribute('name')<%= to() %>.eventually.equal('password'); |
43 | | - <%= expect() %>page.form.submit.getAttribute('type')<%= to() %>.eventually.equal('submit'); |
44 | | - <%= expect() %>page.form.submit.getText()<%= to() %>.eventually.equal('Login'); |
45 | | - });<% if (filters.oauth) { %> |
46 | | - |
47 | | - it('should include oauth buttons with correct classes applied', function() {<% if (filters.facebookAuth) { %> |
48 | | - <%= expect() %>page.form.oauthButtons.facebook.getText()<%= to() %>.eventually.equal('Connect with Facebook'); |
49 | | - <%= expect() %>page.form.oauthButtons.facebook.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } if (filters.googleAuth) { %> |
50 | | - <%= expect() %>page.form.oauthButtons.google.getText()<%= to() %>.eventually.equal('Connect with Google+'); |
51 | | - <%= expect() %>page.form.oauthButtons.google.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } if (filters.twitterAuth) { %> |
52 | | - <%= expect() %>page.form.oauthButtons.twitter.getText()<%= to() %>.eventually.equal('Connect with Twitter'); |
53 | | - <%= expect() %>page.form.oauthButtons.twitter.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } %> |
54 | | - });<% } %> |
55 | | - |
56 | | - describe('with local auth', function() { |
57 | | - |
58 | | - it('should login a user and redirecting to "/"', function() { |
59 | | - return page.login(testUser).then(() => { |
60 | | - var navbar = require('../../components/navbar/navbar.po'); |
61 | | - |
62 | | - return browser.wait( |
63 | | - () => element(by.css('.hero-unit')), |
64 | | - 5000, |
65 | | - `Didn't find .hero-unit after 5s` |
66 | | - ).then(() => { |
67 | | - <%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/'); |
68 | | - <%= expect() %>navbar.navbarAccountGreeting.getText()<%= to() %>.eventually.equal('Hello ' + testUser.name); |
| 8 | + let page; |
| 9 | + |
| 10 | + const loadPage = () => { |
| 11 | + return browser.get(`${config.baseUrl}/login`).then(() => { |
| 12 | + page = new LoginPage(); |
69 | 13 | }); |
70 | | - }); |
| 14 | + }; |
| 15 | + |
| 16 | + const testUser = { |
| 17 | + name: 'Test User', |
| 18 | + email: 'test@example.com', |
| 19 | + password: 'test' |
| 20 | + }; |
| 21 | + |
| 22 | + before(async function() { |
| 23 | + await UserModel |
| 24 | + <% if (filters.mongooseModels) { %>.remove();<% } |
| 25 | + if (filters.sequelizeModels) { %>.destroy({ where: {} });<% } %> |
| 26 | + |
| 27 | + await UserModel.create(testUser); |
| 28 | + |
| 29 | + await loadPage(); |
71 | 30 | }); |
72 | 31 |
|
73 | | - describe('and invalid credentials', function() { |
74 | | - before(function() { |
75 | | - return loadPage(); |
76 | | - }) |
| 32 | + after(function() { |
| 33 | + <% if (filters.mongooseModels) { %>return UserModel.remove();<% } |
| 34 | + if (filters.sequelizeModels) { %>return UserModel.destroy({ where: {} });<% } %> |
| 35 | + }); |
77 | 36 |
|
78 | | - it('should indicate login failures', function() { |
79 | | - page.login({ |
80 | | - email: testUser.email, |
81 | | - password: 'badPassword' |
| 37 | + it('should include login form with correct inputs and submit button', function() { |
| 38 | + <%= expect() %>page.form.email.getAttribute('type')<%= to() %>.eventually.equal('email'); |
| 39 | + <%= expect() %>page.form.email.getAttribute('name')<%= to() %>.eventually.equal('email'); |
| 40 | + <%= expect() %>page.form.password.getAttribute('type')<%= to() %>.eventually.equal('password'); |
| 41 | + <%= expect() %>page.form.password.getAttribute('name')<%= to() %>.eventually.equal('password'); |
| 42 | + <%= expect() %>page.form.submit.getAttribute('type')<%= to() %>.eventually.equal('submit'); |
| 43 | + <%= expect() %>page.form.submit.getText()<%= to() %>.eventually.equal('Login'); |
| 44 | + });<% if (filters.oauth) { %> |
| 45 | + |
| 46 | + it('should include oauth buttons with correct classes applied', function() {<% if (filters.facebookAuth) { %> |
| 47 | + <%= expect() %>page.form.oauthButtons.facebook.getText()<%= to() %>.eventually.equal('Connect with Facebook');<% } if (filters.googleAuth) { %> |
| 48 | + <%= expect() %>page.form.oauthButtons.google.getText()<%= to() %>.eventually.equal('Connect with Google+');<% } if (filters.twitterAuth) { %> |
| 49 | + <%= expect() %>page.form.oauthButtons.twitter.getText()<%= to() %>.eventually.equal('Connect with Twitter');<% } %> |
| 50 | + });<% } %> |
| 51 | + |
| 52 | + describe('with local auth', function() { |
| 53 | + it('should login a user and redirect to "/home"', async function() { |
| 54 | + await page.login(testUser); |
| 55 | + |
| 56 | + let navbar = new NavbarComponent(); |
| 57 | + |
| 58 | + browser.ignoreSynchronization = false; |
| 59 | + await browser.wait(() => browser.getCurrentUrl(), 5000, 'URL didn\'t change after 5s'); |
| 60 | + browser.ignoreSynchronization = true; |
| 61 | + |
| 62 | + <%= expect() %>(await browser.getCurrentUrl())<%= to() %>.equal(`${config.baseUrl}/home`); |
| 63 | + <%= expect() %>(await navbar.navbarAccountGreeting.getText())<%= to() %>.equal(`Hello ${testUser.name}`); |
82 | 64 | }); |
83 | 65 |
|
84 | | - <%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/login'); |
| 66 | + describe('and invalid credentials', function() { |
| 67 | + before(() => loadPage()); |
85 | 68 |
|
86 | | - var helpBlock = page.form.element(by.css('.form-group.has-error .help-block.ng-binding')); |
87 | | - <%= expect() %>helpBlock.getText()<%= to() %>.eventually.equal('This password is not correct.'); |
88 | | - }); |
| 69 | + it('should indicate login failures', async function() { |
| 70 | + await page.login({ |
| 71 | + email: testUser.email, |
| 72 | + password: 'badPassword' |
| 73 | + }); |
89 | 74 |
|
90 | | - }); |
| 75 | + <%= expect() %>(await browser.getCurrentUrl())<%= to() %>.equal(`${config.baseUrl}/login`); |
| 76 | + |
| 77 | + let helpBlock = page.form.element(by.css('.form-group.has-error .help-block:not([hidden])')); |
91 | 78 |
|
92 | | - }); |
| 79 | + browser.ignoreSynchronization = false; |
| 80 | + await browser.wait(() => helpBlock.getText(), 5000, 'Couldn\'t find help text after 5s'); |
| 81 | + browser.ignoreSynchronization = true; |
| 82 | + |
| 83 | + <%= expect() %>(await helpBlock.getText())<%= to() %>.equal('This password is not correct.'); |
| 84 | + }); |
| 85 | + }); |
| 86 | + }); |
93 | 87 | }); |
0 commit comments