Skip to content

Commit

Permalink
feat: add formFiller cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Haller committed Jul 21, 2020
1 parent 84ec323 commit e278b5b
Show file tree
Hide file tree
Showing 12 changed files with 683 additions and 5 deletions.
12 changes: 11 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module.exports = {
node: true,
browser: true,
es2020: true,
'cypress/globals': true,
},
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['prettier', 'babel'],
plugins: ['prettier', 'babel', 'cypress'],
extends: [
'eslint:recommended',
'prettier',
Expand All @@ -18,9 +19,18 @@ module.exports = {
'plugin:import/warnings',
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:cypress/recommended',
],
rules: {
'prettier/prettier': 'error',
'babel/no-unused-expressions': 'error',
},
overrides: [
{
files: ['cypress/integration/*.spec.js'],
rules: {
'jest/expect-expect': 'off',
},
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
node_modules
npm-debug.log
cypress/screenshots
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ install:

script:
- npm run test
- npm run cypress:run

branches:
only:
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ publish-next: ## Publish on next tag

deploy-gh-pages: ## Deploy bookmaklet to gh-pages
npm run deploy-gh-pages

serve-cypress-demo: ## Serve cypress demo directory
npm run cypress:serve-demo

test-cypress: ## Run cypress tests
npm run cypress:run
4 changes: 4 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"defaultCommandTimeout": 10000,
"video": false
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
35 changes: 35 additions & 0 deletions cypress/integration/formFiller.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Chance from 'chance';
import { createHorde, species, strategies } from '../../src/index';

const seed = 'formFiller';

describe('Form filler', () => {
let horde;
beforeEach(() => {
return cy.visit('formFiller.html').then(() =>
cy.window().then((pageWindow) => {
horde = createHorde({
species: [species.formFiller()],
strategies: [strategies.bySpecies({ nb: 10 })],
window: pageWindow,
randomizer: new Chance(seed),
});
})
);
});
it('should fill text input with seeded value', () => {
return cy.wrap(horde.unleash()).then(() => {
cy.get('input[type="text"]').should('have.value', '7uv');
});
});
it('should fill number input with seeded value', () => {
return cy.wrap(horde.unleash()).then(() => {
cy.get('input[type="number"]').should('have.value', '693');
});
});
it('should fill email input with seeded value', () => {
return cy.wrap(horde.unleash()).then(() => {
cy.get('input[type="email"]').should('have.value', '[email protected]');
});
});
});
9 changes: 9 additions & 0 deletions cypress/pages/formFiller.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>

<html>
<body>
<input type="text" />
<input type="number" />
<input type="email" />
</body>
</html>
2 changes: 2 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Overwrite cy.visit to visit local html files
Cypress.Commands.overwrite('visit', (visit, path, options = {}) => visit(`./cypress/pages/${path}`, options));
1 change: 1 addition & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './commands';
Loading

0 comments on commit e278b5b

Please sign in to comment.