Skip to content

Commit a07b457

Browse files
committed
Update Link tests for transitions
1 parent 8fc248c commit a07b457

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

src/Link/tests/index.test.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { shallow, mount } from 'enzyme';
33

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

@@ -15,49 +15,65 @@ describe('<Link />', () => {
1515
},
1616
};
1717

18-
// Clear method spies on prototype before each test
18+
const mockProps = {
19+
linkData,
20+
pathFunc: 'diagonal',
21+
orientation: 'horizontal',
22+
transitionDuration: 500,
23+
};
24+
25+
26+
jest.spyOn(Link.prototype, 'diagonalPath');
27+
jest.spyOn(Link.prototype, 'elbowPath');
28+
jest.spyOn(Link.prototype, 'applyOpacity');
29+
30+
// Clear method spies on prototype after each test
1931
afterEach(() => jest.clearAllMocks());
2032

21-
it('should apply the base className', () => {
33+
34+
it('applies the base className', () => {
2235
const renderedComponent = shallow(
23-
<Link
24-
linkData={linkData}
25-
pathFunc="diagonal"
26-
orientation="horizontal"
27-
/>
36+
<Link {...mockProps} />
2837
);
2938

3039
expect(renderedComponent.prop('className')).toBe('linkBase');
3140
});
3241

33-
it('should call the appropriate path func based on `props.pathFunc`', () => {
34-
jest.spyOn(Link.prototype, 'diagonalPath');
35-
jest.spyOn(Link.prototype, 'elbowPath');
42+
43+
it('calls the appropriate path func based on `props.pathFunc`', () => {
3644
const diagonalComponent = shallow(
37-
<Link
38-
linkData={linkData}
39-
pathFunc="diagonal"
40-
orientation="horizontal"
41-
/>
45+
<Link {...mockProps} />
4246
);
4347
const elbowComponent = shallow(
4448
<Link
45-
linkData={linkData}
49+
{...mockProps}
4650
pathFunc="elbow"
47-
orientation="horizontal"
4851
/>
4952
);
5053

5154
expect(diagonalComponent.instance().diagonalPath).toHaveBeenCalled();
5255
expect(elbowComponent.instance().elbowPath).toHaveBeenCalled();
5356
});
5457

55-
it('should return an appropriate elbowPath according to `props.orientation`', () => {
58+
59+
it('returns an appropriate elbowPath according to `props.orientation`', () => {
5660
expect(
5761
Link.prototype.elbowPath(linkData, 'horizontal')
5862
).toBe(`M${linkData.source.y},${linkData.source.x}V${linkData.target.x}H${linkData.target.y}`);
5963
expect(
6064
Link.prototype.elbowPath(linkData, 'vertical')
6165
).toBe(`M${linkData.source.x},${linkData.source.y}V${linkData.target.y}H${linkData.target.x}`);
6266
});
67+
68+
69+
it('fades in once it has been mounted', () => {
70+
const fixture = 1;
71+
const renderedComponent = mount(
72+
<Link {...mockProps} />
73+
);
74+
75+
expect(renderedComponent.instance().applyOpacity).toHaveBeenCalledWith(fixture);
76+
});
77+
78+
// TODO Find a way to meaningfully test `componentWillLeave`
6379
});

src/Node/tests/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ describe('<Node />', () => {
194194
});
195195

196196
// TODO Find a way to meaningfully test `componentWillLeave`
197+
197198
// it('regresses to its parent coords when unmounting/leaving', () => {
198199
// jest.spyOn(Node.prototype, 'applyTransform');
199200
// const fixture = `translate(${nodeData.parent.y},${nodeData.parent.x})`;

0 commit comments

Comments
 (0)