Skip to content

Commit 4c5ca81

Browse files
authored
Merge pull request #60 from ndouop/feature/front-end-testing-with-cypress
Feature/front end testing with cypress
2 parents 088a4dd + a1a1d63 commit 4c5ca81

File tree

9 files changed

+23047
-1460
lines changed

9 files changed

+23047
-1460
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ exit
148148
make consume
149149
```
150150

151+
## Cypress
152+
153+
We have added cypress for front-end testing, for now it is in webapp directory.
154+
It is recommended to remove it went deploy in production for security reasons:
155+
156+
### Open cypress for testing
157+
In the main directory
158+
```
159+
cd src/webapp
160+
./node_modules/.bin/cypress open
161+
```
162+
151163
## What's next?
152164

153165
### Configuring Git

src/webapp/cypress.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { defineConfig } = require("cypress");
2+
3+
module.exports = defineConfig({
4+
e2e: {
5+
setupNodeEvents(on, config) {
6+
// implement node event listeners here
7+
},
8+
baseUrl: 'http://symfony-boilerplate.localhost',
9+
},
10+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
describe('Create new user', () => {
2+
it('login as admin and create new user', () => {
3+
// go to login page
4+
cy.visit('/login')
5+
cy.get('#input-email').type('admin@admin.com')
6+
cy.get('#input-password').type('admin')
7+
cy.get('button[type=submit]').click()
8+
9+
// we should be redirected to /dashboard
10+
cy.url()
11+
.should('include', '/dashboard')
12+
.then(() => {
13+
// click on users menu
14+
cy.get('.pt-3 > .nav > :nth-child(6) > .nav-item > .nav-link')
15+
.should('have.attr', 'href', '/dashboard/admin/users')
16+
.click()
17+
.then(() => {
18+
// click on create button
19+
cy.get('.m-auto > .btn-primary')
20+
.should('have.attr', 'href', '/dashboard/admin/users/create')
21+
.click()
22+
23+
// field all required fields
24+
cy.get('#input-first-name').type('new-user')
25+
cy.get('#input-last-name').type('test')
26+
cy.get('#input-email').type('newuser@test.com')
27+
cy.get('#input-locale').select('FR')
28+
cy.get('#input-role').select('USER')
29+
cy.get('form > .btn')
30+
.click() // submit the form
31+
.then(() => {
32+
cy.url().should('match', /(\/dashboard\/admin\/users\/)/)
33+
})
34+
})
35+
})
36+
})
37+
})

src/webapp/cypress/e2e/login.cy.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe('login process', () => {
2+
3+
it('login as simple user', () => {
4+
// go to login page
5+
cy.visit('/login')
6+
cy.get('#input-email').type('user@user.com')
7+
cy.get('#input-password').type('user')
8+
cy.get('button[type=submit]').click()
9+
10+
// we should be redirected to /dashboard
11+
cy.url().should('include', '/dashboard')
12+
})
13+
14+
15+
it('login as admin', () => {
16+
// go to login page
17+
cy.visit('/login')
18+
cy.get('#input-email').type('admin@admin.com')
19+
cy.get('#input-password').type('admin')
20+
cy.get('button[type=submit]').click()
21+
22+
// we should be redirected to /dashboard
23+
cy.url().should('include', '/dashboard')
24+
})
25+
})

src/webapp/cypress/e2e/logout.cy.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('Log out process', () => {
2+
it('Log out', () => {
3+
// go to login page
4+
cy.visit('/login')
5+
cy.get('#input-email').type('admin@admin.com')
6+
cy.get('#input-password').type('admin')
7+
cy.get('button[type=submit]').click()
8+
9+
// we should be redirected to /dashboard
10+
cy.url()
11+
.should('include', '/dashboard')
12+
.then(() => {
13+
// dropdown user menu
14+
cy.get('li.nav-item.b-nav-dropdown a[role=button]')
15+
.first()
16+
.click()
17+
.then(() => {
18+
// click on log out button
19+
cy.get(':nth-child(2) > .dropdown-item').click()
20+
})
21+
})
22+
})
23+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
describe('Submit ', () => {
2+
it('login as simple user', () => {
3+
// go to login page
4+
cy.visit('/reset-password')
5+
cy.get('#input-email').type('user@user.com')
6+
cy.get('button[type=submit]').click()
7+
8+
// check form the message of email sent
9+
cy.get('h5').contains('user@user.com')
10+
cy.get('.card-body .text-center p').should('have.length', 2)
11+
})
12+
})

0 commit comments

Comments
 (0)