react-resizable 1.10.1 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.eslintrc +10 -6
  2. package/.flowconfig +8 -8
  3. package/CHANGELOG.md +48 -37
  4. package/README.md +13 -3
  5. package/__tests__/Resizable.test.js +245 -0
  6. package/__tests__/ResizableBox.test.js +99 -0
  7. package/__tests__/__snapshots__/Resizable.test.js.snap +29 -0
  8. package/__tests__/__snapshots__/ResizableBox.test.js.snap +23 -0
  9. package/build/Resizable.js +100 -134
  10. package/build/Resizable.js.flow +87 -161
  11. package/build/ResizableBox.js +32 -29
  12. package/build/ResizableBox.js.flow +44 -28
  13. package/build/propTypes.js +112 -0
  14. package/build/propTypes.js.flow +135 -0
  15. package/build/utils.js +3 -3
  16. package/coverage/clover.xml +107 -0
  17. package/coverage/coverage-final.json +5 -0
  18. package/coverage/lcov-report/Resizable.js.html +665 -0
  19. package/coverage/lcov-report/ResizableBox.js.html +374 -0
  20. package/coverage/lcov-report/base.css +224 -0
  21. package/coverage/lcov-report/block-navigation.js +79 -0
  22. package/coverage/lcov-report/favicon.png +0 -0
  23. package/coverage/lcov-report/flow-typed/npm/index.html +111 -0
  24. package/coverage/lcov-report/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
  25. package/coverage/lcov-report/index.html +156 -0
  26. package/coverage/lcov-report/prettify.css +1 -0
  27. package/coverage/lcov-report/prettify.js +2 -0
  28. package/coverage/lcov-report/propTypes.js.html +485 -0
  29. package/coverage/lcov-report/react-resizable/dist/bundle.js.html +95 -0
  30. package/coverage/lcov-report/react-resizable/dist/index.html +111 -0
  31. package/coverage/lcov-report/react-resizable/flow-typed/npm/index.html +111 -0
  32. package/coverage/lcov-report/react-resizable/flow-typed/npm/jest_v26.x.x.js.html +3734 -0
  33. package/coverage/lcov-report/react-resizable/index.html +111 -0
  34. package/coverage/lcov-report/react-resizable/index.js.html +101 -0
  35. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  36. package/coverage/lcov-report/sorter.js +170 -0
  37. package/coverage/lcov-report/utils.js.html +122 -0
  38. package/coverage/lcov.info +233 -0
  39. package/dist/bundle.js +6 -0
  40. package/flow-typed/npm/jest_v26.x.x.js +1218 -0
  41. package/package.json +26 -20
  42. package/setupTests/enzyme.js +4 -0
  43. package/index.html +0 -15
package/.eslintrc CHANGED
@@ -4,7 +4,9 @@
4
4
  "plugins": [
5
5
  "react"
6
6
  ],
7
- "extends": "eslint:recommended",
7
+ "extends": [
8
+ "eslint:recommended"
9
+ ],
8
10
  "rules": {
9
11
  "strict": 0,
10
12
  "quotes": [0, "single"],
@@ -20,14 +22,16 @@
20
22
  "react/jsx-uses-vars": 1,
21
23
  "semi": [1, "always"]
22
24
  },
23
- env: {
25
+ "env": {
24
26
  "browser": true,
25
- "node": true
27
+ "node": true,
28
+ "jest": true
26
29
  },
27
30
  "globals": {
28
31
  // For Flow
29
- "ReactElement",
30
- "ReactClass",
31
- "SyntheticEvent"
32
+ "ReactElement": false,
33
+ "ReactClass": false,
34
+ "SyntheticEvent": false,
35
+ "ClientRect": false
32
36
  }
33
37
  }
package/.flowconfig CHANGED
@@ -1,5 +1,5 @@
1
1
  [version]
2
- ^0.110.0
2
+ ^0.133.0
3
3
 
4
4
  [ignore]
