Skip to content

Commit

Permalink
Create e2e tests with cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
leolpc21 committed Jul 8, 2024
1 parent 20810c2 commit b454616
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/cy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: ci

on:
push:
branches:
- main
pull_request:

jobs:
eslint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install modules
run: npm install
- name: Run ESLint
run: npm run lint
cypress-tests-desktop:
needs: eslint
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run end-to-end tests on desktop viewport 🧪
uses: cypress-io/github-action@v5
env:
CYPRESS_USER_EMAIL: ${{ secrets.CYPRESS_USER_EMAIL }}
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
CYPRESS_MAILOSAUR_SERVER_ID: ${{ secrets.CYPRESS_MAILOSAUR_SERVER_ID }}
CYPRESS_MAILOSAUR_API_KEY: ${{ secrets.CYPRESS_MAILOSAUR_API_KEY }}
with:
command: npm test
cypress-tests-tablet:
needs: eslint
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run end-to-end tests on tablet viewport 🧪
uses: cypress-io/github-action@v5
env:
CYPRESS_USER_EMAIL: ${{ secrets.CYPRESS_USER_EMAIL }}
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }}
with:
command: npm run test:tablet
3 changes: 3 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = defineConfig({
defaultCommandTimeout : 10000,
requestTimeout: 10000,
chromeWebSecurity: false,
env: {
viewportWidthBreakpoint: 768,
},
setupNodeEvents(on, config) {
// implement node event listeners here
},
Expand Down
17 changes: 17 additions & 0 deletions cypress/e2e/authenticated.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ describe('Scenarios where authentication is a pre-condition', () => {
.its('state')
.should('be.equal', 'Complete')
})

it('logs out', () => {
cy.visit('/')
cy.wait('@getNotes')

if (Cypress.config('viewportWidth') < Cypress.env('viewportWidthBreakpoint')) {
cy.get('.navbar-toggle.collapsed')
.should('be.visible')
.click()
}

cy.contains('.nav a', 'Logout').click()

cy.get('#email')
.should('be.visible')
.should('be.empty')
})
})
1 change: 0 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
///<reference types="cypress-iframe" />

const attachFileHandler = () => {
cy.get('#file').selectFile('cypress/fixtures/example.json')
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"main": "cypress.config.js",
"scripts": {
"lint": "eslint cypress/**/*.js && eslint cypress.config.js",
"lint:fix": "eslint cypress/**/*.js --fix && eslint cypress.config.js --fix"
"lint:fix": "eslint cypress/**/*.js --fix && eslint cypress.config.js --fix",
"cy:open": "cypress open",
"cy:open:tablet": "cypress open --config viewportWidth=767,viewportHeight=480",
"test": "cypress run",
"test:tablet": "cypress run --config viewportWidth=767,viewportHeight=480 --spec cypress/e2e/authenticated.cy.js"
},
"keywords": [],
"author": "Leonardo Costa",
Expand All @@ -18,4 +22,4 @@
"eslint": "^8.43.0",
"eslint-plugin-cypress": "^2.13.3"
}
}
}

0 comments on commit b454616

Please sign in to comment.