Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 8bcec63

Browse files
authored
Merge pull request #275 from CoderDojo/login-cypress-tests
Auth e2e cypress journeys Dojo anniversary display logic fix
2 parents a941809 + 62edd83 commit 8bcec63

File tree

19 files changed

+603
-366
lines changed

19 files changed

+603
-366
lines changed

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ module.exports = {
1212
globals: {
1313
google: true,
1414
},
15-
extends: 'airbnb-base',
15+
extends: [
16+
'airbnb-base',
17+
"plugin:cypress/recommended"
18+
],
1619
// required to lint *.vue files
1720
plugins: [
1821
'html'

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ To run the tests
2727
docker-compose run --rm cypress
2828
```
2929

30+
### E2E Tests
31+
The tests in the `/cypress/integration_e2e` folder that are not run as part of the main test in CI.
32+
33+
They are designed to be run manually & locally with the full stack, no endpoints are stubbed.
34+
35+
> NOTE: the register test includes a 5 second pause where you are required to click the recaptcha.
36+
37+
```
38+
yarn cypress:e2e:open
39+
```
40+
3041
## wdio tests
3142
The selenium-based wdio tests are legacy tests, waiting to be migrated to cypress. They are not actively maintained and are there only for reference until migrated.
3243
To run the tests

cypress-e2e.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrationFolder": "cypress/integration_e2e",
3+
"baseUrl": "http://localhost:8000",
4+
"video": false
5+
}

cypress/fixtures/loginFail.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ok":false,
3+
"why":"invalid-password"
4+
}

cypress/fixtures/loginSuccess.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ok": true,
3+
"why": "password",
4+
"user": {},
5+
"login": {}
6+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import page from '../../pages/login';
2+
3+
const setupLoggedInServer = () => {
4+
cy.server();
5+
cy.route('POST', '/api/2.0/users/login', 'fx:loginSuccess').as('login');
6+
cy.route('/api/2.0/users/instance', 'fx:parentLoggedIn').as('instance');
7+
cy.route('POST', '/api/2.0/dojos/users', 'fx:userDojosChampion').as('userDojosChampion');
8+
};
9+
10+
describe('Login Page', () => {
11+
describe('Form Validation', () => {
12+
beforeEach(() => {
13+
cy.visit('/login');
14+
});
15+
16+
it('should show the header, login box, and all login box elements', () => {
17+
cy.get(page.header).should('be.visible');
18+
cy.get(page.loginBox).should('be.visible');
19+
cy.get(page.email).should('be.visible');
20+
cy.get(page.password).should('be.visible');
21+
cy.get(page.login).should('be.visible');
22+
cy.get(page.forgotPassword).should('be.visible');
23+
cy.get(page.register).should('be.visible');
24+
cy.get(page.forgotPasswordLink).should('have.attr', 'href', '/reset');
25+
cy.get(page.registerLink).should('have.attr', 'href', '/register');
26+
});
27+
28+
it('should show an error when no email is provided on a blur event', () => {
29+
cy.get(page.emailFormatError).should('not.be.visible'); // TODO: Should be emailReqError?
30+
cy.get(page.email).click();
31+
cy.get(page.email).invoke('text').should('eq', '');
32+
cy.get(page.password).click();
33+
cy.get(page.emailFormatError).should('be.visible');
34+
});
35+
36+
it('should show an error when no password is provided on a blur event', () => {
37+
cy.get(page.passwordReqError).should('not.be.visible');
38+
cy.get(page.password).click();
39+
cy.get(page.password).invoke('text').should('eq', '');
40+
cy.get(page.loginBox).click();
41+
cy.get(page.passwordReqError).should('be.visible');
42+
});
43+
44+
it('should show an error when the email input is not in the correct format', () => {
45+
cy.get(page.emailFormatError).should('not.be.visible');
46+
cy.get(page.email).click();
47+
cy.get(page.email).type('janedoe');
48+
cy.get(page.password).click();
49+
cy.get(page.emailFormatError).should('be.visible');
50+
});
51+
52+
it('should show an error when the login fails (on mock server this is only when the incorrect email is provided)', () => {
53+
cy.server();
54+
cy.route('POST', '/api/2.0/users/login', 'fx:loginFail').as('loginFail');
55+
cy.get(page.loginFailed).should('not.be.visible');
56+
cy.get(page.email).click();
57+
cy.get(page.email).type('[email protected]');
58+
cy.get(page.password).type('wrongpassword');
59+
cy.get(page.login).click();
60+
cy.wait('@loginFail');
61+
cy.get(page.loginFailed).should('be.visible');
62+
});
63+
64+
it('should show both requirement errors when a login is attempted if no email and no password is provided', () => {
65+
cy.get(page.emailFormatError).should('not.be.visible'); // TODO: Should be emailReqError?
66+
cy.get(page.passwordReqError).should('not.be.visible');
67+
cy.get(page.login).click();
68+
cy.get(page.emailFormatError).should('be.visible');
69+
cy.get(page.passwordReqError).should('be.visible');
70+
});
71+
72+
it('should show only the email format error when a login is attempted if no password and incorrect form of email is provided', () => {
73+
cy.get(page.emailFormatError).should('not.be.visible');
74+
cy.get(page.email).type('janedoe');
75+
cy.get(page.login).click();
76+
cy.get(page.emailFormatError).should('be.visible');
77+
});
78+
79+
it('should show password requirement error when a login is attempted if no password but an email is provided', () => {
80+
cy.get(page.passwordReqError).should('not.be.visible');
81+
cy.get(page.email).type('[email protected]');
82+
cy.get(page.login).click();
83+
cy.get(page.passwordReqError).should('be.visible');
84+
});
85+
86+
it('should show email requirement error when a login is attempted if no email but a password is provided', () => {
87+
cy.get(page.emailFormatError).should('not.be.visible'); // TODO: Should be emailReqError?
88+
cy.get(page.password).type('test123');
89+
cy.get(page.login).click();
90+
cy.get(page.emailFormatError).should('be.visible');
91+
});
92+
});
93+
94+
describe('Successful Login', () => {
95+
it('should login successfully without a referrer query param', () => {
96+
cy.visit('/login');
97+
setupLoggedInServer();
98+
cy.get(page.email).type('[email protected]');
99+
cy.get(page.password).type('testparent1');
100+
cy.get(page.login).click();
101+
cy.url().should('include', '/home');
102+
});
103+
104+
it('should login successfully with a referrer query param', () => {
105+
cy.visit('/login?referrer=%2Fdashboard%2Ftickets');
106+
setupLoggedInServer();
107+
cy.get(page.email).type('[email protected]');
108+
cy.get(page.password).type('testparent1');
109+
cy.get(page.login).click();
110+
cy.url().should('include', '/dashboard/tickets');
111+
});
112+
});
113+
});

cypress/integration/dashboard/communications_spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import moment from 'moment';
2-
import eventPage from '../../pages/events';
32
import homePage from '../../pages/home';
43

54
describe('Homepage comms', () => {

cypress/integration/dashboard/news_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Dashboard news', () => {
1313
cy.wait('@blogArticles');
1414
cy.get(homePage.newsTitle).invoke('text').should('eq', 'News');
1515
});
16-
16+
1717
it('should display the latest 6 news', () => {
1818
cy.visit('/home');
1919
cy.wait('@loggedIn');
@@ -26,7 +26,7 @@ describe('Dashboard news', () => {
2626
cy.wait('@loggedIn');
2727
cy.wait('@blogArticles');
2828
cy.get(homePage.newsEntries).first()
29-
.within((el) => {
29+
.within(() => {
3030
cy.get(homePage.newsEntryTitle).invoke('text').should('eq', 'What we discussed on the July Open Community Call');
3131
cy.get(homePage.newsEntryDate).invoke('text').should('eq', '09/08/2018');
3232
// cy.get(homePage.newsEntryCategory).invoke('text').should('eq', 'News');
@@ -37,7 +37,7 @@ describe('Dashboard news', () => {
3737
cy.wait('@loggedIn');
3838
cy.wait('@blogArticles');
3939
cy.get(homePage.newsEntries).last()
40-
.within((el) => {
40+
.within(() => {
4141
cy.get(homePage.newsEntryDate).invoke('text').should('eq', '17/07/2018');
4242
});
4343
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import page from '../../pages/login';
2+
import homePage from '../../pages/home';
3+
4+
describe('Login & out Smoke', () => {
5+
describe('Successful Login & out', () => {
6+
it('should login successfully without a referrer query param', () => {
7+
cy.visit('/login');
8+
cy.get(page.email).type('[email protected]');
9+
cy.get(page.password).type('test');
10+
cy.get(page.login).click();
11+
12+
cy.url().should('include', '/home');
13+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
14+
});
15+
16+
it('should login successfully with a referrer query param', () => {
17+
cy.visit('/login?referrer=%2Fdashboard%2Ftickets');
18+
cy.get(page.email).type('[email protected]');
19+
cy.get(page.password).type('test');
20+
cy.get(page.login).click();
21+
22+
cy.url().should('include', '/dashboard/tickets');
23+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
24+
});
25+
26+
it('should logout successfully', () => {
27+
cy.visit('/login');
28+
cy.get(page.email).type('[email protected]');
29+
cy.get(page.password).type('test');
30+
cy.get(page.login).click();
31+
32+
cy.url().should('include', '/home');
33+
cy.get(homePage.menuUserName).first().click();
34+
cy.get(homePage.menuLogout).first().click();
35+
36+
cy.get(homePage.menuUserName).should('not.be.visible');
37+
});
38+
});
39+
});
40+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import userPage from '../../pages/register-user';
2+
import profilePage from '../../pages/register-profile';
3+
import loginPage from '../../pages/login';
4+
import homePage from '../../pages/home';
5+
6+
const uniqueEmail = `smoke_${String(Math.random()).slice(2)}@test.com`;
7+
const password = 't3stt3st';
8+
9+
describe('Register, login & out Smoke', () => {
10+
it('should register', () => {
11+
cy.visit('/register/user');
12+
13+
cy.get(userPage.firstName).type('Namey');
14+
cy.get(userPage.surname).type('McNameFace');
15+
cy.get(userPage.emailAddress).type(uniqueEmail);
16+
cy.get(userPage.password).type(password);
17+
cy.get(userPage.passConfirmField).type(password);
18+
cy.get(userPage.termsConditionsAccepted).check();
19+
cy.get(userPage.submit).click();
20+
cy.url().should('include', '/register/profile');
21+
22+
cy.get(profilePage.dobCalendarBtn).click();
23+
cy.get(profilePage.yearButton).first().click();
24+
cy.get(profilePage.monthButton).first().click();
25+
cy.get(profilePage.dayButton).first().click();
26+
cy.get(profilePage.countrySelectOpen).click();
27+
cy.get(profilePage.countryInput).type('united kingdom');
28+
cy.get(profilePage.countryOption).first().click();
29+
cy.wait(5000); // Click the recaptcha!
30+
cy.get(profilePage.submit).click();
31+
32+
cy.url().should('include', '/home');
33+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
34+
});
35+
it('should logout', () => {
36+
cy.get(homePage.menuUserName).first().click();
37+
cy.get(homePage.menuLogout).first().click();
38+
39+
cy.get(homePage.menuUserName).should('not.be.visible');
40+
});
41+
it('should login', () => {
42+
cy.visit('/login');
43+
cy.get(loginPage.email).type(uniqueEmail);
44+
cy.get(loginPage.password).type(password);
45+
cy.get(loginPage.login).click();
46+
47+
cy.url().should('include', '/home');
48+
cy.get(homePage.menuUserName).first().invoke('text').should('eq', 'Namey McNameFace');
49+
});
50+
});
51+

0 commit comments

Comments
 (0)