Skip to content

Commit 7844895

Browse files
authored
Fix/data updates static updates (#52)
* Add react-editable-json-tree dep * Make graph data editable with react-editable-json-tree * Allow state to be passed into graph _tick function * Fix typo in utils docs * Improve utils isDeepEqual function * Add pick function to utils * Improve diff strategy to detect changes in input graph nodes & links * Remove restriction to perform updates on static graphs 🙉 * Improve change detection in graph config as well * Sandbox improvements. Fix some linting problems * Update graph.helper unit tests. Update linting rules for unit tests * Small Sandbox style improvement * Add functional tests * Update cypress to 2.0.1 🙏 * Set cypress videoRecording to false * Update yarn.lock * Use npm install in travis * Small tweaks in sandbox styling
1 parent dcb2d88 commit 7844895

File tree

19 files changed

+470
-174
lines changed

19 files changed

+470
-174
lines changed

.eslintrc.test.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ module.exports = {
2323
"jest/no-focused-tests": "error",
2424
"jest/no-identical-title": "error",
2525
"jest/valid-expect": "error",
26-
"max-len": ["error", 180, 4, { "ignoreComments": true }]
26+
"max-len": ["error", 180, 4, { "ignoreComments": true }],
27+
"max-lines": ["error", {"max": 800, "skipComments": true}],
2728
},
2829
"env": {
2930
"jest/globals": true

.gitignore

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

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: node_js
22
node_js:
33
- "8.9.0"
44
install:
5-
- yarn install
5+
- npm install
66
before_script:
77
- npm start -- --silent &
88
script:

cypress.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"videoRecording": false
3+
}

cypress/common/page-objects/node.po.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*global cy*/
2+
13
/**
24
* Page Object for interacting with Node component.
35
* @param {string} id the id of the node.
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1+
/*global cy*/
2+
13
/**
24
* Page Object for interacting with sandbox interface.
35
* @returns {undefined}
46
*/
57
function SandboxPO () {
68
// whitelist checkbox inputs
7-
this.checkboxes = [ 'node.renderLabel' ];
8-
9+
this.checkboxes = ['node.renderLabel', 'staticGraph'];
10+
911
// actions
1012
this.playGraph = () => cy.get('.container__graph > :nth-child(1) > :nth-child(2)').click();
1113
this.pauseGraph = () => cy.get('.container__graph > :nth-child(1) > :nth-child(3)').click();
14+
this.addNode = () => cy.get('.container__graph > :nth-child(1) > :nth-child(5)').click();
15+
this.removeNode = () => cy.get('.container__graph > :nth-child(1) > :nth-child(6)').click();
16+
this.clickJsonTreeNodes = () => {
17+
cy.get('.container__graph-data').contains('root').scrollIntoView();
18+
cy.get('.container__graph-data').contains('nodes').click();
19+
};
20+
// must be collapsed
21+
this.clickJsonTreeFirstNode = () => cy.get(':nth-child(2) > .rejt-not-collapsed > .rejt-not-collapsed-list > :nth-child(1) > .rejt-collapsed > .rejt-collapsed-text').click();
22+
this.addJsonTreeFirstNodeProp = () => cy.get(':nth-child(2) > :nth-child(1) > .rejt-not-collapsed > :nth-child(4) > .rejt-plus-menu').click();
23+
this.deleteJsonTreeFirstNodeProp = () => cy.get('.rejt-not-collapsed-list > :nth-child(2) > .rejt-minus-menu').click();
1224

1325
// element getters
1426
this.getFieldInput = (field) => this.checkboxes.includes(field)
1527
? cy.contains(field).children('input')
1628
: cy.contains(field).siblings('.form-control');
29+
this.getGraphNumbers = () => cy.get('.container__graph-info');
1730
}
1831

1932
module.exports = SandboxPO;

cypress/integration/graph.e2e.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*global cy*/
2+
const SANDBOX_URL = Cypress.env('SANDBOX_URL');
3+
4+
const NodePO = require('../common/page-objects/node.po');
5+
const SandboxPO = require('../common/page-objects/sandbox.po');
6+
let nodes = require('./../../sandbox/data').nodes.map(({id}) => id);
7+
8+
describe('[rd3g-graph] graph tests', function () {
9+
before(function () {
10+
this.sandboxPO = new SandboxPO();
11+
// visit sandbox
12+
cy.visit(SANDBOX_URL);
13+
// sleep 2 seconds
14+
cy.wait(2000);
15+
// pause the graph
16+
this.sandboxPO.pauseGraph();
17+
});
18+
19+
describe('when data is changed', function () {
20+
describe('and we change nodes props', function () {
21+
beforeEach(function () {
22+
// expand nodes
23+
this.sandboxPO.clickJsonTreeNodes();
24+
// expand 1st node
25+
this.sandboxPO.clickJsonTreeFirstNode();
26+
});
27+
28+
afterEach(function () {
29+
this.sandboxPO.clickJsonTreeNodes();
30+
});
31+
32+
it('nodes props modifications should be reflected in the graph', function () {
33+
// click (+) add prop to 1st node
34+
this.sandboxPO.addJsonTreeFirstNodeProp();
35+
36+
// prop name be color
37+
cy.get('[placeholder="Key"]')
38+
.clear()
39+
.type('color');
40+
41+
// prop value be red and press ENTER
42+
cy.get('[placeholder="Value"]')
43+
.clear()
44+
.type('red{enter}');
45+
46+
const nodePO = new NodePO(nodes[0]);
47+
48+
nodePO.getColor().should('eq', 'red');
49+
50+
// delete created prop
51+
this.sandboxPO.deleteJsonTreeFirstNodeProp();
52+
53+
nodePO.getColor().should('eq', '#d3d3d3');
54+
});
55+
56+
describe('and staticGraph is toggled on', function () {
57+
beforeEach(function () {
58+
cy.contains('staticGraph').scrollIntoView();
59+
this.sandboxPO.getFieldInput('staticGraph').click();
60+
});
61+
62+
it('nodes props modifications should be reflected in the graph', function () {
63+
cy.get('text').should('have.length', 14);
64+
65+
this.sandboxPO.addNode();
66+
this.sandboxPO.addNode();
67+
this.sandboxPO.addNode();
68+
this.sandboxPO.addNode();
69+
70+
cy.get('text').should('have.length', 18);
71+
72+
// click (+) add prop to 1st node
73+
this.sandboxPO.addJsonTreeFirstNodeProp();
74+
// prop name be color
75+
cy.get('[placeholder="Key"]')
76+
.clear()
77+
.type('color');
78+
// prop value be red and press ENTER
79+
cy.get('[placeholder="Value"]')
80+
.clear()
81+
.type('red{enter}');
82+
83+
const nodePO = new NodePO(nodes[0]);
84+
85+
nodePO.getColor().should('eq', 'red');
86+
87+
// delete created prop
88+
this.sandboxPO.deleteJsonTreeFirstNodeProp();
89+
90+
nodePO.getColor().should('eq', '#d3d3d3');
91+
92+
this.sandboxPO.removeNode();
93+
94+
cy.get('text').should('have.length', 17);
95+
96+
this.sandboxPO.removeNode();
97+
this.sandboxPO.removeNode();
98+
this.sandboxPO.removeNode();
99+
100+
cy.get('text').should('have.length', 14);
101+
});
102+
});
103+
});
104+
});
105+
});

cypress/integration/node.e2e.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/*global cy*/
2+
const SANDBOX_URL = Cypress.env('SANDBOX_URL');
3+
14
const NodePO = require('../common/page-objects/node.po');
25
const SandboxPO = require('../common/page-objects/sandbox.po');
3-
const SANDBOX_URL = Cypress.env('SANDBOX_URL');
46
let nodes = require('./../../sandbox/data').nodes.map(({id}) => id);
57

68
describe('[rd3g-node] node tests', function () {

package-lock.json

Lines changed: 31 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"babel-preset-react": "6.24.1",
4646
"babel-preset-stage-0": "6.24.1",
4747
"css-loader": "0.28.7",
48-
"cypress": "1.4.1",
48+
"cypress": "2.0.1",
4949
"documentation": "5.3.2",
5050
"eslint": "3.18.0",
5151
"eslint-config-recommended": "1.5.0",
@@ -59,6 +59,7 @@
5959
"npm-run-all": "4.1.1",
6060
"react-addons-test-utils": "15.6.0",
6161
"react-dom": "15.6.1",
62+
"react-editable-json-tree": "2.1.0",
6263
"react-jsonschema-form": "0.50.1",
6364
"react-router-dom": "4.2.2",
6465
"react-test-renderer": "15.6.1",

0 commit comments

Comments
 (0)