5
5
  .*/node_modules/@babel.*
@@ -10,20 +10,20 @@
10
10
  [include]
11
11
 
12
12
  [libs]
13
+ flow-typed
14
+
15
+ [lints]
16
+ all=warn
17
+ implicit-inexact-object=error
13
18
 
14
19
  [options]
15
- suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowFixMe.*
16
- suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowBug.*
17
- suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowIgnore.*
18
- suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowNewLine.*
19
- suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowIssue
20
20
  suppress_type=$FlowFixMe
21
21
  esproposal.class_static_fields=enable
22
22
  esproposal.class_instance_fields=enable
23
23
  esproposal.decorators=ignore
24
24
  esproposal.export_star_as=enable
25
25
  experimental.strict_call_arity=true
26
- module.system.node.resolve_dirname=node_modules
27
- module.system.node.resolve_dirname=.
26
+ module.system.node.allow_root_relative=true
28
27
  module.use_strict=true
29
28
  server.max_workers=6
29
+ exact_by_default=true
package/CHANGELOG.md CHANGED
@@ -1,113 +1,124 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.11.0 (Sep 3, 2020)
4
+
5
+ - ⚠ Important Notice!
6
+ - React-Resizable 2.0.0 was published due to a breaking change in `props` handling. This change ended up actually completely breaking certain workflows, for the dubious benefit of making the code slightly simpler to add to. The breaking change has been reverted, 2.0.0 is now deprecated, and we will continue on the 1.x branch. Future breaking changes to `react-resizable` will upgrade the major version to `3`.
7
+ - ➕ Feature: `<ResizableBox>` now takes a `style` prop which will be applied on the wrapping `<div>`. `width` and `height` in this prop are ignored.
8
+ - 🐛 Bugfix: remove unknown Prop `handle` from div children in Resizable `React.cloneElement`. [#124](https://github.com/STRML/react-resizable/issues/124)
9
+ - 🐛 Bugfix: Fix top and left resizing jerkiness. Thanks @conor-kelleher. [#136](https://github.com/STRML/react-resizable/pull/136)
10
+ - ✏ Chore: Improved test suite. Please contribute tests for your use cases if you have the time, I would really appreciate it! Thanks very much, @Danielecina
11
+ - ✏ Chore: Minor internal refactors and additional tests.
12
+ - ✏ Chore: Additional examples.
13
+
3
14
  ### 1.10.1 (Nov 25, 2019)
4
15
 
5
16
  > Note: 1.10.0 was a mis-publish.
6
17
 
7
- - Feat: Add `transformScale` prop [#115](https://github.com/STRML/react-resizable/pull/115)
8
- - Bugfix: Resolve `getDerivedStateFromProps` dev warning [#117](https://github.com/STRML/react-resizable/pull/117)
18
+ - ➕ Feature: Add `transformScale` prop [#115](https://github.com/STRML/react-resizable/pull/115)
19
+ - 🐛 Bugfix: Resolve `getDerivedStateFromProps` dev warning [#117](https://github.com/STRML/react-resizable/pull/117)
9
20
 
10
21
  ### 1.9.0 (Oct 24, 2019)
11
22
 
12
- - Fix resize with north/south handles when `lockAspectRatio=true` [#106](https://github.com/STRML/react-resizable/pull/106)
13
- - Remove deprecated React 16.9 lifecycle methods (`componentWillReceiveProps`) (https://github.com/STRML/react-resizable/pull/112/commits/541dee69b8e45d91a533855609472b481634edee)
14
- - Upgrade to babel 7
15
- - [Remove unused state inside `<Draggable>`](https://github.com/STRML/react-resizable/pull/112/commits/05693f63d6d221ad652f0f28af024cfb46a5f2df). This has not been needed for quite some time, fixes [some bugs](https://github.com/STRML/react-resizable/issues/99) and improves performance.
23
+ - 🐛 Bugfix: Fix resize with north/south handles when `lockAspectRatio=true` [#106](https://github.com/STRML/react-resizable/pull/106)
24
+ - ✏ Chore: Remove deprecated React 16.9 lifecycle methods (`componentWillReceiveProps`) (https://github.com/STRML/react-resizable/pull/112/commits/541dee69b8e45d91a533855609472b481634edee)
25
+ - ✏ Chore: Upgrade to babel 7
26
+ - ✏ Chore: [Remove unused state inside `<Draggable>`](https://github.com/STRML/react-resizable/pull/112/commits/05693f63d6d221ad652f0f28af024cfb46a5f2df). This has not been needed for quite some time, fixes [some bugs](https://github.com/STRML/react-resizable/issues/99) and improves performance.
16
27
 
17
28
  ### 1.8.0 (May 15, 2019)
18
29
 
19
- - Added support for custom resize handles [#79](https://github.com/STRML/react-resizable/pull/79)
20
- - Added support for resize handles on all corners [#191](https://github.com/STRML/react-resizable/pull/191)
30
+ - ➕ Feature: Added support for custom resize handles [#79](https://github.com/STRML/react-resizable/pull/79)
31
+ - ➕ Feature: Added support for resize handles on all corners [#191](https://github.com/STRML/react-resizable/pull/191)
21
32
 
22
33
  ### 1.7.5 (Sep 26, 2017)
23
34
 
24
- - Support for React 16 (no changes required, updated `peerDependencies`)
25
- - Minor dep updates.
35
+ - ✏ Chore: Support for React 16 (no changes required, updated `peerDependencies`)
36
+ - ✏ Chore: Minor dep updates.
26
37
 
27
38
  ### 1.7.4 (Sep 5, 2017)
28
39
 
29
- - Minor Flow & dependency updates.
40
+ - ✏ Chore: Minor Flow & dependency updates.
30
41
 
31
42
  ### 1.7.3 (Aug 31, 2017)
32
43
 
33
- - Fix React deprecation warnings from `import *`
44
+ - 🐛 Bugfix: React deprecation warnings from `import *`
34
45
  - https://github.com/facebook/react/issues/10583
35
46
 
36
47
  ### 1.7.2 (Aug 21, 2017)
37
48
 
38
- - Pkg: Add `react-draggable@3.0.0` to version range.
49
+ - ✏ Chore: Pkg: Add `react-draggable@3.0.0` to version range.
39
50
  - This package is compatible with both `@2` and `@3` versions.
40
51
 
41
52
  ### 1.7.1 (May 23, 2017)
42
53
 
43
- - Bugfix: Some flow types were improperly specified.
54
+ - 🐛 Bugfix: Some flow types were improperly specified.
44
55
 
45
56
  ### 1.7.0 (May 1, 2017)
46
57
 
47
- - Deprecation: `React.PropTypes` now deprecated in React 15.5, moved to `prop-types` package
48
- - Internal: Update devDeps, upgrade to webpack 2
49
- - Internal: Remove babel `stage-1` and `transform-flow-comments`, bring in only selected plugins, makes for leaner dev/build.
58
+ - Deprecation: `React.PropTypes` now deprecated in React 15.5, moved to `prop-types` package
59
+ - ✏ Chore: Update devDeps, upgrade to webpack 2
60
+ - ✏ Chore: Remove babel `stage-1` and `transform-flow-comments`, bring in only selected plugins, makes for leaner dev/build.
50
61
 
51
62
  ### 1.6.0 (Jan 23, 2017)
52
63
 
53
- - Feature: Allow restricting by axis. (#40, thanks @dnissley-al)
64
+ - Feature: Allow restricting by axis. (#40, thanks @dnissley-al)
54
65
 
55
66
  ### 1.5.0 (Jan 23, 2017)
56
67
 
57
- - Bugfix: Persist SyntheticEvents when needed (#45, #46)
58
- - Feature: Add componentWillReceiveProps to `<ResizableBox>` (#44, thanks @JoaoMosmann)
68
+ - 🐛 Bugfix: Persist SyntheticEvents when needed (#45, #46)
69
+ - Feature: Add componentWillReceiveProps to `<ResizableBox>` (#44, thanks @JoaoMosmann)
59
70
 
60
71
  ### 1.4.6 (Dec 30, 2016)
61
72
 
62
- - Removed unused ref from `<Resizable>`.
63
- - Added development lockfile.
73
+ - ✏ Chore: Removed unused ref from `<Resizable>`.
74
+ - ✏ Chore: Added development lockfile.
64
75
 
65
76
  ### 1.4.5 (Sep 30, 2016)
66
77
 
67
- - Fix bad publish
78
+ - 🐛 Bugfix: Fix bad publish
68
79
 
69
80
  ### 1.4.4 (Sep 30, 2016)
70
81
 
71
- - Bugfix: Minor flow errors
82
+ - 🐛 Bugfix: Minor flow errors
72
83
 
73
84
  ### 1.4.3 (Sep 27, 2016)
74
85
 
75
- - Bugfix: Don't pass `onResize` in `<ResizableBox>`.
76
- - Bugfix: Fix new Flow errors (type parameters no longer optional).
86
+ - 🐛 Bugfix: Don't pass `onResize` in `<ResizableBox>`.
87
+ - 🐛 Bugfix: Fix new Flow errors (type parameters no longer optional).
77
88
 
78
89
  ### 1.4.2 (July 1, 2016)
79
90
 
80
- - Bugfix: Don't pass unknown props to underlying DOM element. Fixes React 15.2.0 warnings.
91
+ - 🐛 Bugfix: Don't pass unknown props to underlying DOM element. Fixes React 15.2.0 warnings.
81
92
 
82
93
  ### 1.4.1 (May 23, 2016)
83
94
 
84
- - Bugfix: Resizable handle should have a `key` when injected. Fixes React warnings on custom components.
95
+ - 🐛 Bugfix: Resizable handle should have a `key` when injected. Fixes React warnings on custom components.
85
96
 
86
97
  ### 1.4.0 (May 20, 2016)
87
98
 
88
- - Update to React-Draggable v2, which changed callback data structure.
99
+ - ✏ Chore: Update to React-Draggable v2, which changed callback data structure.
89
100
 
90
101
  ### 1.3.4 (May 17, 2016)
91
102
 
92
- - Bugfix: Slack was not being reset on resizeStop. Fixes #34, #36.
93
- - Added `flow-bin` to devDeps.
103
+ - 🐛 Bugfix: Slack was not being reset on resizeStop. Fixes #34, #36.
104
+ - ✏ Chore: Added `flow-bin` to devDeps.
94
105
 
95
106
  ### 1.3.3 (Apr 19, 2016)
96
107
 
97
- - Enhancement: Add Flow comments.
108
+ - ➕ Feature: Add Flow comments.
98
109
 
99
110
  ### 1.3.2 (Apr 8, 2016)
100
111
 
101
- - Bugfix: Prevent `width` and `height` from leaking to the underlying DOM element and being written.
112
+ - 🐛 Bugfix: Prevent `width` and `height` from leaking to the underlying DOM element and being written.
102
113
 
103
114
  ### 1.3.1 (Apr 8, 2016)
104
115
 
105
- - Allow React v15 in peerdeps.
116
+ - ✏ Chore: Allow React v15 in peerdeps.
106
117
 
107
118
  ### 1.3.0 (Mar 11, 2016)
108
119
 
109
- - Switch to ES2015 Loose Mode to fix IE9/10 issues.
110
- - Flow typing fixes.
111
- - Styling fixes to the demo page.
120
+ - 🐛 Bugfix: Switch to ES2015 Loose Mode to fix IE9/10 issues.
121
+ - 🐛 Bugfix: Flow typing fixes.
122
+ - 🐛 Bugfix: Styling fixes to the demo page.
112
123
 
113
124
  > Changes before 1.3.0 were not logged. Please see the git commit history.
package/README.md CHANGED
@@ -6,14 +6,14 @@ A simple widget that can be resized via one or more handles.
6
6
 
7
7
  You can either use the `<Resizable>` element directly, or use the much simpler `<ResizableBox>` element.
8
8
 
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
10
10
  [ResizableBox](/lib/ResizableBox.js) for more details.
11
11
 
12
12
  Make sure you use the associated styles in [/css/styles.css](/css/styles.css), as without them, you will have
13
13
  problems with handle placement and visibility.
14
14
 
15
15
  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.
17
17
 
18
18
  ### Installation
19
19
 
@@ -43,7 +43,7 @@ render() {
43
43
 
44
44
  ### Props
45
45
 
46
- These props apply to both `<Resizable>` and `<ResizableBox>`.
46
+ These props apply to both `<Resizable>` and `<ResizableBox>`. Unknown props that are not in the list below will be passed to the child component.
47
47
 
48
48
  ```js
49
49
  {
@@ -65,3 +65,13 @@ These props apply to both `<Resizable>` and `<ResizableBox>`.
65
65
  resizeHandles?: ?Array<'s' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne'> = ['se']
66
66
  };
67
67
  ```
68
+
69
+ The following props can also be used on `<ResizableBox>`:
70
+
71
+ ```js
72
+ {
73
+ style?: Object
74
+ }
75
+ ```
76
+
77
+ If a `width` or `height` is passed to `<ResizableBox>`'s `style` prop, it will be ignored as it is required for internal function.
@@ -0,0 +1,245 @@
1
+ // @flow
2
+ import React from 'react';
3
+ import renderer from 'react-test-renderer';
4
+ import {shallow} from 'enzyme';
5
+ import {DraggableCore} from "react-draggable";
6
+
7
+ import Resizable from '../lib/Resizable';
8
+
9
+ describe('render Resizable', () => {
10
+ const props = {
11
+ axis: 'both',
12
+ className: 'test-classname',
13
+ draggableOpts: {},
14
+ handleSize: [20, 20],
15
+ height: 50,
16
+ lockAspectRatio: false,
17
+ maxConstraints: [Infinity, Infinity],
18
+ minConstraints: [20, 20],
19
+ onResize: jest.fn(),
20
+ onResizeStart: jest.fn(),
21
+ onResizeStop: jest.fn(),
22
+ resizeHandles: ['se', 'e'],
23
+ transformScale: 1,
24
+ width: 50,
25
+ };
26
+ const userChildren = <span className={'children'} />;
27
+ const resizableBoxChildren = <div style={{width: '50px', height: '50px'}}>{userChildren}</div>;
28
+
29
+ beforeEach(() => {
30
+ jest.clearAllMocks();
31
+ });
32
+
33
+ test('snapshot default props', () => {
34
+ const tree = renderer.create(<Resizable {...props}>{resizableBoxChildren}</Resizable>).toJSON();
35
+ expect(tree).toMatchSnapshot();
36
+ });
37
+
38
+ test('with correct props', () => {
39
+ const element = shallow(<Resizable {...props}>{resizableBoxChildren}</Resizable>);
40
+ expect(element.find('.test-classname').find('.children'));
41
+ expect(element.find(DraggableCore)).toHaveLength(2);
42
+ const cursorSe = element.find('.react-resizable-handle-se');
43
+ const cursorE = element.find('.react-resizable-handle-e');
44
+ expect(cursorSe).toHaveLength(1);
45
+ expect(cursorE).toHaveLength(1);
46
+ });
47
+
48
+ describe('and pass handle props', () => {
49
+ test('as component', () => {
50
+ const customProps = {
51
+ ...props,
52
+ resizeHandles: ['se'],
53
+ handle: <span className={'custom-component'} />
54
+ };
55
+ const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
56
+ expect(element.find('.react-resizable-handle-se')).toHaveLength(0);
57
+ expect(element.find('.custom-component')).toHaveLength(1);
58
+ });
59
+ test('as function', () => {
60
+ const customProps = {
61
+ ...props,
62
+ resizeHandles: ['se'],
63
+ handle: (h) => <span className={`custom-component-${h}`} />
64
+ };
65
+ const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
66
+ expect(element.find('.custom-component-se')).toHaveLength(1);
67
+ });
68
+ });
69
+
70
+ describe('<Resizable> props filtering', () => {
71
+ const allProps = {
72
+ ...props,
73
+ draggableOpts: {},
74
+ handle: <div />,
75
+ };
76
+
77
+ // Ensure everything in propTypes is represented here. Otherwise the next two tests are not valid
78
+ test('all intended props are in our allProps object', () => {
79
+ expect(['children', ...Object.keys(allProps)].sort()).toEqual(Object.keys(Resizable.propTypes).sort());
80
+ });
81
+
82
+ test('none of these props leak down to the child', () => {
83
+ const element = shallow(<Resizable {...allProps}><div className="foo" /></Resizable>);
84
+ expect(Object.keys(element.find('.foo').props())).toEqual(['className', 'children']);
85
+ });
86
+
87
+ test('className is constructed properly', () => {
88
+ const element = shallow(<Resizable {...allProps}><div className="foo" /></Resizable>);
89
+ expect(element.find('.foo').props().className).toEqual(`foo ${allProps.className} react-resizable`);
90
+ });
91
+ });
92
+
93
+ describe('onResize callback with modified position', () => {
94
+ const customProps = {
95
+ ...props,
96
+ resizeHandles: ['nw', 'sw' ,'ne', 'se', 'n', 's', 'w', 'e'],
97
+ };
98
+ const mockClientRect = {
99
+ left: 0,
100
+ top: 0,
101
+ };
102
+ const node = document.createElement('div');
103
+ // $FlowIgnore need to override to have control over dummy dom element
104
+ node.getBoundingClientRect = () => ({ ...mockClientRect });
105
+ const mockEvent = { };
106
+ const element = shallow(<Resizable {...customProps}>{resizableBoxChildren}</Resizable>);
107
+ const nwHandle = element.find('DraggableCore').first();
108
+
109
+ test('Gradual resizing without movement between does not modify callback', () => {
110
+ expect(props.onResize).not.toHaveBeenCalled();
111
+ nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
112
+ expect(props.onResize).lastCalledWith(
113
+ mockEvent,
114
+ expect.objectContaining({
115
+ size: {
116
+ height: 40,
117
+ width: 45,
118
+ },
119
+ })
120
+ );
121
+ });
122
+
123
+ test('Movement between callbacks modifies response values', () => {
124
+ expect(props.onResize).not.toHaveBeenCalled();
125
+
126
+ mockClientRect.top = -10; // Object moves between callbacks
127
+ nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
128
+ expect(props.onResize).lastCalledWith(
129
+ mockEvent,
130
+ expect.objectContaining({
131
+ size: {
132
+ height: 50, // No height change since deltaY is caused by clientRect moving vertically
133
+ width: 45,
134
+ },
135
+ })
136
+ );
137
+
138
+ mockClientRect.left = 20; // Object moves between callbacks
139
+ nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
140
+ expect(props.onResize).lastCalledWith(
141
+ mockEvent,
142
+ expect.objectContaining({
143
+ size: {
144
+ height: 40, // Height decreased as deltaY increases - no further top position change since last
145
+ width: 25, // Width decreased 25 - 5 from deltaX and 20 from changing position
146
+ },
147
+ })
148
+ );
149
+
150
+ props.onResize.mockClear();
151
+ mockClientRect.left -= 10; // Object moves between callbacks
152
+ mockClientRect.top -= 10; // Object moves between callbacks
153
+ nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
154
+ expect(props.onResize).not.toHaveBeenCalled();
155
+
156
+ mockClientRect.left -= 10; // Object moves between callbacks
157
+ mockClientRect.top -= 10; // Object moves between callbacks
158
+ const swHandle = element.find('DraggableCore').at(1);
159
+ swHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
160
+ expect(props.onResize).lastCalledWith(
161
+ mockEvent,
162
+ expect.objectContaining({
163
+ size: {
164
+ height: 60, // Changed since resizing from bottom doesn't cause position change
165
+ width: 50, // No change - movement has caused entire delta
166
+ },
167
+ })
168
+ );
169
+
170
+ mockClientRect.left -= 10; // Object moves between callbacks
171
+ mockClientRect.top -= 10; // Object moves between callbacks
172
+ const neHandle = element.find('DraggableCore').at(2);
173
+ neHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
174
+ expect(props.onResize).lastCalledWith(
175
+ mockEvent,
176
+ expect.objectContaining({
177
+ size: {
178
+ height: 50, // No change - movement has caused entire delta
179
+ width: 60, // Changed since resizing from right doesn't cause position change
180
+ },
181
+ })
182
+ );
183
+
184
+ mockClientRect.left -= 10; // Object moves between callbacks
185
+ mockClientRect.top -= 10; // Object moves between callbacks
186
+ const seHandle = element.find('DraggableCore').at(3);
187
+ seHandle.prop('onDrag')(mockEvent, { node, deltaX: 10, deltaY: 10 });
188
+ expect(props.onResize).lastCalledWith(
189
+ mockEvent,
190
+ expect.objectContaining({
191
+ size: {
192
+ height: 60, // Changed since resizing from right doesn't cause position change
193
+ width: 60, // Changed since resizing from right doesn't cause position change
194
+ },
195
+ })
196
+ );
197
+ });
198
+
199
+ test('use of < 1 transformScale', () => {
200
+ const element = shallow(<Resizable {...customProps} transformScale={0.5}>{resizableBoxChildren}</Resizable>);
201
+ const nwHandle = element.find('DraggableCore').first();
202
+ expect(props.onResize).not.toHaveBeenCalled();
203
+ nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
204
+ expect(props.onResize).lastCalledWith(
205
+ mockEvent,
206
+ expect.objectContaining({
207
+ size: {
208
+ // Should be doubled
209
+ height: 30,
210
+ width: 40,
211
+ },
212
+ })
213
+ );
214
+
215
+ mockClientRect.left = 20; // Object moves between callbacks
216
+ nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
217
+ expect(props.onResize).lastCalledWith(
218
+ mockEvent,
219
+ expect.objectContaining({
220
+ size: {
221
+ height: 30, // Height decreased as deltaY increases - no further top position change since last
222
+ width: 20, // Width decreased 10 from deltaX and 20 from changing position
223
+ },
224
+ })
225
+ );
226
+ });
227
+
228
+ test('use of > 1 transformScale', () => {
229
+ const element = shallow(<Resizable {...customProps} transformScale={2}>{resizableBoxChildren}</Resizable>);
230
+ const nwHandle = element.find('DraggableCore').first();
231
+ expect(props.onResize).not.toHaveBeenCalled();
232
+ nwHandle.prop('onDrag')(mockEvent, { node, deltaX: 5, deltaY: 10 });
233
+ expect(props.onResize).lastCalledWith(
234
+ mockEvent,
235
+ expect.objectContaining({
236
+ size: {
237
+ // Should be halved
238
+ height: 45,
239
+ width: 47.5,
240
+ },
241
+ })
242
+ );
243
+ });
244
+ });
245
+ });
@@ -0,0 +1,99 @@
1
+ // @flow
2
+ import React from 'react';
3
+ import renderer from 'react-test-renderer';
4
+ import {shallow} from 'enzyme';
5
+
6
+ import ResizableBox from '../lib/ResizableBox';
7
+ import Resizable from "../lib/Resizable";
8
+
9
+ describe('render ResizableBox', () => {
10
+ const props = {
11
+ axis: 'x',
12
+ draggableOpts: {},
13
+ handle: jest.fn(resizeHandle => <span className={`test-class-${resizeHandle}`} />),
14
+ handleSize: [20, 20],
15
+ height: 50,
16
+ lockAspectRatio: false,
17
+ maxConstraints: [30, 30],
18
+ minConstraints: [10, 10],
19
+ onResize: jest.fn(),
20
+ onResizeStart: jest.fn(),
21
+ onResizeStop: jest.fn(),
22
+ resizeHandles: ['w'],
23
+ transformScale: 1,
24
+ width: 50,
25
+ };
26
+ const children = <span className="children" />;
27
+
28
+ beforeEach(() => {
29
+ jest.clearAllMocks();
30
+ });
31
+
32
+ test('snapshot default props', () => {
33
+ const tree = renderer.create(<ResizableBox {...props}>{children}</ResizableBox>).toJSON();
34
+ expect(tree).toMatchSnapshot();
35
+ });
36
+
37
+ test('with correct props', () => {
38
+ const element = shallow(<ResizableBox {...props}>{children}</ResizableBox>);
39
+ expect(element.state()).toEqual({
40
+ height: 50,
41
+ propsHeight: 50,
42
+ propsWidth: 50,
43
+ width: 50,
44
+ });
45
+ const resizable = element.find(Resizable);
46
+ const fakeEvent = {persist: jest.fn()};
47
+ const data = {node: children, size: {width: 30, height: 30}, handle: 'w'};
48
+ resizable.simulate('resize', fakeEvent, data);
49
+ expect(element.state()).toEqual({
50
+ height: 30,
51
+ propsHeight: 50,
52
+ propsWidth: 50,
53
+ width: 30,
54
+ });
55
+ expect(element.find('.children')).toHaveLength(1);
56
+ expect(fakeEvent.persist).toHaveBeenCalledTimes(1);
57
+ expect(props.onResize).toHaveBeenCalledWith(fakeEvent, data);
58
+
59
+ resizable.simulate('resizeStart', fakeEvent, data);
60
+ expect(props.onResizeStart).toHaveBeenCalledWith(fakeEvent, data);
61
+
62
+ resizable.simulate('resizeStop', fakeEvent, data);
63
+ expect(props.onResizeStop).toHaveBeenCalledWith(fakeEvent, data);
64
+ });
65
+
66
+ describe('<Resizable> props filtering', () => {
67
+ // Ensure everything in propTypes is represented here. Otherwise the next two tests are not valid
68
+ test('all intended props are in our props object', () => {
69
+ expect(['children', 'className', ...Object.keys(props)].sort()).toEqual(Object.keys(Resizable.propTypes).sort());
70
+ });
71
+
72
+ test('none of these props leak down to the child', () => {
73
+ const element = shallow(<ResizableBox {...props} />);
74
+ expect(Object.keys(element.find('div').props())).toEqual(['style']);
75
+ });
76
+
77
+ test('className is constructed properly', () => {
78
+ const element = shallow(<ResizableBox {...props} className='foo' />);
79
+ expect(element.find('div').props().className).toEqual(`foo`);
80
+ });
81
+ });
82
+
83
+ test('style prop', () => {
84
+ const element = shallow(<ResizableBox {...props} style={{backgroundColor: 'red'}}>{children}</ResizableBox>);
85
+ expect(element.find('div').at(0).prop('style')).toEqual({
86
+ width: '50px',
87
+ height: '50px',
88
+ backgroundColor: 'red'
89
+ });
90
+ });
91
+
92
+ test('style prop width and height ignored', () => {
93
+ const element = shallow(<ResizableBox {...props} style={{width: 10, height: 10}}>{children}</ResizableBox>);
94
+ expect(element.find('div').at(0).prop('style')).toEqual({
95
+ width: '50px',
96
+ height: '50px',
97
+ });
98
+ });
99
+ });
@@ -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
+ `;
@@ -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
+ `;