Skip to content

Commit 8a215f9

Browse files
committed
Update tests for style props
1 parent ec88dfa commit 8a215f9

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

src/Link/tests/index.test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { shallow, mount } from 'enzyme';
33

44
import Link from '../index';
55

6+
// TODO Find a way to meaningfully test `componentWillLeave`
67
describe('<Link />', () => {
78
const linkData = {
89
source: {
@@ -41,6 +42,20 @@ describe('<Link />', () => {
4142
});
4243

4344

45+
it('applies `props.styles` when defined', () => {
46+
const initialStyle = { opacity: 0 }; // state.initialStyle
47+
const fixture = { ...initialStyle, stroke: '#777', strokeWidth: 2 };
48+
const renderedComponent = shallow(
49+
<Link
50+
{...mockProps}
51+
styles={fixture}
52+
/>
53+
);
54+
55+
expect(renderedComponent.prop('style')).toEqual(fixture);
56+
});
57+
58+
4459
it('calls the appropriate path func based on `props.pathFunc`', () => {
4560
const diagonalComponent = shallow(
4661
<Link {...mockProps} />
@@ -75,6 +90,4 @@ describe('<Link />', () => {
7590

7691
expect(renderedComponent.instance().applyOpacity).toHaveBeenCalledWith(fixture);
7792
});
78-
79-
// TODO Find a way to meaningfully test `componentWillLeave`
8093
});

src/Node/tests/index.test.js

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,84 @@ describe('<Node />', () => {
4242

4343

4444
it('applies correct base className if `nodeData._children` is defined', () => {
45-
const noChildrenComponent = shallow(
45+
const leafNodeComponent = shallow(
4646
<Node {...mockProps} />
4747
);
48-
const withChildrenComponent = shallow(
48+
const nodeComponent = shallow(
4949
<Node
5050
{...mockProps}
5151
nodeData={{ ...nodeData, _children: [] }}
5252
/>
5353
);
5454

55-
expect(noChildrenComponent.prop('className')).toBe('leafNodeBase');
56-
expect(withChildrenComponent.prop('className')).toBe('nodeBase');
55+
expect(leafNodeComponent.prop('className')).toBe('leafNodeBase');
56+
expect(nodeComponent.prop('className')).toBe('nodeBase');
5757
});
5858

5959

60-
it('applies correct <circle> style prop if `nodeData._children` is defined', () => {
60+
it('applies correct node styles depending on `nodeData._children`', () => {
61+
const initialStyle = { opacity: 0 }; // state.initialStyle
62+
const fixture = {
63+
node: { ...initialStyle, fill: 'blue' },
64+
leafNode: { ...initialStyle, fill: 'green' },
65+
};
66+
const leafNodeComponent = shallow(
67+
<Node
68+
{...mockProps}
69+
styles={fixture}
70+
/>
71+
);
72+
const nodeComponent = shallow(
73+
<Node
74+
{...mockProps}
75+
nodeData={{ ...nodeData, _children: [] }}
76+
styles={fixture}
77+
/>
78+
);
79+
80+
expect(leafNodeComponent.prop('style')).toEqual(fixture.leafNode);
81+
expect(nodeComponent.prop('style')).toEqual(fixture.node);
82+
});
83+
84+
85+
it('applies correct <circle> styles depending on `nodeData._children`', () => {
6186
const leafCircle = { fill: 'blue' };
6287
const circle = { fill: 'green' };
6388
const styles = { circle, leafCircle };
64-
const noChildrenComponent = shallow(
89+
const leafNodeComponent = shallow(
6590
<Node
6691
{...mockProps}
6792
styles={styles}
6893
/>
6994
);
70-
const withChildrenComponent = shallow(
95+
const nodeComponent = shallow(
7196
<Node
7297
{...mockProps}
7398
nodeData={{ ...nodeData, _children: [] }}
7499
styles={styles}
75100
/>
76101
);
77102

78-
expect(noChildrenComponent.find('circle').prop('style')).toBe(leafCircle);
79-
expect(withChildrenComponent.find('circle').prop('style')).toBe(circle);
103+
expect(leafNodeComponent.find('circle').prop('style')).toBe(leafCircle);
104+
expect(nodeComponent.find('circle').prop('style')).toBe(circle);
105+
});
106+
107+
108+
it('applies correct node attributes styles', () => {
109+
const fixture = {
110+
attributes: {
111+
stroke: '#000',
112+
strokeWidth: 12,
113+
},
114+
};
115+
const renderedComponent = shallow(
116+
<Node
117+
{...mockProps}
118+
styles={fixture}
119+
/>
120+
);
121+
122+
expect(renderedComponent.find('.nodeAttributesBase').prop('style')).toBe(fixture.attributes);
80123
});
81124

82125

0 commit comments

Comments
 (0)