Skip to content

Commit ae115fa

Browse files
DanielecinaDaniele
andauthored
FIX: Invalid proptype warning for handle prop (#133)
* Add test suite && refactor unused props in Resizablejs && ResizableBox * remove breaking change * improve snapshot * changelog * import draggableprops from library * abstracted flowTypes & propTypes * resolve conflict Co-authored-by: Daniele <daniele.cina@makeitapp.eu>
1 parent e808ae8 commit ae115fa

19 files changed

Lines changed: 4532 additions & 1809 deletions

.eslintrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"plugins": [
55
"react"
66
],
7-
"extends": "eslint:recommended",
7+
"extends": [
8+
"eslint:recommended"
9+
],
810
"rules": {
911
"strict": 0,
1012
"quotes": [0, "single"],
@@ -20,9 +22,10 @@
2022
"react/jsx-uses-vars": 1,
2123
"semi": [1, "always"]
2224
},
23-
env: {
25+
"env": {
2426
"browser": true,
25-
"node": true
27+
"node": true,
28+
"jest": true
2629
},
2730
"globals": {
2831
// For Flow

.gitignore

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
node_modules
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
23
dist
3-
npm-debug.log
4-
build/
4+
build
5+
6+
# dependencies
7+
/node_modules
8+
package-lock.json
9+
10+
# testing
11+
/coverage/
12+
13+
# misc
14+
.DS_Store
15+
npm-debug.log*
16+
yarn-debug.log*
17+
yarn-error.log*
18+
19+
# ide
20+
.vscode
21+
.idea
22+

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### Unreleased
4+
5+
- 🐛 Bugfix: remove unknown Prop `handle` from div children in Resizable React.CloneElement [124](https://github.com/STRML/react-resizable/issues/124)
6+
37
### 1.10.1 (Nov 25, 2019)
48

59
> Note: 1.10.0 was a mis-publish.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ A simple widget that can be resized via one or more handles.
66

77
You can either use the `<Resizable>` element directly, or use the much simpler `<ResizableBox>` element.
88

9-
See the example and associated code in [TestLayout](/test/TestLayout.js) and
9+
See the example and associated code in [TestLayout](/examples/TestLayout.js) and
1010
[ResizableBox](/lib/ResizableBox.js) for more details.
1111

1212
Make sure you use the associated styles in [/css/styles.css](/css/styles.css), as without them, you will have
1313
problems with handle placement and visibility.
1414

1515
You can pass options directly to the underlying `DraggableCore` instance by using the prop `draggableOpts`.
16-
See the [demo](/test/TestLayout.js) for more on this.
16+
See the [demo](/examples/TestLayout.js) for more on this.
1717

1818
### Installation
1919

__tests__/Resizable.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
import {shallow} from 'enzyme';
4+
import {DraggableCore} from "react-draggable";
5+
6+
import Resizable from '../lib/Resizable';
7+
8+
describe('render Resizable', () => {
9+
const props = {
10+
axis: 'both',
11+
className: 'test-classname',
12+
handleSize: [20, 20],
13+
height: 50,
14+
lockAspectRatio: false,
15+
maxConstraints: [Infinity, Infinity],
16+
minConstraints: [20, 20],
17+
onResize: jest.fn(),
18+
resizeHandles: ['se', 'e'],
19+
transformScale: 1,
20+
width: 50,
21+
};
22+
const userChildren = <span className={'children'} />;
23+
const resizableBoxChildren = <div style={{width: '50px', height: '50px'}}>{userChildren}</div>;
24+
25+
beforeEach(() => {
26+
jest.clearAllMocks();
27+
});
28+
29+
test('snapshot default props', () => {
30+
const tree = renderer.create(<Resizable {...props}>{resizableBoxChildren}</Resizable>).toJSON();
31+
expect(tree).toMatchSnapshot();
32+
});
33+
34+
test('with correct props', () => {
35+
const element = shallow(<Resizable {...props}>{resizableBoxChildren}</Resizable>);
36+
expect(element.find('.test-classname').find('.children'));
37+
expect(element.find(DraggableCore)).toHaveLength(2);
38+
const cursorSe = element.find('.react-resizable-handle-se');
39+
const cursorE = element.find('.react-resizable-handle-e');
40+
expect(cursorSe).toHaveLength(1);
41+
expect(cursorE).toHaveLength(1);
42+
});
43+
44+
describe('and pass handle props', () => {
45+
test('as component', () => {
46+
const customProps = {
47+
...props,
48+
resizeHandles: ['se'],
49+
handle: <span className={'custom-component'} />
50+
};
51+
const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
52+
expect(element.find('.react-resizable-handle-se')).toHaveLength(0);
53+
expect(element.find('.custom-component')).toHaveLength(1);
54+
});
55+
test('as function', () => {
56+
const customProps = {
57+
...props,
58+
resizeHandles: ['se'],
59+
handle: (h) => <span className={`custom-component-${h}`} />
60+
};
61+
const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
62+
expect(element.find('.custom-component-se')).toHaveLength(1);
63+
});
64+
});
65+
});

__tests__/ResizableBox.test.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
import {shallow} from 'enzyme';
4+
5+
import ResizableBox from '../lib/ResizableBox';
6+
import Resizable from "../lib/Resizable";
7+
8+
describe('render ResizableBox', () => {
9+
const props = {
10+
axis: 'x',
11+
handle: jest.fn(resizeHandle => <span className={`test-class-${resizeHandle}`} />),
12+
handleSize: [20, 20],
13+
height: 50,
14+
lockAspectRatio: false,
15+
maxConstraints: [30, 30],
16+
minConstraints: [10, 10],
17+
onResize: jest.fn(),
18+
onResizeStart: jest.fn(),
19+
onResizeStop: jest.fn(),
20+
resizeHandles: ['w'],
21+
width: 50,
22+
};
23+
const children = <span className={'children'} />;
24+
25+
beforeEach(() => {
26+
jest.clearAllMocks();
27+
});
28+
29+
test('snapshot default props', () => {
30+
const tree = renderer.create(<ResizableBox {...props}>{children}</ResizableBox>).toJSON();
31+
expect(tree).toMatchSnapshot();
32+
});
33+
34+
test('with correct props', () => {
35+
const element = shallow(<ResizableBox {...props}>{children}</ResizableBox>);
36+
expect(element.state()).toEqual({
37+
height: 50,
38+
propsHeight: 50,
39+
propsWidth: 50,
40+
width: 50,
41+
});
42+
const resizable = element.find(Resizable);
43+
const fakeEvent = {persist: jest.fn()};
44+
const data = {node: children, size: {width: 30, height: 30}, handle: 'w'};
45+
resizable.simulate('resize', fakeEvent, data);
46+
expect(element.state()).toEqual({
47+
height: 30,
48+
propsHeight: 50,
49+
propsWidth: 50,
50+
width: 30,
51+
});
52+
expect(element.find('.children')).toHaveLength(1);
53+
expect(fakeEvent.persist).toHaveBeenCalledTimes(1);
54+
expect(props.onResize).toHaveBeenCalledWith(fakeEvent, data);
55+
56+
resizable.simulate('resizeStart', fakeEvent, data);
57+
expect(props.onResizeStart).toHaveBeenCalledWith(fakeEvent, data);
58+
59+
resizable.simulate('resizeStop', fakeEvent, data);
60+
expect(props.onResizeStop).toHaveBeenCalledWith(fakeEvent, data);
61+
});
62+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`render Resizable snapshot default props 1`] = `
4+
<div
5+
className="test-classname react-resizable"
6+
style={
7+
Object {
8+
"height": "50px",
9+
"width": "50px",
10+
}
11+
}
12+
>
13+
<span
14+
className="children"
15+
/>
16+
<span
17+
className="react-resizable-handle react-resizable-handle-se"
18+
onMouseDown={[Function]}
19+
onMouseUp={[Function]}
20+
onTouchEnd={[Function]}
21+
/>
22+
<span
23+
className="react-resizable-handle react-resizable-handle-e"
24+
onMouseDown={[Function]}
25+
onMouseUp={[Function]}
26+
onTouchEnd={[Function]}
27+
/>
28+
</div>
29+
`;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`render ResizableBox snapshot default props 1`] = `
4+
<div
5+
className="react-resizable"
6+
style={
7+
Object {
8+
"height": "50px",
9+
"width": "50px",
10+
}
11+
}
12+
>
13+
<span
14+
className="children"
15+
/>
16+
<span
17+
className="test-class-w"
18+
onMouseDown={[Function]}
19+
onMouseUp={[Function]}
20+
onTouchEnd={[Function]}
21+
/>
22+
</div>
23+
`;

examples/1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h3>React-Resizable Demo</h3>
5454
gives those components resize handles.
5555
</p>
5656
<p><a href="https://github.com/STRML/react-resizable">View project on GitHub</a></p>
57-
<p><a href="https://github.com/STRML/react-resizable/blob/master/test/TestLayout.js">View this page's source</a></p>
57+
<p><a href="https://github.com/STRML/react-resizable/blob/master/examples/ExampleLayout.js">View this page's source</a></p>
5858
<div id="content"></div>
5959
</body>
6060
</html>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ResizableBox from '../lib/ResizableBox';
44
import 'style-loader!css-loader!../css/styles.css';
55
import 'style-loader!css-loader!./test.css';
66

7-
export default class TestLayout extends React.Component<{}, {width: number, height: number}> {
7+
export default class ExampleLayout extends React.Component<{}, {width: number, height: number}> {
88
state = {width: 200, height: 200};
99

1010
onClick = () => {

0 commit comments

Comments
 (0)