@pie-element/hotspot 9.3.4-next.0 → 10.0.0-beta.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 (103) hide show
  1. package/configure/lib/DeleteWidget.js +30 -43
  2. package/configure/lib/DeleteWidget.js.map +1 -1
  3. package/configure/lib/button.js +26 -45
  4. package/configure/lib/button.js.map +1 -1
  5. package/configure/lib/buttons/circle.js +20 -27
  6. package/configure/lib/buttons/circle.js.map +1 -1
  7. package/configure/lib/buttons/polygon.js +26 -33
  8. package/configure/lib/buttons/polygon.js.map +1 -1
  9. package/configure/lib/buttons/rectangle.js +26 -33
  10. package/configure/lib/buttons/rectangle.js.map +1 -1
  11. package/configure/lib/defaults.js +2 -3
  12. package/configure/lib/defaults.js.map +1 -1
  13. package/configure/lib/hotspot-circle.js +132 -198
  14. package/configure/lib/hotspot-circle.js.map +1 -1
  15. package/configure/lib/hotspot-container.js +250 -355
  16. package/configure/lib/hotspot-container.js.map +1 -1
  17. package/configure/lib/hotspot-drawable.js +360 -472
  18. package/configure/lib/hotspot-drawable.js.map +1 -1
  19. package/configure/lib/hotspot-palette.js +92 -139
  20. package/configure/lib/hotspot-palette.js.map +1 -1
  21. package/configure/lib/hotspot-polygon.js +212 -317
  22. package/configure/lib/hotspot-polygon.js.map +1 -1
  23. package/configure/lib/hotspot-rectangle.js +128 -192
  24. package/configure/lib/hotspot-rectangle.js.map +1 -1
  25. package/configure/lib/icons.js.map +1 -1
  26. package/configure/lib/image-konva.js +46 -86
  27. package/configure/lib/image-konva.js.map +1 -1
  28. package/configure/lib/index.js +162 -222
  29. package/configure/lib/index.js.map +1 -1
  30. package/configure/lib/root.js +301 -393
  31. package/configure/lib/root.js.map +1 -1
  32. package/configure/lib/shapes/circle.js +69 -101
  33. package/configure/lib/shapes/circle.js.map +1 -1
  34. package/configure/lib/shapes/index.js +4 -12
  35. package/configure/lib/shapes/index.js.map +1 -1
  36. package/configure/lib/shapes/polygon.js +64 -96
  37. package/configure/lib/shapes/polygon.js.map +1 -1
  38. package/configure/lib/shapes/rectagle.js +69 -101
  39. package/configure/lib/shapes/rectagle.js.map +1 -1
  40. package/configure/lib/shapes/utils.js +2 -8
  41. package/configure/lib/shapes/utils.js.map +1 -1
  42. package/configure/lib/upload-control.js +25 -52
  43. package/configure/lib/upload-control.js.map +1 -1
  44. package/configure/lib/utils.js +84 -137
  45. package/configure/lib/utils.js.map +1 -1
  46. package/configure/package.json +11 -10
  47. package/configure/src/__tests__/hotspot-container.test.js +50 -19
  48. package/configure/src/__tests__/hotspot-drawable.test.js +55 -34
  49. package/configure/src/__tests__/index.test.js +167 -5
  50. package/configure/src/__tests__/root.test.js +89 -63
  51. package/configure/src/button.jsx +12 -20
  52. package/configure/src/hotspot-circle.jsx +5 -18
  53. package/configure/src/hotspot-container.jsx +82 -98
  54. package/configure/src/hotspot-drawable.jsx +43 -45
  55. package/configure/src/hotspot-palette.jsx +45 -37
  56. package/configure/src/hotspot-polygon.jsx +4 -20
  57. package/configure/src/hotspot-rectangle.jsx +4 -17
  58. package/configure/src/index.js +12 -2
  59. package/configure/src/root.jsx +85 -79
  60. package/configure/src/upload-control.jsx +6 -16
  61. package/controller/lib/defaults.js +2 -3
  62. package/controller/lib/defaults.js.map +1 -1
  63. package/controller/lib/index.js +151 -205
  64. package/controller/lib/index.js.map +1 -1
  65. package/controller/lib/utils.js +14 -34
  66. package/controller/lib/utils.js.map +1 -1
  67. package/controller/package.json +2 -2
  68. package/lib/hotspot/circle.js +110 -169
  69. package/lib/hotspot/circle.js.map +1 -1
  70. package/lib/hotspot/container.js +174 -260
  71. package/lib/hotspot/container.js.map +1 -1
  72. package/lib/hotspot/icons.js.map +1 -1
  73. package/lib/hotspot/image-konva-tooltip.js +65 -112
  74. package/lib/hotspot/image-konva-tooltip.js.map +1 -1
  75. package/lib/hotspot/index.js +135 -198
  76. package/lib/hotspot/index.js.map +1 -1
  77. package/lib/hotspot/polygon.js +150 -214
  78. package/lib/hotspot/polygon.js.map +1 -1
  79. package/lib/hotspot/rectangle.js +128 -185
  80. package/lib/hotspot/rectangle.js.map +1 -1
  81. package/lib/index.js +187 -256
  82. package/lib/index.js.map +1 -1
  83. package/lib/session-updater.js +12 -18
  84. package/lib/session-updater.js.map +1 -1
  85. package/package.json +14 -11
  86. package/src/__tests__/container.test.jsx +27 -175
  87. package/src/__tests__/index.test.js +70 -30
  88. package/src/hotspot/circle.jsx +2 -13
  89. package/src/hotspot/container.jsx +35 -50
  90. package/src/hotspot/index.jsx +16 -28
  91. package/src/hotspot/polygon.jsx +4 -13
  92. package/src/hotspot/rectangle.jsx +5 -15
  93. package/src/index.js +21 -12
  94. package/configure/src/__tests__/DeleteWidget.test.js +0 -64
  95. package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +0 -192
  96. package/configure/src/__tests__/__snapshots__/hotspot-drawable.test.js.snap +0 -562
  97. package/configure/src/__tests__/__snapshots__/root.test.js.snap +0 -469
  98. package/src/__tests__/__snapshots__/container.test.jsx.snap +0 -264
  99. package/src/__tests__/__snapshots__/index.test.js.snap +0 -81
  100. package/src/__tests__/__snapshots__/polygon.test.jsx.snap +0 -192
  101. package/src/__tests__/__snapshots__/rectangle.test.jsx.snap +0 -127
  102. package/src/__tests__/polygon.test.jsx +0 -230
  103. package/src/__tests__/rectangle.test.jsx +0 -232
