Skip to content

Commit

Permalink
Merge pull request #23 from GermaVinsmoke/tests
Browse files Browse the repository at this point in the history
Cypress E2E tests
  • Loading branch information
GermaVinsmoke committed Oct 30, 2019
2 parents 21b7d6d + 4307b16 commit 42bd2bd
Show file tree
Hide file tree
Showing 9 changed files with 1,090 additions and 17 deletions.
3 changes: 3 additions & 0 deletions cypress.json
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:3000/"
}
6 changes: 6 additions & 0 deletions cypress/.eslintrc.json
@@ -0,0 +1,6 @@
{
"plugins": ["cypress"],
"env": {
"cypress/globals": true
}
}
41 changes: 41 additions & 0 deletions cypress/integration/BmiForm.spec.js
@@ -0,0 +1,41 @@
describe('BmiForm Component', () => {
beforeEach(() => {
cy.visit('/');
});

it('accepts input', () => {
const weight = '50';
const height = '176';

cy.get('#weight')
.type(weight)
.should('have.value', weight);
cy.get('#height')
.type(height)
.should('have.value', height);
});

context('Form submission', () => {
it('Adds a new bmi card data', () => {
let weight = '50';
const height = '176';
let today = new Date().toLocaleString().split(',')[0];

cy.get('#weight')
.type(weight)
.should('have.value', weight);
cy.get('#height')
.type(height)
.should('have.value', height);

cy.get('#bmi-btn').click();
cy.get('#weight').should('have.value', '');
cy.get('#height').should('have.value', '');

cy.get("[data-test='weight']").should('contain', weight);
cy.get("[data-test='height']").should('contain', height);
cy.get("[data-test='bmi']").should('contain', '16.14');
cy.get("[data-test='date']").should('contain', today);
});
});
});
17 changes: 17 additions & 0 deletions cypress/plugins/index.js
@@ -0,0 +1,17 @@
// ***********************************************************
// 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)

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')

0 comments on commit 42bd2bd

Please sign in to comment.