Skip to content

Commit

Permalink
Add visual tests (#60)
Browse files Browse the repository at this point in the history
Add visual tests
  • Loading branch information
pierpo authored Oct 6, 2019
2 parents 8709513 + 2396d4a commit 4842b6a
Show file tree
Hide file tree
Showing 14 changed files with 658 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ lib
index.html
coverage
example-dist
__diff_output__
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"video": false,
"watchForFileChanges": false,
"baseUrl": "http://localhost:8080"
}
1 change: 1 addition & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
37 changes: 37 additions & 0 deletions cypress/integration/archer/main.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
context('React Archer', () => {
beforeEach(() => {
cy.visit('/');
cy.contains('Root');
});

describe('First example page', () => {
beforeEach(() => {
cy.contains('Example 1').click();
});

it('should draw arrows', () => {
cy.matchImageSnapshot();
});
});

describe('Second example page', () => {
beforeEach(() => {
cy.contains('Example 2').click();
cy.contains('Change labels').click();
});

it('should draw arrows', () => {
cy.matchImageSnapshot();
});

it('should update labels', () => {
cy.get('[data-cy="change-labels-input"]').type('blabla some test');
cy.matchImageSnapshot();
});

it('should update number of elements', () => {
cy.get('[data-cy="add-element"]').click();
cy.matchImageSnapshot();
});
});
});
20 changes: 20 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// 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)

const {
addMatchImageSnapshotPlugin,
} = require('cypress-image-snapshot/plugin');

module.exports = (on, config) => {
addMatchImageSnapshotPlugin(on, config);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ***********************************************
// 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 is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';

addMatchImageSnapshotCommand();
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 2 additions & 0 deletions example/SecondExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SecondExample extends React.Component {
<div>
<div>Change labels</div>
<input
data-cy="change-labels-input"
type="text"
onChange={event => {
this.setState({ labels: event.currentTarget.value });
Expand All @@ -28,6 +29,7 @@ class SecondExample extends React.Component {
<div>
<div>Add elements</div>
<button
data-cy="add-element"
onClick={() =>
this.setState({ nbElements: this.state.nbElements + 1 })
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"pretest": "yarn lint && yarn flow",
"prepare": "npm run build",
"lint": "eslint --ext .js,.jsx src/",
"test:e2e": "cypress open",
"test:e2e:update-snapshots": "rm -rf ./cypress/snapshots",
"test:watch": "jest ./src/ --watch",
"test": "jest --coverage ./src/"
},
Expand All @@ -45,6 +47,8 @@
"babel-loader": "8.0.4",
"cross-env": "5.1.3",
"css-loader": "3.2.0",
"cypress": "3.4.1",
"cypress-image-snapshot": "3.1.1",
"enzyme": "3.7.0",
"enzyme-adapter-react-16": "1.6.0",
"eslint": "6.2.1",
Expand Down
Loading

0 comments on commit 4842b6a

Please sign in to comment.