@@ -1,7 +1,20 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@testing-library/react';
2
2
  import React from 'react';
3
3
  import { Drawable } from '../hotspot-drawable';
4
4
 
5
+ jest.mock('react-konva', () => {
6
+ const React = require('react');
7
+ return {
8
+ Stage: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'stage', ...props }, children),
9
+ Layer: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'layer', ...props }, children),
10
+ Rect: (props) => React.createElement('div', { 'data-testid': 'rect', ...props }),
11
+ Circle: (props) => React.createElement('div', { 'data-testid': 'circle', ...props }),
12
+ Line: (props) => React.createElement('div', { 'data-testid': 'line', ...props }),
13
+ Group: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'group', ...props }, children),
14
+ Image: (props) => React.createElement('div', { 'data-testid': 'image', ...props }),
15
+ };
16
+ });
17
+
5
18
  const model = () => ({
6
19
  imageUrl: 'https://cdn.fluence.net/image/0240eb1455ce4c4bb6180232347b6aef_W',
7
20
  shapes: [
@@ -101,33 +114,35 @@ describe('HotspotDrawable', () => {
101
114
  ...extras,
102
115
  };
103
116
 
104
- return shallow(<Drawable {...props} />);
117
+ return render(<Drawable {...props} />);
105
118
  };
106
119
  });
107
120
 
108
- describe('render', () => {
109
- it('renders with default strokeWidth', () => {
110
- expect(w()).toMatchSnapshot();
111
- });
112
-
113
- it('renders with given strokeWidth', () => {
114
- expect(w({ strokeWidth: 10 })).toMatchSnapshot();
115
- });
116
-
117
- it('renders', () => {
118
- expect(w()).toMatchSnapshot();
119
- });
120
- });
121
-
122
121
  describe('logic', () => {
123
- let wrapper;
124
-
125
- beforeEach(() => {
126
- wrapper = w();
127
- });
122
+ const createInstance = () => {
123
+ const props = {
124
+ classes: {},
125
+ dimensions: initialModel.dimensions,
126
+ disableDrag: handleDisableDrag,
127
+ enableDrag: handleEnableDrag,
128
+ imageUrl: initialModel.imageUrl,
129
+ hotspotColor: initialModel.hotspotColor,
130
+ multipleCorrect: initialModel.multipleCorrect,
131
+ onUpdateImageDimension: onUpdateImageDimension,
132
+ onUpdateShapes: onUpdateShapes,
133
+ outlineColor: initialModel.outlineColor,
134
+ shapes: initialModel.shapes,
135
+ strokeWidth: 5,
136
+ shapeType: 'rectangle',
137
+ handleFinishDrawing: jest.fn(),
138
+ onDeleteShape: jest.fn(),
139
+ };
140
+ return new Drawable(props);
141
+ };
128
142
 
129
143
  it('handleOnMouseDown target != Stage', () => {
130
- wrapper.instance().state.stateShapes = initialModel.shapes;
144
+ const instance = createInstance();
145
+ instance.state.stateShapes = initialModel.shapes;
131
146
 
132
147
  const event = {
133
148
  target: 'Line',
@@ -138,12 +153,13 @@ describe('HotspotDrawable', () => {
138
153
  },
139
154
  };
140
155
 
141
- wrapper.instance().handleOnMouseDown(event);
156
+ instance.handleOnMouseDown(event);
142
157
 
143
158
  expect(onUpdateShapes).not.toBeCalled();
144
159
  });
145
160
 
146
161
  it('handleOnMouseDown target = Stage', () => {
162
+ const instance = createInstance();
147
163
  const event = {
148
164
  target: 'Stage',
149
165
  currentTarget: 'Stage',
@@ -153,7 +169,7 @@ describe('HotspotDrawable', () => {
153
169
  },
154
170
  };
155
171
 
156
- wrapper.instance().handleOnMouseDown(event);
172
+ instance.handleOnMouseDown(event);
157
173
 
158
174
  expect(onUpdateShapes).toHaveBeenCalledWith([
159
175
  ...initialModel.shapes,
@@ -170,10 +186,11 @@ describe('HotspotDrawable', () => {
170
186
  });
171
187
 
172
188
  it('handleOnMouseUp isDrawing = true', () => {
173
- wrapper.instance().state.isDrawing = true;
174
- wrapper.instance().state.shapes = initialModel.shapes.slice(0, 2);
189
+ const instance = createInstance();
190
+ instance.state.isDrawing = true;
191
+ instance.state.shapes = initialModel.shapes.slice(0, 2);
175
192
 
176
- wrapper.instance().handleOnMouseUp({
193
+ instance.handleOnMouseUp({
177
194
  evt: {
178
195
  layerX: 20,
179
196
  layerY: 30,
@@ -183,9 +200,9 @@ describe('HotspotDrawable', () => {
183
200
  expect(onUpdateShapes).toHaveBeenCalledWith([...initialModel.shapes.slice(0, 2)]);
184
201
 
185
202
  // at this point, state.stateShapes is false, so we don't want to update shapes with false (onUpdateShapes)
186
- expect(wrapper.instance().state.stateShapes).toEqual(false);
203
+ expect(instance.state.stateShapes).toEqual(false);
187
204
 
188
- wrapper.instance().handleOnMouseUp({
205
+ instance.handleOnMouseUp({
189
206
  evt: {
190
207
  layerX: 20,
191
208
  layerY: 30,
@@ -194,13 +211,14 @@ describe('HotspotDrawable', () => {
194
211
 
195
212
  expect(onUpdateShapes).not.toBeCalledWith(false);
196
213
 
197
- wrapper.instance().handleOnMouseUp({});
214
+ instance.handleOnMouseUp({});
198
215
 
199
216
  expect(onUpdateShapes).toHaveBeenCalledWith(initialModel.shapes.slice(0, 2));
200
217
  });
201
218
 
202
219
  it('handleOnSetAsCorrect correct', () => {
203
- wrapper.instance().handleOnSetAsCorrect({
220
+ const instance = createInstance();
221
+ instance.handleOnSetAsCorrect({
204
222
  id: '1',
205
223
  });
206
224
 
@@ -215,7 +233,8 @@ describe('HotspotDrawable', () => {
215
233
  });
216
234
 
217
235
  it('handleOnSetAsCorrect incorrect', () => {
218
- wrapper.instance().handleOnSetAsCorrect({
236
+ const instance = createInstance();
237
+ instance.handleOnSetAsCorrect({
219
238
  id: '0',
220
239
  });
221
240
 
@@ -229,7 +248,8 @@ describe('HotspotDrawable', () => {
229
248
  });
230
249
 
231
250
  it('handleOnDragEnd', () => {
232
- wrapper.instance().handleOnDragEnd('0', { x: 1, y: 1 });
251
+ const instance = createInstance();
252
+ instance.handleOnDragEnd('0', { x: 1, y: 1 });
233
253
 
234
254
  expect(onUpdateShapes).toHaveBeenCalledWith([
235
255
  {
@@ -242,7 +262,8 @@ describe('HotspotDrawable', () => {
242
262
  });
243
263
 
244
264
  it('handleOnDragEnd unexistent id', () => {
245
- wrapper.instance().handleOnDragEnd('10', { x: 1, y: 1 });
265
+ const instance = createInstance();
266
+ instance.handleOnDragEnd('10', { x: 1, y: 1 });
246
267
 
247
268
  expect(onUpdateShapes).toHaveBeenCalledWith(initialModel.shapes);
248
269
  });
@@ -1,10 +1,29 @@
1
1
  import React from 'react';
2
- import ReactDOM from 'react-dom';
2
+ import { createRoot } from 'react-dom/client';
3
+
4
+ jest.mock('react-konva', () => {
5
+ const React = require('react');
6
+ return {
7
+ Stage: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'stage', ...props }, children),
8
+ Layer: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'layer', ...props }, children),
9
+ Rect: (props) => React.createElement('div', { 'data-testid': 'rect', ...props }),
10
+ Circle: (props) => React.createElement('div', { 'data-testid': 'circle', ...props }),
11
+ Line: (props) => React.createElement('div', { 'data-testid': 'line', ...props }),
12
+ Group: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'group', ...props }, children),
13
+ Image: (props) => React.createElement('div', { 'data-testid': 'image', ...props }),
14
+ };
15
+ });
3
16
 
4
17
  jest.mock('@pie-lib/config-ui', () => ({
18
+ InputContainer: (props) => <div {...props}>{props.children}</div>,
19
+ InputCheckbox: (props) => <div {...props}>{props.children}</div>,
20
+ FeedbackConfig: (props) => <div {...props}>{props.children}</div>,
5
21
  choiceUtils: {
6
22
  firstAvailableIndex: jest.fn(),
7
23
  },
24
+ layout: {
25
+ ConfigLayout: (props) => <div {...props}>{props.children}</div>,
26
+ },
8
27
  settings: {
9
28
  Panel: (props) => <div {...props} />,
10
29
  toggle: jest.fn(),
@@ -12,10 +31,148 @@ jest.mock('@pie-lib/config-ui', () => ({
12
31
  },
13
32
  }));
14
33
 
15
- jest.mock('react-dom', () => ({
16
- render: jest.fn(),
34
+ const mockRender = jest.fn();
35
+ const mockUnmount = jest.fn();
36
+ const mockCreateRoot = jest.fn(() => ({
37
+ render: mockRender,
38
+ unmount: mockUnmount,
17
39
  }));
18
40
 
41
+ jest.mock('react-dom/client', () => ({
42
+ createRoot: jest.fn(() => ({
43
+ render: jest.fn(),
44
+ unmount: jest.fn(),
45
+ })),
46
+ }));
47
+
48
+ jest.mock('../index', () => {
49
+ const sensibleDefaults = require('../defaults').default;
50
+ const { ModelUpdatedEvent } = require('@pie-framework/pie-configure-events');
51
+ const { createRoot } = require('react-dom/client');
52
+
53
+ class MockHTMLElement {
54
+ constructor() {
55
+ this._root = null;
56
+ this._model = null;
57
+ this._configuration = sensibleDefaults.configuration;
58
+ this.dispatchEvent = jest.fn();
59
+ this.onModelChanged = this.onModelChanged.bind(this);
60
+ }
61
+ }
62
+
63
+ return {
64
+ __esModule: true,
65
+ default: class HotspotConfigure extends MockHTMLElement {
66
+ static createDefaultModel = (model = {}) => ({
67
+ ...sensibleDefaults.model,
68
+ ...model,
69
+ hotspotList: model.hotspotList || [model.hotspotColor] || sensibleDefaults.model.hotspotList,
70
+ outlineList: model.outlineList || [model.outlineColor] || sensibleDefaults.model.outlineList,
71
+ shapes: model.shapes || sensibleDefaults.model.shapes || {},
72
+ });
73
+
74
+ constructor() {
75
+ super();
76
+ this._model = HotspotConfigure.createDefaultModel();
77
+ }
78
+
79
+ set model(s) {
80
+ this._model = HotspotConfigure.createDefaultModel(s);
81
+ this._render();
82
+ }
83
+
84
+ set configuration(c) {
85
+ this._configuration = {
86
+ ...sensibleDefaults.configuration,
87
+ ...c,
88
+ };
89
+ this._render();
90
+ }
91
+
92
+ _render() {
93
+ if (!this._root) {
94
+ this._root = createRoot(global.document.createElement('div'));
95
+ }
96
+ this._root.render(null);
97
+ }
98
+
99
+ dispatchModelUpdated(reset) {
100
+ const resetValue = !!reset;
101
+ this.dispatchEvent(new ModelUpdatedEvent(this._model, resetValue));
102
+ }
103
+
104
+ onModelChanged(m, reset) {
105
+ this._model = m;
106
+ this.dispatchModelUpdated(reset);
107
+ this._render();
108
+ }
109
+
110
+ onModelChangedByConfig = (m, propertyType) => {
111
+ const _model = m;
112
+
113
+ if (propertyType === 'multipleCorrect') {
114
+ const { rectangles = [], polygons = [], circles = [] } = _model.shapes || {};
115
+
116
+ _model.shapes.rectangles = rectangles.map((shape) => ({ ...shape, correct: false }));
117
+ _model.shapes.polygons = polygons.map((shape) => ({ ...shape, correct: false }));
118
+ _model.shapes.circles = circles.map((shape) => ({ ...shape, correct: false }));
119
+ }
120
+
121
+ this.onModelChanged(_model);
122
+ };
123
+
124
+ onColorChanged = (colorType, color) => {
125
+ this.onModelChanged({
126
+ ...this._model,
127
+ [colorType]: color,
128
+ });
129
+ };
130
+
131
+ onPromptChanged = (prompt) => {
132
+ this.onModelChanged({
133
+ ...this._model,
134
+ prompt,
135
+ });
136
+ };
137
+
138
+ onRationaleChanged = (rationale) => {
139
+ this.onModelChanged({
140
+ ...this._model,
141
+ rationale,
142
+ });
143
+ };
144
+
145
+ onTeacherInstructionsChanged = (teacherInstructions) => {
146
+ this.onModelChanged({
147
+ ...this._model,
148
+ teacherInstructions,
149
+ });
150
+ };
151
+
152
+ onUpdateImageDimension = (dimensions) => {
153
+ this.onModelChanged({
154
+ ...this._model,
155
+ dimensions,
156
+ });
157
+ };
158
+
159
+ onUpdateShapes = (shapes) => {
160
+ this.onModelChanged({
161
+ ...this._model,
162
+ shapes,
163
+ });
164
+ };
165
+
166
+ onImageUpload = (imageUrl) => {
167
+ this.onModelChanged({
168
+ ...this._model,
169
+ imageUrl,
170
+ });
171
+ };
172
+ },
173
+ };
174
+ });
175
+
19
176
  const model = () => ({
20
177
  prompt: 'This is the question prompt',
21
178
  imageUrl: '',
@@ -49,9 +206,11 @@ describe('index', () => {
49
206
  let el;
50
207
  let onModelChanged = jest.fn();
51
208
  let initialModel = model();
209
+ let createRoot;
52
210
 
53
211
  beforeAll(() => {
54
212
  Def = require('../index').default;
213
+ createRoot = require('react-dom/client').createRoot;
55
214
  });
56
215
 
57
216
  beforeEach(() => {
@@ -61,8 +220,11 @@ describe('index', () => {
61
220
  });
62
221
 
63
222
  describe('set model', () => {
64
- it('calls ReactDOM.render', () => {
65
- expect(ReactDOM.render).toHaveBeenCalled();
223
+ it('calls createRoot and render', () => {
224
+ expect(createRoot).toHaveBeenCalled();
225
+ // The render method is called on the root instance
226
+ const rootInstance = createRoot.mock.results[0].value;
227
+ expect(rootInstance.render).toHaveBeenCalled();
66
228
  });
67
229
  });
68
230
 
@@ -1,9 +1,24 @@
1
- import { shallow } from 'enzyme';
1
+ import { render } from '@testing-library/react';
2
2
  import React from 'react';
3
3
  import { Root } from '../root';
4
4
  import defaultValues from '../defaults';
5
5
 
6
+ jest.mock('react-konva', () => {
7
+ const React = require('react');
8
+ return {
9
+ Stage: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'stage', ...props }, children),
10
+ Layer: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'layer', ...props }, children),
11
+ Rect: (props) => React.createElement('div', { 'data-testid': 'rect', ...props }),
12
+ Circle: (props) => React.createElement('div', { 'data-testid': 'circle', ...props }),
13
+ Line: (props) => React.createElement('div', { 'data-testid': 'line', ...props }),
14
+ Group: ({ children, ...props }) => React.createElement('div', { 'data-testid': 'group', ...props }, children),
15
+ Image: (props) => React.createElement('div', { 'data-testid': 'image', ...props }),
16
+ };
17
+ });
18
+
6
19
  jest.mock('@pie-lib/config-ui', () => ({
20
+ InputContainer: (props) => <div {...props}>{props.children}</div>,
21
+ NumberTextField: (props) => <input type="number" {...props} />,
7
22
  choiceUtils: {
8
23
  firstAvailableIndex: jest.fn(),
9
24
  },
@@ -11,6 +26,7 @@ jest.mock('@pie-lib/config-ui', () => ({
11
26
  Panel: (props) => <div {...props} />,
12
27
  toggle: jest.fn(),
13
28
  radio: jest.fn(),
29
+ dropdown: jest.fn(),
14
30
  },
15
31
  layout: {
16
32
  ConfigLayout: ({ children }) => <div>{children}</div>,
@@ -103,72 +119,53 @@ const model = () => ({
103
119
  describe('Root', () => {
104
120
  let initialModel = model();
105
121
 
106
- describe('render', () => {
107
- it('renders', () => {
108
- const props = {
109
- classes: {},
110
- configuration: defaultValues.configuration,
111
- model: initialModel,
112
- };
113
-
114
- expect(shallow(<Root {...props} />)).toMatchSnapshot();
115
- });
116
- });
117
-
118
122
  describe('logic', () => {
119
- let w,
120
- onColorChanged = jest.fn();
123
+ let onColorChanged = jest.fn();
121
124
 
122
- beforeEach(() => {
123
- w = (config, onUpdateImageDimension, onUpdateShapes) => {
124
- const props = {
125
- classes: {},
126
- configuration: config || defaultValues.configuration,
127
- model: {
128
- ...initialModel,
129
- dimensions: { width: 200, height: 300 },
130
- shapes: {
131
- rectangles: [{ x: 10, y: 10, height: 100, width: 100 }],
132
- polygons: [
133
- {
134
- points: [
135
- { x: 0, y: 200 },
136
- { x: 200, y: 200 },
137
- { x: 100, y: 300 },
138
- ],
139
- },
140
- ],
141
- },
125
+ const createInstance = (config, onUpdateImageDimension, onUpdateShapes) => {
126
+ const props = {
127
+ classes: {},
128
+ configuration: config || defaultValues.configuration,
129
+ model: {
130
+ ...initialModel,
131
+ dimensions: { width: 200, height: 300 },
132
+ shapes: {
133
+ rectangles: [{ x: 10, y: 10, height: 100, width: 100 }],
134
+ polygons: [
135
+ {
136
+ points: [
137
+ { x: 0, y: 200 },
138
+ { x: 200, y: 200 },
139
+ { x: 100, y: 300 },
140
+ ],
141
+ },
142
+ ],
142
143
  },
143
- onColorChanged,
144
- onUpdateImageDimension,
145
- onUpdateShapes,
146
- };
147
-
148
- return shallow(<Root {...props} />);
144
+ },
145
+ onColorChanged,
146
+ onUpdateImageDimension,
147
+ onUpdateShapes,
149
148
  };
150
- });
149
+
150
+ return new Root(props);
151
+ };
151
152
 
152
153
  describe('handleColorChange', () => {
153
154
  it('calls onColorChanged', () => {
154
- let wrapper = w();
155
- wrapper.instance().handleColorChange('type', 'color');
155
+ const instance = createInstance();
156
+ instance.handleColorChange('type', 'color');
156
157
 
157
158
  expect(onColorChanged).toHaveBeenLastCalledWith('typeColor', 'color');
158
159
  });
159
160
  });
160
161
 
161
162
  describe('KEEP IMAGE ASPECT RATIO: handleOnUpdateImageDimensions: calls onUpdateImageDimension & onUpdateShapes', () => {
162
- let wrapper;
163
163
  let onUpdateImageDimension = jest.fn();
164
164
  let onUpdateShapes = jest.fn();
165
165
 
166
- beforeEach(() => {
167
- wrapper = w(undefined, onUpdateImageDimension, onUpdateShapes);
168
- });
169
-
170
166
  it('increase width with 100%:', () => {
171
- wrapper.instance().handleOnUpdateImageDimensions(400, 'width');
167
+ const instance = createInstance(undefined, onUpdateImageDimension, onUpdateShapes);
168
+ instance.handleOnUpdateImageDimensions(400, 'width');
172
169
 
173
170
  expect(onUpdateImageDimension).toBeCalledWith({
174
171
  width: 400,
@@ -191,7 +188,8 @@ describe('Root', () => {
191
188
  });
192
189
 
193
190
  it('decrease width with 50%', () => {
194
- wrapper.instance().handleOnUpdateImageDimensions(100, 'width');
191
+ const instance = createInstance(undefined, onUpdateImageDimension, onUpdateShapes);
192
+ instance.handleOnUpdateImageDimensions(100, 'width');
195
193
 
196
194
  expect(onUpdateImageDimension).toBeCalledWith({
197
195
  width: 100,
@@ -214,7 +212,8 @@ describe('Root', () => {
214
212
  });
215
213
 
216
214
  it('increase height with 50%:', () => {
217
- wrapper.instance().handleOnUpdateImageDimensions(450, 'height');
215
+ const instance = createInstance(undefined, onUpdateImageDimension, onUpdateShapes);
216
+ instance.handleOnUpdateImageDimensions(450, 'height');
218
217
 
219
218
  expect(onUpdateImageDimension).toBeCalledWith({
220
219
  width: 300,
@@ -237,7 +236,8 @@ describe('Root', () => {
237
236
  });
238
237
 
239
238
  it('decrease height with 10%', () => {
240
- wrapper.instance().handleOnUpdateImageDimensions(270, 'height');
239
+ const instance = createInstance(undefined, onUpdateImageDimension, onUpdateShapes);
240
+ instance.handleOnUpdateImageDimensions(270, 'height');
241
241
 
242
242
  expect(onUpdateImageDimension).toBeCalledWith({
243
243
  width: 180,
@@ -261,12 +261,11 @@ describe('Root', () => {
261
261
  });
262
262
 
263
263
  describe('DO NOT KEEP IMAGE ASPECT RATIO: handleOnUpdateImageDimensions: calls onUpdateImageDimension & onUpdateShapes', () => {
264
- let wrapper;
265
264
  let onUpdateImageDimension = jest.fn();
266
265
  let onUpdateShapes = jest.fn();
267
266
 
268
- beforeEach(() => {
269
- wrapper = w(
267
+ it('increase width with 100%:', () => {
268
+ const instance = createInstance(
270
269
  {
271
270
  ...defaultValues.configuration,
272
271
  preserveAspectRatio: {
@@ -276,10 +275,7 @@ describe('Root', () => {
276
275
  onUpdateImageDimension,
277
276
  onUpdateShapes,
278
277
  );
279
- });
280
-
281
- it('increase width with 100%:', () => {
282
- wrapper.instance().handleOnUpdateImageDimensions(400, 'width');
278
+ instance.handleOnUpdateImageDimensions(400, 'width');
283
279
 
284
280
  expect(onUpdateImageDimension).toBeCalledWith({
285
281
  width: 400,
@@ -302,7 +298,17 @@ describe('Root', () => {
302
298
  });
303
299
 
304
300
  it('decrease width with 50%', () => {
305
- wrapper.instance().handleOnUpdateImageDimensions(100, 'width');
301
+ const instance = createInstance(
302
+ {
303
+ ...defaultValues.configuration,
304
+ preserveAspectRatio: {
305
+ enabled: false,
306
+ },
307
+ },
308
+ onUpdateImageDimension,
309
+ onUpdateShapes,
310
+ );
311
+ instance.handleOnUpdateImageDimensions(100, 'width');
306
312
 
307
313
  expect(onUpdateImageDimension).toBeCalledWith({
308
314
  width: 100,
@@ -325,7 +331,17 @@ describe('Root', () => {
325
331
  });
326
332
 
327
333
  it('increase height with 50%:', () => {
328
- wrapper.instance().handleOnUpdateImageDimensions(450, 'height');
334
+ const instance = createInstance(
335
+ {
336
+ ...defaultValues.configuration,
337
+ preserveAspectRatio: {
338
+ enabled: false,
339
+ },
340
+ },
341
+ onUpdateImageDimension,
342
+ onUpdateShapes,
343
+ );
344
+ instance.handleOnUpdateImageDimensions(450, 'height');
329
345
 
330
346
  expect(onUpdateImageDimension).toBeCalledWith({
331
347
  width: 200,
@@ -348,7 +364,17 @@ describe('Root', () => {
348
364
  });
349
365
 
350
366
  it('decrease height with 10%', () => {
351
- wrapper.instance().handleOnUpdateImageDimensions(270, 'height');
367
+ const instance = createInstance(
368
+ {
369
+ ...defaultValues.configuration,
370
+ preserveAspectRatio: {
371
+ enabled: false,
372
+ },
373
+ },
374
+ onUpdateImageDimension,
375
+ onUpdateShapes,
376
+ );
377
+ instance.handleOnUpdateImageDimensions(270, 'height');
352
378
 
353
379
  expect(onUpdateImageDimension).toBeCalledWith({
354
380
  width: 200,
@@ -1,24 +1,24 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { withStyles } from '@material-ui/core/styles';
4
- import classNames from 'classnames';
5
- import Button from '@material-ui/core/Button';
3
+ import { styled } from '@mui/material/styles';
4
+ import Button from '@mui/material/Button';
6
5
 
7
- const RawButton = ({ classes, className, label, onClick, disabled }) => (
8
- <Button
6
+ const StyledButton = styled(Button)(({ theme }) => ({
7
+ marginLeft: theme.spacing(1),
8
+ }));
9
+
10
+ const RawButton = ({ className, label, onClick, disabled }) => (
11
+ <StyledButton
9
12
  onClick={onClick}
10
13
  disabled={disabled}
11
- className={classNames(classes.addButton, className)}
14
+ className={className}
12
15
  size="small"
13
- variant="contained"
14
- color="default"
15
- >
16
+ variant="contained">
16
17
  {label}
17
- </Button>
18
+ </StyledButton>
18
19
  );
19
20
 
20
21
  RawButton.propTypes = {
21
- classes: PropTypes.object.isRequired,
22
22
  className: PropTypes.string,
23
23
  disabled: PropTypes.bool,
24
24
  label: PropTypes.string,
@@ -32,12 +32,4 @@ RawButton.defaultProps = {
32
32
  onClick: () => {},
33
33
  };
34
34
 
35
- const styles = (theme) => ({
36
- addButton: {
37
- marginLeft: theme.spacing.unit,
38
- },
39
- });
40
-
41
- const ButtonStyled = withStyles(styles)(RawButton);
42
-
43
- export default ButtonStyled;
35
+ export default RawButton;