Skip to content

Feature/front end testing with cypress #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ exit
make consume
```

## Cypress

We have added cypress for front-end testing, for now it is in webapp directory.
It is recommended to remove it went deploy in production for security reasons:

### Open cypress for testing
In the main directory
```
cd src/webapp
./node_modules/.bin/cypress open
```

## What's next?

### Configuring Git
Expand Down
10 changes: 10 additions & 0 deletions src/webapp/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
baseUrl: 'http://symfony-boilerplate.localhost',
},
});
37 changes: 37 additions & 0 deletions src/webapp/cypress/e2e/createUser.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
describe('Create new user', () => {
it('login as admin and create new user', () => {
// go to login page
cy.visit('/login')
cy.get('#input-email').type('admin@admin.com')
cy.get('#input-password').type('admin')
cy.get('button[type=submit]').click()

// we should be redirected to /dashboard
cy.url()
.should('include', '/dashboard')
.then(() => {
// click on users menu
cy.get('.pt-3 > .nav > :nth-child(6) > .nav-item > .nav-link')
.should('have.attr', 'href', '/dashboard/admin/users')
.click()
.then(() => {
// click on create button
cy.get('.m-auto > .btn-primary')
.should('have.attr', 'href', '/dashboard/admin/users/create')
.click()

// field all required fields
cy.get('#input-first-name').type('new-user')
cy.get('#input-last-name').type('test')
cy.get('#input-email').type('newuser@test.com')
cy.get('#input-locale').select('FR')
cy.get('#input-role').select('USER')
cy.get('form > .btn')
.click() // submit the form
.then(() => {
cy.url().should('match', /(\/dashboard\/admin\/users\/)/)
})
})
})
})
})
25 changes: 25 additions & 0 deletions src/webapp/cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe('login process', () => {

it('login as simple user', () => {
// go to login page
cy.visit('/login')
cy.get('#input-email').type('user@user.com')
cy.get('#input-password').type('user')
cy.get('button[type=submit]').click()

// we should be redirected to /dashboard
cy.url().should('include', '/dashboard')
})


it('login as admin', () => {
// go to login page
cy.visit('/login')
cy.get('#input-email').type('admin@admin.com')
cy.get('#input-password').type('admin')
cy.get('button[type=submit]').click()

// we should be redirected to /dashboard
cy.url().should('include', '/dashboard')
})
})
23 changes: 23 additions & 0 deletions src/webapp/cypress/e2e/logout.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('Log out process', () => {
it('Log out', () => {
// go to login page
cy.visit('/login')
cy.get('#input-email').type('admin@admin.com')
cy.get('#input-password').type('admin')
cy.get('button[type=submit]').click()

// we should be redirected to /dashboard
cy.url()
.should('include', '/dashboard')
.then(() => {
// dropdown user menu
cy.get('li.nav-item.b-nav-dropdown a[role=button]')
.first()
.click()
.then(() => {
// click on log out button
cy.get(':nth-child(2) > .dropdown-item').click()
})
})
})
})
12 changes: 12 additions & 0 deletions src/webapp/cypress/e2e/passwordReset.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe('Submit ', () => {
it('login as simple user', () => {
// go to login page
cy.visit('/reset-password')
cy.get('#input-email').type('user@user.com')
cy.get('button[type=submit]').click()

// check form the message of email sent
cy.get('h5').contains('user@user.com')
cy.get('.card-body .text-center p').should('have.length', 2)
})
})
Loading