Skip to content

Commit d62d105

Browse files
authored
Feature/e2e testing (#50)
* Setup cypress. Add simple sample test * Setup cy env var to use as target in functional tests * Add and config cypress webpack-preprocessor * Add node and sandbox page objects * Add node spec * Remove simple_spec * Read node ids from sandbox data * Add favicon to sandbox * Add start script to serve sandbox with npm http-server * Update yarn.lock * Update travis.yml to include functional tests run in CI pipeline * Rename node.spec.js to node.e2e.js * Rename functional:run task to functional * Update .npmignore
1 parent e49e000 commit d62d105

File tree

16 files changed

+1835
-221
lines changed

16 files changed

+1835
-221
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ gen-docs
7272
.DS_Store
7373
**/.DS_Store
7474
.vscode
75+
cypress/videos/

.npmignore

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
.babelrc
2-
.DS_Store
3-
.eslintrc.js
41
.git
52
.gitignore
6-
.travis.yml
3+
.github
4+
.vscode
75
coverage
6+
cypress
87
docs
98
gen-docs
10-
package.json
119
sandbox
12-
src
1310
test
11+
.babelrc
12+
.editorconfig
13+
.eslintrc.js
14+
.eslintrc.test.config.js
15+
.travis.yml
16+
cypress.json
17+
package-lock.json
18+
RELEASE_PROCESS
1419
webpack.config.dist.js
1520
webpack.config.js
1621
yarn.lock
22+
.DS_Store

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ node_js:
33
- "8.9.0"
44
install:
55
- yarn install
6+
before_script:
7+
- npm start -- --silent &
68
script:
79
- npm run lint
810
- npm run test
911
- npm run dist:sandbox
12+
- npm run functional

cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Page Object for interacting with Node component.
3+
* @param {string} id the id of the node.
4+
* @returns {undefined}
5+
*/
6+
function NodePO (id) {
7+
this.id = id;
8+
this.path = `#${this.id} > path`;
9+
this.text = `#${this.id} > text`;
10+
11+
this.getPath = () => cy.get(this.path);
12+
this.getLabel = () => cy.get(this.text);
13+
this.getColor = () => cy.get(this.path).invoke('attr', 'fill');
14+
this.getFontSize = () => cy.get(this.text).invoke('attr', 'font-size');
15+
}
16+
17+
module.exports = NodePO;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Page Object for interacting with sandbox interface.
3+
* @returns {undefined}
4+
*/
5+
function SandboxPO () {
6+
// whitelist checkbox inputs
7+
this.checkboxes = [ 'node.renderLabel' ];
8+
9+
// actions
10+
this.playGraph = () => cy.get('.container__graph > :nth-child(1) > :nth-child(2)').click();
11+
this.pauseGraph = () => cy.get('.container__graph > :nth-child(1) > :nth-child(3)').click();
12+
13+
// element getters
14+
this.getFieldInput = (field) => this.checkboxes.includes(field)
15+
? cy.contains(field).children('input')
16+
: cy.contains(field).siblings('.form-control');
17+
}
18+
19+
module.exports = SandboxPO;

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": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/integration/node.e2e.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const NodePO = require('../common/page-objects/node.po');
2+
const SandboxPO = require('../common/page-objects/sandbox.po');
3+
const SANDBOX_URL = Cypress.env('SANDBOX_URL');
4+
let nodes = require('./../../sandbox/data').nodes.map(({id}) => id);
5+
6+
describe('[rd3g-node] node tests', function () {
7+
before(function () {
8+
this.sandboxPO = new SandboxPO();
9+
// visit sandbox
10+
cy.visit(SANDBOX_URL);
11+
// sleep 2 seconds
12+
cy.wait(2000);
13+
// pause the graph
14+
this.sandboxPO.pauseGraph();
15+
16+
// @TODO: Could add this to a global scope
17+
// NOTE: https://github.com/cypress-io/cypress/issues/300
18+
// cy.window().then((win) => {
19+
// cy.spy(win.console, 'log')
20+
// });
21+
});
22+
23+
describe('when setting specific node color', function () {
24+
beforeEach(function () {
25+
// scroll down to node.color config
26+
cy.contains('node.color').scrollIntoView();
27+
// input text 'green'
28+
this.sandboxPO.getFieldInput('node.color')
29+
.clear()
30+
.type('green');
31+
});
32+
33+
it('all nodes should have the selected color', function () {
34+
nodes.forEach(function (n) {
35+
const nodePO = new NodePO(n);
36+
37+
// below alternative using async/await
38+
// expect(await nodePO.getColor()).to.eq('green');
39+
nodePO.getColor().should('eq', 'green');
40+
});
41+
});
42+
});
43+
44+
describe('when setting specific node label fontSize', function () {
45+
beforeEach(function () {
46+
// scroll down to node.fontSize config
47+
cy.contains('node.fontSize').scrollIntoView();
48+
// input text '14'
49+
this.sandboxPO.getFieldInput('node.fontSize')
50+
.clear()
51+
.type('14');
52+
});
53+
54+
it('all nodes labels should have the selected fontSize', function () {
55+
nodes.forEach(function (n) {
56+
const nodePO = new NodePO(n);
57+
58+
nodePO.getFontSize().should('eq', '14');
59+
});
60+
});
61+
});
62+
63+
describe('when toggling off render label', function () {
64+
beforeEach(function () {
65+
// scroll down to node.renderLabel config & click
66+
cy.contains('node.renderLabel').scrollIntoView();
67+
this.sandboxPO.getFieldInput('node.renderLabel').click();
68+
});
69+
70+
it('all node labels should disappear', function () {
71+
nodes.forEach(n => {
72+
const nodePO = new NodePO(n);
73+
74+
nodePO.getLabel().should('not.be.visible');
75+
});
76+
});
77+
});
78+
});

cypress/plugins/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ***********************************************************
2+
// This example plugins/index.js can be used to load plugins
3+
//
4+
// You can change the location of this file or turn off loading
5+
// the plugins file with the 'pluginsFile' configuration option.
6+
//
7+
// You can read more here:
8+
// https://on.cypress.io/plugins-guide
9+
// ***********************************************************
10+
11+
// This function is called when a project is opened or re-opened (e.g. due to
12+
// the project's config changing)
13+
const webpack = require('@cypress/webpack-preprocessor');
14+
15+
module.exports = (on, config) => {
16+
// `on` is used to hook into various events Cypress emits
17+
// `config` is the resolved Cypress config
18+
const options = webpack.defaultOptions;
19+
options.entry = ['babel-polifyll'];
20+
options.webpackOptions.module.rules[0].test = '/\.spec.js$/';
21+
22+
on('file:preprocessor', webpack(options));
23+
}

cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This is will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

0 commit comments

Comments
 (0)