Skip to content

Commit

Permalink
Implement end-to-end testing with Cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
fabi1999 committed Jun 10, 2024
1 parent 2d95f2a commit 9fa2f44
Show file tree
Hide file tree
Showing 10 changed files with 793 additions and 22 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/cypressTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: End-to-end tests
on: push
jobs:
cypress-run:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cypress run
uses: cypress-io/github-action@v6
with:
browser: chrome
config: baseURL=https://${{ github.event.pull_request.number }}.development.scrumlr.fra.ics.inovex.io
7 changes: 7 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000'
},
});
57 changes: 57 additions & 0 deletions cypress/e2e/landingPageToBoard-spec.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/// <reference types="cypress" />
/// <reference path="../support/index.d.ts" />

import { columnTemplates } from "../../src/routes/NewBoard/columnTemplates"
import translationEn from "../../src/i18n/en/translation.json"

describe("When clicking the CTA on the homepage", () => {
it("it should navigate to the next page", () => {
// go to homepage
cy.visit("/")
// switch to english
cy.changeLanguageToEnglish()
cy.acceptCookies()

// click CTA
cy.get("a").contains(translationEn.Homepage.startButton).click()

// navigates to /login
cy.url().should("include", "/login")
cy.get("h1").contains(translationEn.LoginBoard.title)

// terms and conditions checkbox
cy.get("[type='checkbox']").should("not.be.checked")
cy.get("[type='checkbox']").check()

// click CTA
cy.get("button").contains(translationEn.LoginBoard.login).click()

// check templates
cy.get("h1").contains(translationEn.NewBoard.basicConfigurationTitle)
Object.values(columnTemplates).forEach(templateName => {
cy.contains(templateName.name)
})

cy.get("button")
.contains(translationEn.NewBoard.createNewBoard)
.parent()
.should("be.disabled")

// select template
cy.get("input[type='radio']").siblings().contains("Lean Coffee").click()

cy.get("button")
.contains(translationEn.NewBoard.createNewBoard)
.parent()
.should("not.be.disabled")

// click CTA
cy.get("button")
.contains(translationEn.NewBoard.createNewBoard)
.click()

// navigates to the board
cy.url().should("include", "/board/")
cy.get("h2").contains("Lean Coffee")
})
})
1 change: 1 addition & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
12 changes: 12 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />
/// <reference path="../support/index.d.ts" />

import translationEn from "../../src/i18n/en/translation.json"

Cypress.Commands.add("acceptCookies", () => {
cy.contains(translationEn.CookieNotice.accept).click()
});

Cypress.Commands.add("changeLanguageToEnglish", () => {
cy.get(`button[aria-label=${translationEn.Language.english}]`).click({ force: true })
});
17 changes: 17 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
15 changes: 15 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable {
/**
* Custom command to accept the cookies so the cookie banner is dismissed.
*/
acceptCookies(): Chainable<void>

/**
* Custom command to change the language to english.
*/
changeLanguageToEnglish(): Chainable<void>
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"cross-env": "^7.0.3",
"cypress": "^13.11.0",
"eslint": "^8.57.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"sourceMap": true,
"sourceMap": false,
"rootDir": "src",
"noImplicitReturns": true,
"noImplicitThis": true,
Expand All @@ -29,7 +29,8 @@
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"downlevelIteration": true
"downlevelIteration": true,
"ignoreDeprecations": "5.0"
},
"include": ["src"]
}
Loading

0 comments on commit 9fa2f44

Please sign in to comment.