Skip to content

Commit 6250101

Browse files
committed
feat(e2e-tests): configured cypress for e2e tests
Added cypress library. Added example tests. Installed dependencies: ``` yarn add cypress start-server-and-test @testing-library/cypress --dev ```
1 parent 73cecf9 commit 6250101

File tree

19 files changed

+815
-33
lines changed

19 files changed

+815
-33
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ TODO.md
1313

1414
# testing
1515
/coverage
16+
/cypress/videos
17+
/cypress/screenshots
1618

1719
# production
1820
/build

cypress.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"baseUrl": "http://localhost:3000",
3+
"env": {
4+
"HELLO_FROM_ENV_FILE": "Hello from Cypress Env file!!!"
5+
}
6+
}

cypress/.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
root: true,
3+
plugins: ['eslint-plugin-cypress'],
4+
parser: '@typescript-eslint/parser',
5+
env: { 'cypress/globals': true },
6+
};

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe('About Page', () => {
2+
it('should open about page when user clicks about navigation item', () => {
3+
cy.visit('/')
4+
5+
cy.findByRole('link', { name: /about/i }).click()
6+
7+
cy.findByRole('heading', { name: /about page/i }).should('exist')
8+
})
9+
10+
it('should display title when user use direct path (/about)', () => {
11+
cy.visit('/about')
12+
cy.findByRole('heading', { name: /about page/i }).should('exist')
13+
})
14+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('Env', () => {
2+
it('should inject custom env from cypress.json file', () => {
3+
expect(Cypress.env('HELLO_FROM_ENV_FILE')).to.equal('Hello from Cypress Env file!!!')
4+
})
5+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
describe('i18n', () => {
2+
it('should translate site to Polish', () => {
3+
cy.visit('/')
4+
5+
cy.findByRole('button', { name: /🇵🇱/i }).click()
6+
7+
cy.findByRole('heading', { name: /nazwa firmy/i }).should('exist')
8+
})
9+
10+
it('should translate site to English', () => {
11+
cy.visit('/')
12+
13+
cy.findByRole('button', { name: /🇵🇱/i }).click()
14+
15+
cy.findByRole('heading', { name: /nazwa firmy/i }).should('exist')
16+
17+
cy.findByRole('button', { name: /🇺🇸/i }).click()
18+
19+
cy.findByRole('heading', { name: /company name/i }).should('exist')
20+
})
21+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
describe('Feature - Posts', () => {
2+
it('should add new post', () => {
3+
cy.visit('/')
4+
5+
cy.findByRole('textbox', { name: /title/i }).type('Hello from Cypress!')
6+
cy.findByRole('textbox', { name: /body/i }).type('This is our first Cypress test😊')
7+
8+
cy.findByRole('button', { name: /add new post/i }).click()
9+
10+
cy.findByRole('heading', { name: /hello from cypress!/i }).should('exist')
11+
})
12+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('i18n - feature', () => {
2+
it('should change theme to dark mode', () => {
3+
cy.visit('/')
4+
5+
cy.get('body').should('have.css', 'background-color', 'rgb(255, 255, 255)')
6+
7+
cy.findByTestId('Brightness4Icon').click()
8+
9+
cy.get('body').should('have.css', 'background-color', 'rgb(18, 18, 18)')
10+
})
11+
12+
it('should change back theme to light mode', () => {
13+
cy.visit('/')
14+
15+
cy.findByTestId('Brightness4Icon').click()
16+
17+
cy.get('body').should('have.css', 'background-color', 'rgb(18, 18, 18)')
18+
19+
cy.findByTestId('Brightness7Icon').click()
20+
21+
cy.get('body').should('have.css', 'background-color', 'rgb(255, 255, 255)')
22+
})
23+
})

cypress/plugins/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.ts can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}

0 commit comments

Comments
 (0)