Skip to content

Commit

Permalink
Add e2e tests with cypress (#51)
Browse files Browse the repository at this point in the history
* refactor: layout of testimonials (#47)

* chore: Added Danny too testimonials (#48)

* Install cypress (#49)

* chore: installed cypress

* test: initial install for example tests

* adding Cypress

* delete Cypress example tests

* adding first tests

* removing "only" filter in test spec

* Update README.md

* eslint Cypress plugin added

* cleanup via eslint

* Removing package-lock.json and .gitignore update

Co-authored-by: Benjamin Lo <wolfnun011@gmail.com>
  • Loading branch information
TheLaw1337 and benji011 committed Oct 6, 2021
1 parent c066e61 commit 5e20aa0
Show file tree
Hide file tree
Showing 17 changed files with 15,056 additions and 37,594 deletions.
14 changes: 13 additions & 1 deletion .eslintrc
@@ -1,5 +1,8 @@
{
"extends": ["wesbos"],
"plugins": [
"cypress"
],
"extends": ["wesbos", "plugin:cypress/recommended"],
"rules": {
"no-console": 2,
"import/no-unresolved": 0,
Expand All @@ -13,6 +16,15 @@
"printWidth": 120,
"tabWidth": 2
}
],
"spaced-comment": [
"error",
"always",
{
"line": {
"markers": ["/"]
}
}
]
},
"settings": {
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Expand Up @@ -70,4 +70,8 @@ yarn-error.log
# Yarn Integrity file
.yarn-integrity

.now
.now

# Cypress
cypress/videos
cypress/screenshots
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -11,7 +11,7 @@ My personal portfolio website forked from [Gatsby-theme-portfolio](https://githu
## TODO

- ~fix i18n internationalization. See branch [wip/portfolio-ben-i18n](https://github.com/benji011/portfolio.benjaminlo.io/tree/wip/portfolio-ben-i18n) for more details~
- E2E tests
- ~E2E tests~
- fix hamburger icon colour
- ~fix ESLint~
- refactor some weird looking code
Expand Down Expand Up @@ -53,4 +53,4 @@ i18n
├── skills
│   └── skills.json
└── translation.json
```
```
3 changes: 3 additions & 0 deletions cypress.json
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:8000"
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
24 changes: 24 additions & 0 deletions cypress/integration/e2e.spec.js
@@ -0,0 +1,24 @@
/// <reference types="cypress" />

describe('E2E tests', () => {
beforeEach(() => {
cy.visit('/');
});
it('checks if link to repository is opening in a new tab', () => {
cy.get('.GlEmu > a:nth-of-type(1)').should('have.attr', 'target', '_blank');
});
it('checks if the contact form is visible after "Contact me" click', () => {
cy.get('.Intro___StyledButton-bAANjW').click();
cy.get('#contact').should('be.visible');
});
it('checks if form validation works during typing', () => {
cy.get(':nth-child(1) > .Input-eXLwAq').type('J{backspace}').blur();
cy.get(':nth-child(1) > .styles__Error-MrfTy').should('be.visible').and('have.text', 'Full name field is required');

cy.get(':nth-child(2) > .Input-eXLwAq').type('qwerty').blur();
cy.get(':nth-child(2) > .styles__Error-MrfTy').should('be.visible').and('have.text', 'Invalid email');

cy.get(':nth-child(3) > .Input-eXLwAq').type('D{backspace}').blur();
cy.get(':nth-child(3) > .styles__Error-MrfTy').should('be.visible').and('have.text', 'Message field is required');
});
});
22 changes: 22 additions & 0 deletions cypress/plugins/index.js
@@ -0,0 +1,22 @@
// / <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
25 changes: 25 additions & 0 deletions cypress/support/commands.js
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js 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';

// Alternatively you can use CommonJS syntax:
// require('./commands')
6 changes: 2 additions & 4 deletions i18n/testimonials/testimonials.json
@@ -1,10 +1,8 @@
{
"en": {
"title": "Trusted by",
"read more": "Read more"
"title": "Trusted by"
},
"ja": {
"title": "お客様の声",
"read more": "続きを読む"
"title": "お客様の声"
}
}

0 comments on commit 5e20aa0

Please sign in to comment.