Skip to content

Commit

Permalink
SankeyDiagram SankeyNodeLabel unit test for rendering arbitrary SVG l…
Browse files Browse the repository at this point in the history
…abels
  • Loading branch information
Dan Delany committed Mar 12, 2018
1 parent 9f77123 commit 2e12b41
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/jsdom/spec/SankeyDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ describe("SankeyDiagram", () => {
id: "lemons",
name: "Sour Lemons"
};
it("renders a node label", () => {
it("renders a node label in a <text> element", () => {
const label = mount(<SankeyNodeLabel {...{node: basicNodeObj, nodeLabelText: () => "ok"}} />);
const text = label.find("text");
expect(text).to.have.length(1);
Expand Down Expand Up @@ -643,6 +643,20 @@ describe("SankeyDiagram", () => {
expect(textWithId).to.have.length(1);
expect(textWithId.text()).to.equal("lemons");
});
it("renders nodeLabelText as-is (not wrapped in <text>), if it returns an element instead of string", () => {
const label = mount(
<SankeyNodeLabel
{...{
node: basicNodeObj,
nodeLabelText: node => <rect x={node.x0} y={node.y0} width={50} height={20} />
}}
/>
);
expect(label.find("text")).to.have.length(0);
expect(label.find("rect")).to.have.length(1);
expect(label.find("rect").props().width).to.equal(50);
});

it("passes nodeLabelClassName and nodeLabelStyle through to the text element", () => {
const nodeLabelClassName = "my-fun-node-label";
const nodeLabelStyle = {fill: "salmon"};
Expand Down

0 comments on commit 2e12b41

Please sign in to comment.