Skip to content

Commit 7c70f71

Browse files
chazcbCharles Covey-Brandtwilliaster
authored
internal: Remove Enzyme from visx (#1893)
* Tag enzyme files * Get the Jest baseline * Ran LLM fix everything * One more passing * One more passing * All passing * Run a pass to remove mocks where possible * Add lost coverage * Clean for PR * Lint fix * Fix remaining errors * fix funky tests * one more pass * remove duplicative test * remove spurious @testing-library/react-hooks * fix visx-glyph tests * remove enzyme deps and setup scripts --------- Co-authored-by: Charles Covey-Brandt <[email protected]> Co-authored-by: Chris Williams <[email protected]>
1 parent 4b6dd16 commit 7c70f71

File tree

87 files changed

+2849
-2160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2849
-2160
lines changed

config-jest/setup/enzyme.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ module.exports = {
3737
},
3838
roots: ['<rootDir>/packages'],
3939
setupFiles: ['<rootDir>/config-jest/setup/shims.js', '<rootDir>/config-jest/setup/console.js'],
40-
setupFilesAfterEnv: ['<rootDir>/config-jest/setup/enzyme.js'],
4140
testEnvironment: 'jsdom',
4241
testURL: 'http://localhost',
4342
timers: 'fake',

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"@testing-library/jest-dom": "^6.6.0",
7272
"@testing-library/react": "^16.1.0",
7373
"@testing-library/user-event": "^13.5.0",
74-
"@types/enzyme": "^3.10.3",
7574
"@types/jest": "^24.0.18",
7675
"@types/jsdom": "^12.2.4",
7776
"@types/node-fetch": "1.6.9",
@@ -81,9 +80,6 @@
8180
"babel-plugin-typescript-to-proptypes": "^2.0.0",
8281
"chalk": "4.1.0",
8382
"coveralls": "^3.0.6",
84-
"enzyme": "^3.10.0",
85-
"enzyme-adapter-react-16": "^1.14.0",
86-
"enzyme-to-json": "^3.4.0",
8783
"eslint": "^8.30.0",
8884
"eslint-config-airbnb": "^19.0.4",
8985
"eslint-config-prettier": "^8.5.0",
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { render } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
34
import { CircleSubject } from '../src';
45

56
describe('<CircleSubject />', () => {
67
it('should be defined', () => {
78
expect(CircleSubject).toBeDefined();
89
});
9-
it('should render a cirlce', () => {
10-
expect(shallow(<CircleSubject />).find('circle')).toHaveLength(1);
10+
11+
it('should render a circle', () => {
12+
const { container } = render(
13+
<svg>
14+
<CircleSubject x={10} y={10} />
15+
</svg>,
16+
);
17+
18+
const circle = container.querySelector('circle');
19+
expect(circle).toBeInTheDocument();
20+
expect(circle).toHaveAttribute('cx', '10');
21+
expect(circle).toHaveAttribute('cy', '10');
1122
});
1223
});
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { render } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
34
import { Connector } from '../src';
45

56
describe('<Connector />', () => {
67
it('should be defined', () => {
78
expect(Connector).toBeDefined();
89
});
10+
911
it('should render a path', () => {
10-
expect(shallow(<Connector />).find('path')).toHaveLength(1);
12+
const { container } = render(
13+
<svg width={100} height={100}>
14+
<Connector />
15+
</svg>,
16+
);
17+
expect(container.querySelector('path')).toBeInTheDocument();
1118
});
1219
});
Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,75 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
3-
import { Annotation, EditableAnnotation } from '../src';
4-
import { EditableAnnotationProps } from '../lib/components/EditableAnnotation';
2+
import { render } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
5+
import EditableAnnotation from '../src/components/EditableAnnotation';
56

67
describe('<EditableAnnotation />', () => {
7-
function setup(props?: Partial<EditableAnnotationProps>) {
8-
return shallow(
9-
<EditableAnnotation width={100} height={100} {...props}>
10-
<div />
11-
</EditableAnnotation>,
8+
type EditableAnnotationProps = React.ComponentProps<typeof EditableAnnotation>;
9+
10+
const defaultProps: EditableAnnotationProps = {
11+
width: 100,
12+
height: 100,
13+
x: 0,
14+
y: 0,
15+
dx: 0,
16+
dy: 0,
17+
children: <div data-testid="child-content">Child content</div>,
18+
};
19+
20+
function renderComponent(props?: Partial<EditableAnnotationProps>) {
21+
return render(
22+
<svg>
23+
<EditableAnnotation {...defaultProps} {...props} />
24+
</svg>,
1225
);
1326
}
27+
28+
beforeEach(() => {
29+
jest.clearAllMocks();
30+
});
31+
1432
it('should be defined', () => {
15-
expect(EditableAnnotation).toBeDefined();
33+
expect(() => renderComponent()).not.toThrow();
1634
});
17-
it('should render two resize handles', () => {
18-
expect(setup().find('circle')).toHaveLength(2);
35+
36+
it('should render two resize handles by default', () => {
37+
const { container } = renderComponent();
38+
const circles = container.querySelectorAll('circle');
39+
expect(circles).toHaveLength(2);
1940
});
20-
it('should render one resize handle if canEditLabel or canEditSubject are false', () => {
21-
expect(setup({ canEditLabel: false }).find('circle')).toHaveLength(1);
22-
expect(setup({ canEditSubject: false }).find('circle')).toHaveLength(1);
41+
42+
it('should render one resize handle if canEditLabel is false', () => {
43+
const { container } = renderComponent({ canEditLabel: false });
44+
const circles = container.querySelectorAll('circle');
45+
expect(circles).toHaveLength(1);
2346
});
24-
it('should render an Annotation', () => {
25-
expect(setup().find(Annotation)).toHaveLength(1);
47+
48+
it('should render one resize handle if canEditSubject is false', () => {
49+
const { container } = renderComponent({ canEditSubject: false });
50+
const circles = container.querySelectorAll('circle');
51+
expect(circles).toHaveLength(1);
52+
});
53+
54+
it('should render children content', () => {
55+
const { getByTestId } = renderComponent();
56+
expect(getByTestId('child-content')).toBeInTheDocument();
57+
});
58+
59+
it('should render with correct initial positions', () => {
60+
const { container } = renderComponent({
61+
x: 10,
62+
y: 20,
63+
dx: 30,
64+
dy: 40,
65+
});
66+
67+
const circles = container.querySelectorAll('circle');
68+
const [subjectHandle, labelHandle] = circles;
69+
70+
expect(subjectHandle).toHaveAttribute('cx', '10');
71+
expect(subjectHandle).toHaveAttribute('cy', '20');
72+
expect(labelHandle).toHaveAttribute('cx', '40'); // x + dx
73+
expect(labelHandle).toHaveAttribute('cy', '60'); // y + dy
2674
});
2775
});
Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
11
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
25
import { ResizeObserver } from '@juggle/resize-observer';
3-
import Text from '@visx/text/lib/Text';
4-
import { shallow } from 'enzyme';
56
import { Label } from '../src';
67

78
describe('<Label />', () => {
9+
const renderLabel = (props: React.ComponentProps<typeof Label>) =>
10+
render(
11+
<svg>
12+
<Label {...props} />
13+
</svg>,
14+
);
15+
816
it('should be defined', () => {
917
expect(Label).toBeDefined();
1018
});
11-
it('should render title Text', () => {
12-
expect(
13-
shallow(<Label title="title test" resizeObserverPolyfill={ResizeObserver} />)
14-
.dive()
15-
.children()
16-
.find(Text)
17-
.prop('children'),
18-
).toBe('title test');
19+
20+
it('should render title text', () => {
21+
const { getByText } = renderLabel({
22+
title: 'title test',
23+
resizeObserverPolyfill: ResizeObserver,
24+
});
25+
expect(getByText('title test')).toBeInTheDocument();
1926
});
20-
it('should render subtitle Text', () => {
21-
expect(
22-
shallow(
23-
<Label
24-
title="title test"
25-
subtitle="subtitle test"
26-
resizeObserverPolyfill={ResizeObserver}
27-
/>,
28-
)
29-
.dive()
30-
.children()
31-
.find(Text)
32-
.at(1)
33-
.prop('children'),
34-
).toBe('subtitle test');
27+
28+
it('should render subtitle text', () => {
29+
const { getByText } = renderLabel({
30+
title: 'title test',
31+
subtitle: 'subtitle test',
32+
resizeObserverPolyfill: ResizeObserver,
33+
});
34+
expect(getByText('subtitle test')).toBeInTheDocument();
3535
});
36-
it('should render a background', () => {
37-
expect(
38-
shallow(<Label title="title test" showBackground resizeObserverPolyfill={ResizeObserver} />)
39-
.dive()
40-
.find('rect'),
41-
).toHaveLength(1);
36+
37+
it('should render background', () => {
38+
const { container } = renderLabel({
39+
title: 'title test',
40+
showBackground: true,
41+
resizeObserverPolyfill: ResizeObserver,
42+
});
43+
const rect = container.querySelector('rect');
44+
expect(rect).toBeInTheDocument();
4245
});
43-
it('should render an anchor line', () => {
44-
expect(
45-
shallow(<Label title="title test" showAnchorLine resizeObserverPolyfill={ResizeObserver} />)
46-
.dive()
47-
.find('AnchorLine')
48-
.dive()
49-
.find('line'),
50-
).toHaveLength(1);
46+
47+
it('should render anchor line', () => {
48+
const { container } = renderLabel({
49+
title: 'title test',
50+
showAnchorLine: true,
51+
resizeObserverPolyfill: ResizeObserver,
52+
});
53+
const line = container.querySelector('line');
54+
expect(line).toBeInTheDocument();
5155
});
5256
});
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { render } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
34
import { LineSubject } from '../src';
45

56
describe('<LineSubject />', () => {
67
it('should be defined', () => {
78
expect(LineSubject).toBeDefined();
89
});
10+
911
it('should render a line', () => {
10-
expect(shallow(<LineSubject min={0} max={100} />).find('line')).toHaveLength(1);
12+
const { container } = render(
13+
<svg width={100} height={100}>
14+
<LineSubject min={0} max={100} x={50} y={50} />
15+
</svg>,
16+
);
17+
const lineElement = container.querySelector('line');
18+
expect(lineElement).toBeInTheDocument();
1119
});
1220
});

0 commit comments

Comments
 (0)