Skip to content

Commit

Permalink
make SankeyNode/SankeyLink private, use rewire to access private comp…
Browse files Browse the repository at this point in the history
…onents in unit tests
  • Loading branch information
Dan Delany committed Dec 5, 2017
1 parent 409875e commit f5abedb
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 41 deletions.
279 changes: 244 additions & 35 deletions docs/src/docs/SankeyDiagram/propDocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,11 @@
"type": {
"name": "arrayOf",
"value": {
"name": "shape",
"value": {
"id": {
"name": "union",
"value": [
{
"name": "string"
},
{
"name": "number"
}
],
"required": false
},
"value": {
"name": "number",
"required": false
},
"step": {
"name": "number",
"required": false
}
}
"name": "object"
}
},
"required": false,
"description": "Array of node objects, represented by vertical lines.\nThese represent the base entities which links flow into & out of.\nEach should have a numerical value and (optionally) a unique identifier.\nIf no identifier is included, the node index will be used."
"required": true,
"description": "Array of node objects, represented by vertical rectangles.\nThese represent the base entities which links flow into & out of."
},
"links": {
"type": {
Expand Down Expand Up @@ -71,23 +49,93 @@
}
}
},
"required": false,
"required": true,
"description": "Array of link objects, represented by curved paths between nodes.\nLinks represent a magnitude of flow between one node and another.\nEach should have a 'source' node [identifier], a 'target' node [identifier],\nand a numerical value representing flow magnitude."
},
"width": {
"type": {
"name": "number"
},
"required": true,
"description": "Width of the SVG element.",
"defaultValue": {
"value": "400",
"computed": false
}
},
"height": {
"type": {
"name": "number"
},
"required": true,
"description": "Height of the SVG element.",
"defaultValue": {
"value": "300",
"computed": false
}
},
"className": {
"type": {
"name": "string"
},
"required": false,
"description": "`className` attribute to be applied to the SVG element.",
"defaultValue": {
"value": "''",
"computed": false
}
},
"style": {
"type": {
"name": "object"
},
"required": false,
"description": "Inline style object to be applied to the SVG element.",
"defaultValue": {
"value": "{}",
"computed": false
}
},
"nodeId": {
"type": {
"name": "func"
},
"required": false,
"description": "Accessor function `nodeId(node, nodeIndex)` which specifies how to access the ID of each node object.\nThese should be the same identifiers used by `links[].source` and `.target`.\nUses the node's index in `nodes` array by default.",
"defaultValue": {
"value": "node => node.index",
"computed": false
}
},
"nodeLabelText": {
"type": {
"name": "func"
},
"required": false,
"description": "",
"defaultValue": {
"value": "node => node.name",
"computed": false
}
},
"showNodes": {
"type": {
"name": "union",
"value": [
{
"name": "string"
"name": "bool"
},
{
"name": "func"
}
]
},
"required": false,
"description": ""
"description": "Boolean which determines if node rectangles should be shown,\nor function (`showNode(node, nodeIndex)`) which returns a boolean",
"defaultValue": {
"value": "true",
"computed": false
}
},
"nodeWidth": {
"type": {
Expand Down Expand Up @@ -153,7 +201,7 @@
]
},
"required": false,
"description": "Class attribute to be applied to each node,\nor accessor function which returns a class (string).",
"description": "`className` attribute to be applied to each node,\nor accessor function which returns a class (string).",
"defaultValue": {
"value": "''",
"computed": false
Expand All @@ -178,23 +226,184 @@
"computed": false
}
},
"width": {
"showLinks": {
"type": {
"name": "union",
"value": [
{
"name": "bool"
},
{
"name": "func"
}
]
},
"required": false,
"description": "Boolean which determines if link paths should be shown,\nor function (`showLink(link, linkIndex)`) which returns a boolean",
"defaultValue": {
"value": "400",
"value": "true",
"computed": false
}
},
"height": {
"linkClassName": {
"type": {
"name": "union",
"value": [
{
"name": "string"
},
{
"name": "func"
}
]
},
"required": false,
"description": "Class attribute to be applied to each link,\nor accessor function which returns a class (string).",
"defaultValue": {
"value": "300",
"value": "''",
"computed": false
}
},
"getNodeId": {
"linkStyle": {
"type": {
"name": "union",
"value": [
{
"name": "object"
},
{
"name": "func"
}
]
},
"required": false,
"description": "Inline style object to be applied to each link,\nor accessor function which returns a style object.",
"defaultValue": {
"value": "{}",
"computed": false
}
},
"showNodeLabels": {
"type": {
"name": "union",
"value": [
{
"name": "bool"
},
{
"name": "func"
}
]
},
"required": false,
"description": "Boolean which determines if node labels should be shown,\nor function (`showLink(link, linkIndex)`) which returns a boolean",
"defaultValue": {
"value": "true",
"computed": false
}
},
"showLinkLabels": {
"type": {
"name": "union",
"value": [
{
"name": "bool"
},
{
"name": "func"
}
]
},
"required": false,
"description": "Boolean which determines if node labels should be shown,\nor function (`showLink(link, linkIndex)`) which returns a boolean",
"defaultValue": {
"value": "'id'",
"value": "true",
"computed": false
}
},
"onMouseEnterNode": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseLeaveNode": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseMoveNode": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseDownNode": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseUpNode": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onClickNode": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseEnterLink": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseLeaveLink": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseMoveLink": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseDownLink": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onMouseUpLink": {
"type": {
"name": "func"
},
"required": false,
"description": ""
},
"onClickLink": {
"type": {
"name": "func"
},
"required": false,
"description": ""
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"react-router-dom": "^4.1.2",
"remark": "^8.0.0",
"remark-react": "^4.0.1",
"rewire": "^3.0.2",
"shelljs": "^0.7.8",
"sinon": "^4.1.2",
"sinon-chai": "^2.14.0",
Expand Down
4 changes: 2 additions & 2 deletions src/SankeyDiagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const nodeAlignmentsByName = {
};


export const SankeyNode = (props) => {
const SankeyNode = (props) => {
const {graph, node, nodeIndex, nodeClassName, nodeStyle,
onMouseEnterNode, onMouseLeaveNode, onMouseMoveNode, onMouseDownNode, onMouseUpNode, onClickNode
} = props;
Expand All @@ -41,7 +41,7 @@ export const SankeyNode = (props) => {
/>;
};

export const SankeyLink = (props) => {
const SankeyLink = (props) => {
const {
graph, link, linkIndex, linkPath, linkClassName, linkStyle,
onMouseEnterLink, onMouseLeaveLink, onMouseMoveLink, onMouseDownLink, onMouseUpLink, onClickLink
Expand Down
9 changes: 6 additions & 3 deletions tests/jsdom/spec/SankeyDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import sinonChai from 'sinon-chai';
chai.use(sinonChai);
const {expect} = chai;

import {SankeyDiagram} from '../../../src/index.js';
import {SankeyNode, SankeyLink} from '../../../src/SankeyDiagram';

// use rewire to test internal SankeyNode/Link/etc. components
const rewire = require('rewire');
const Sankey = rewire('../../../src/SankeyDiagram');
const SankeyDiagram = Sankey.default;
const SankeyNode = Sankey.__get__('SankeyNode');
const SankeyLink = Sankey.__get__('SankeyLink');

describe('SankeyDiagram', () => {
it('renders a Sankey Diagram', () => {
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ babel-plugin-transform-es2015-block-scoped-functions@^6.22.0:
dependencies:
babel-runtime "^6.22.0"

babel-plugin-transform-es2015-block-scoping@^6.24.1:
babel-plugin-transform-es2015-block-scoping@^6.24.1, babel-plugin-transform-es2015-block-scoping@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f"
dependencies:
Expand Down Expand Up @@ -5726,6 +5726,13 @@ resolve@^1.1.6:
dependencies:
path-parse "^1.0.5"

rewire@^3.0.2:
version "3.0.2"
resolved "http://artifactory.spotify.net/artifactory/api/npm/virtual-npm/rewire/-/rewire-3.0.2.tgz#25e5413c4f1676eb3247d1884198b3a265408bbd"
dependencies:
babel-core "^6.26.0"
babel-plugin-transform-es2015-block-scoping "^6.26.0"

right-align@^0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef"
Expand Down

0 comments on commit f5abedb

Please sign in to comment.