@pie-element/drawing-response 10.3.4-next.3 → 11.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.
- package/configure/lib/button.js +23 -47
- package/configure/lib/button.js.map +1 -1
- package/configure/lib/defaults.js +2 -3
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/image-container.js +238 -327
- package/configure/lib/image-container.js.map +1 -1
- package/configure/lib/index.js +115 -182
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +194 -260
- package/configure/lib/root.js.map +1 -1
- package/configure/package.json +9 -7
- package/configure/src/__tests__/image-container.test.jsx +101 -37
- package/configure/src/__tests__/index.test.js +27 -5
- package/configure/src/__tests__/root.test.jsx +37 -21
- package/configure/src/button.jsx +14 -24
- package/configure/src/image-container.jsx +73 -77
- package/configure/src/index.js +12 -2
- package/configure/src/root.jsx +24 -25
- package/controller/lib/defaults.js +2 -3
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +39 -65
- package/controller/lib/index.js.map +1 -1
- package/controller/package.json +1 -1
- package/lib/drawing-response/button.js +35 -60
- package/lib/drawing-response/button.js.map +1 -1
- package/lib/drawing-response/constants.js +2 -3
- package/lib/drawing-response/constants.js.map +1 -1
- package/lib/drawing-response/container.js +270 -351
- package/lib/drawing-response/container.js.map +1 -1
- package/lib/drawing-response/drawable-circle.js +65 -104
- package/lib/drawing-response/drawable-circle.js.map +1 -1
- package/lib/drawing-response/drawable-eraser.js +50 -86
- package/lib/drawing-response/drawable-eraser.js.map +1 -1
- package/lib/drawing-response/drawable-free-path.js +56 -97
- package/lib/drawing-response/drawable-free-path.js.map +1 -1
- package/lib/drawing-response/drawable-helper.js +16 -28
- package/lib/drawing-response/drawable-helper.js.map +1 -1
- package/lib/drawing-response/drawable-image.js +30 -49
- package/lib/drawing-response/drawable-image.js.map +1 -1
- package/lib/drawing-response/drawable-line.js +60 -99
- package/lib/drawing-response/drawable-line.js.map +1 -1
- package/lib/drawing-response/drawable-main.js +273 -345
- package/lib/drawing-response/drawable-main.js.map +1 -1
- package/lib/drawing-response/drawable-palette.js +123 -166
- package/lib/drawing-response/drawable-palette.js.map +1 -1
- package/lib/drawing-response/drawable-rectangle.js +65 -104
- package/lib/drawing-response/drawable-rectangle.js.map +1 -1
- package/lib/drawing-response/drawable-text.js +201 -313
- package/lib/drawing-response/drawable-text.js.map +1 -1
- package/lib/drawing-response/drawable-transformer.js +36 -79
- package/lib/drawing-response/drawable-transformer.js.map +1 -1
- package/lib/drawing-response/factory.js +6 -19
- package/lib/drawing-response/factory.js.map +1 -1
- package/lib/drawing-response/icon.js +8 -24
- package/lib/drawing-response/icon.js.map +1 -1
- package/lib/drawing-response/index.js +74 -116
- package/lib/drawing-response/index.js.map +1 -1
- package/lib/index.js +51 -102
- package/lib/index.js.map +1 -1
- package/package.json +13 -12
- package/src/__tests__/drawing-index-test.jsx +90 -27
- package/src/drawing-response/__tests__/container.test.jsx +56 -36
- package/src/drawing-response/__tests__/drawing-main.test.jsx +158 -139
- package/src/drawing-response/button.jsx +23 -34
- package/src/drawing-response/container.jsx +39 -40
- package/src/drawing-response/drawable-image.jsx +17 -20
- package/src/drawing-response/drawable-main.jsx +67 -60
- package/src/drawing-response/drawable-palette.jsx +48 -54
- package/src/drawing-response/drawable-text.jsx +26 -38
- package/src/drawing-response/index.jsx +21 -20
- package/src/index.js +17 -2
- package/configure/src/__tests__/__snapshots__/image-container.test.jsx.snap +0 -45
- package/configure/src/__tests__/__snapshots__/root.test.jsx.snap +0 -185
- package/esm/configure.js +0 -16151
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -814
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -54130
- package/esm/element.js.map +0 -1
- package/esm/package.json +0 -3
- package/src/__tests__/__snapshots__/drawing-index-test.jsx.snap +0 -23
- package/src/drawing-response/__tests__/__snapshots__/container.test.jsx.snap +0 -396
- package/src/drawing-response/__tests__/__snapshots__/drawing-main.test.jsx.snap +0 -247
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
3
4
|
|
|
4
5
|
import { ImageContainer } from '../image-container';
|
|
5
6
|
|
|
@@ -15,38 +16,69 @@ jest.mock('@pie-lib/config-ui', () => ({
|
|
|
15
16
|
},
|
|
16
17
|
}));
|
|
17
18
|
|
|
19
|
+
const theme = createTheme();
|
|
20
|
+
|
|
18
21
|
describe('ImageContainer', () => {
|
|
19
22
|
const onUpdateImageDimension = jest.fn();
|
|
20
23
|
const onImageUpload = jest.fn();
|
|
21
|
-
let wrapper;
|
|
22
24
|
|
|
23
25
|
beforeEach(() => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
jest.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const renderImageContainer = (props = {}) => {
|
|
30
|
+
const defaultProps = {
|
|
26
31
|
imageUrl: 'url',
|
|
27
32
|
onUpdateImageDimension,
|
|
28
33
|
onImageUpload,
|
|
34
|
+
...props,
|
|
29
35
|
};
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
return render(
|
|
37
|
+
<ThemeProvider theme={theme}>
|
|
38
|
+
<ImageContainer {...defaultProps} />
|
|
39
|
+
</ThemeProvider>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe('rendering', () => {
|
|
44
|
+
it('renders "Replace Image" button when imageUrl is provided', () => {
|
|
45
|
+
renderImageContainer({ imageUrl: 'http://example.com/image.png' });
|
|
46
|
+
expect(screen.getByRole('button', { name: /replace image/i })).toBeInTheDocument();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders "Upload Image" button when no imageUrl', () => {
|
|
50
|
+
renderImageContainer({ imageUrl: '' });
|
|
51
|
+
// Should have two "Upload Image" buttons - one in toolbar, one in center
|
|
52
|
+
const uploadButtons = screen.getAllByRole('button', { name: /upload image/i });
|
|
53
|
+
expect(uploadButtons.length).toBeGreaterThanOrEqual(1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('shows drag and drop instruction when no image', () => {
|
|
57
|
+
renderImageContainer({ imageUrl: '' });
|
|
58
|
+
expect(screen.getByText(/drag and drop or upload image from computer/i)).toBeInTheDocument();
|
|
59
|
+
});
|
|
32
60
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
it('renders the image when imageUrl is provided', () => {
|
|
62
|
+
const { container } = renderImageContainer({ imageUrl: 'http://example.com/test.png' });
|
|
63
|
+
// Image has alt="" so it has role="presentation", query by tag instead
|
|
64
|
+
const image = container.querySelector('img');
|
|
65
|
+
expect(image).toBeInTheDocument();
|
|
66
|
+
expect(image).toHaveAttribute('src', 'http://example.com/test.png');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('does not show drag and drop instruction when image exists', () => {
|
|
70
|
+
renderImageContainer({ imageUrl: 'http://example.com/image.png' });
|
|
71
|
+
expect(screen.queryByText(/drag and drop or upload image from computer/i)).not.toBeInTheDocument();
|
|
36
72
|
});
|
|
37
73
|
});
|
|
38
74
|
|
|
39
75
|
describe('logic', () => {
|
|
40
|
-
let w;
|
|
41
76
|
let oldFileReader;
|
|
77
|
+
let dummyFileReader;
|
|
42
78
|
|
|
43
79
|
beforeAll(() => {
|
|
44
|
-
const dummyFileReader = {};
|
|
45
|
-
|
|
46
|
-
w = wrapper();
|
|
47
|
-
w.instance().resize = { addEventListener: jest.fn() };
|
|
48
|
-
|
|
49
80
|
oldFileReader = window.FileReader;
|
|
81
|
+
dummyFileReader = {};
|
|
50
82
|
|
|
51
83
|
dummyFileReader.readAsDataURL = (result) => {
|
|
52
84
|
dummyFileReader.result = result;
|
|
@@ -55,22 +87,35 @@ describe('ImageContainer', () => {
|
|
|
55
87
|
window.FileReader = jest.fn(() => dummyFileReader);
|
|
56
88
|
});
|
|
57
89
|
|
|
90
|
+
afterAll(() => {
|
|
91
|
+
window.FileReader = oldFileReader;
|
|
92
|
+
});
|
|
93
|
+
|
|
58
94
|
it('handleFileRead calls onImageUpload', () => {
|
|
59
|
-
|
|
95
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
96
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
97
|
+
|
|
98
|
+
testInstance.handleFileRead('file');
|
|
60
99
|
|
|
61
100
|
expect(onImageUpload).toBeCalled();
|
|
62
101
|
expect(onImageUpload).toHaveBeenCalledTimes(1);
|
|
63
102
|
});
|
|
64
103
|
|
|
65
104
|
it('handleUploadImage calls handleFileRead which calls onImageUpload', () => {
|
|
66
|
-
|
|
105
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
106
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
107
|
+
|
|
108
|
+
testInstance.handleUploadImage({ target: { files: ['file'] }, preventDefault: jest.fn() });
|
|
67
109
|
|
|
68
110
|
expect(onImageUpload).toBeCalled();
|
|
69
|
-
expect(onImageUpload).toHaveBeenCalledTimes(
|
|
111
|
+
expect(onImageUpload).toHaveBeenCalledTimes(1);
|
|
70
112
|
});
|
|
71
113
|
|
|
72
114
|
it('handleOnDrop calls handleFileRead which calls onImageUpload if item is file and image', () => {
|
|
73
|
-
|
|
115
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
116
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
117
|
+
|
|
118
|
+
testInstance.handleOnDrop({
|
|
74
119
|
preventDefault: jest.fn(),
|
|
75
120
|
dataTransfer: {
|
|
76
121
|
items: [
|
|
@@ -84,11 +129,14 @@ describe('ImageContainer', () => {
|
|
|
84
129
|
});
|
|
85
130
|
|
|
86
131
|
expect(onImageUpload).toBeCalledWith({ type: 'image', key: 'item' });
|
|
87
|
-
expect(onImageUpload).toHaveBeenCalledTimes(
|
|
132
|
+
expect(onImageUpload).toHaveBeenCalledTimes(1);
|
|
88
133
|
});
|
|
89
134
|
|
|
90
135
|
it("handleOnDrop calls handleFileRead which doesn't call onImageUpload if item is file but not image", () => {
|
|
91
|
-
|
|
136
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
137
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
138
|
+
|
|
139
|
+
testInstance.handleOnDrop({
|
|
92
140
|
preventDefault: jest.fn(),
|
|
93
141
|
dataTransfer: {
|
|
94
142
|
items: [
|
|
@@ -101,12 +149,16 @@ describe('ImageContainer', () => {
|
|
|
101
149
|
},
|
|
102
150
|
});
|
|
103
151
|
|
|
104
|
-
//
|
|
105
|
-
expect(onImageUpload).
|
|
152
|
+
// Should not be called since 'jpg' doesn't start with 'image'
|
|
153
|
+
expect(onImageUpload).not.toHaveBeenCalled();
|
|
106
154
|
});
|
|
107
155
|
|
|
108
156
|
it('handleOnDrop calls handleFileRead which calls onImageUpload if item is not file, but file is image', () => {
|
|
109
|
-
|
|
157
|
+
jest.clearAllMocks();
|
|
158
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
159
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
160
|
+
|
|
161
|
+
testInstance.handleOnDrop({
|
|
110
162
|
preventDefault: jest.fn(),
|
|
111
163
|
dataTransfer: {
|
|
112
164
|
items: [
|
|
@@ -120,11 +172,15 @@ describe('ImageContainer', () => {
|
|
|
120
172
|
});
|
|
121
173
|
|
|
122
174
|
expect(onImageUpload).toBeCalledWith({ type: 'image', key: 'file' });
|
|
123
|
-
expect(onImageUpload).toHaveBeenCalledTimes(
|
|
175
|
+
expect(onImageUpload).toHaveBeenCalledTimes(1);
|
|
124
176
|
});
|
|
125
177
|
|
|
126
178
|
it("handleOnDrop calls handleFileRead which doesn't call onImageUpload if item is not file and file is not image", () => {
|
|
127
|
-
|
|
179
|
+
jest.clearAllMocks();
|
|
180
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
181
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
182
|
+
|
|
183
|
+
testInstance.handleOnDrop({
|
|
128
184
|
preventDefault: jest.fn(),
|
|
129
185
|
dataTransfer: {
|
|
130
186
|
items: [
|
|
@@ -137,12 +193,15 @@ describe('ImageContainer', () => {
|
|
|
137
193
|
},
|
|
138
194
|
});
|
|
139
195
|
|
|
140
|
-
//
|
|
141
|
-
expect(onImageUpload).
|
|
196
|
+
// Should not be called since file type is 'something else', not 'image'
|
|
197
|
+
expect(onImageUpload).not.toHaveBeenCalled();
|
|
142
198
|
});
|
|
143
199
|
|
|
144
200
|
it('handleOnImageLoad calls onUpdateImageDimension', () => {
|
|
145
|
-
|
|
201
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
202
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
203
|
+
|
|
204
|
+
testInstance.handleOnImageLoad({
|
|
146
205
|
target: { offsetHeight: 50, offsetWidth: 50, naturalWidth: 50, naturalHeight: 50 },
|
|
147
206
|
});
|
|
148
207
|
|
|
@@ -152,16 +211,21 @@ describe('ImageContainer', () => {
|
|
|
152
211
|
});
|
|
153
212
|
});
|
|
154
213
|
|
|
155
|
-
it('stopResizing calls onUpdateImageDimension', () => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
214
|
+
it('stopResizing calls onUpdateImageDimension with state dimensions', () => {
|
|
215
|
+
jest.clearAllMocks();
|
|
216
|
+
const testInstance = new ImageContainer({ imageUrl: 'url', onUpdateImageDimension, onImageUpload });
|
|
217
|
+
testInstance.resize = { addEventListener: jest.fn() };
|
|
159
218
|
|
|
160
|
-
|
|
161
|
-
|
|
219
|
+
// Set state dimensions directly
|
|
220
|
+
testInstance.state = { ...testInstance.state, dimensions: { height: 75, width: 100 } };
|
|
162
221
|
|
|
163
|
-
|
|
164
|
-
|
|
222
|
+
// Call stopResizing which should use the dimensions from state
|
|
223
|
+
testInstance.stopResizing();
|
|
224
|
+
|
|
225
|
+
expect(onUpdateImageDimension).toHaveBeenCalledWith({
|
|
226
|
+
height: 75,
|
|
227
|
+
width: 100,
|
|
228
|
+
});
|
|
165
229
|
});
|
|
166
230
|
});
|
|
167
231
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
3
|
|
|
4
4
|
jest.mock('@pie-lib/config-ui', () => ({
|
|
5
5
|
choiceUtils: {
|
|
@@ -9,9 +9,20 @@ jest.mock('@pie-lib/config-ui', () => ({
|
|
|
9
9
|
Panel: (props) => <div {...props} />,
|
|
10
10
|
toggle: jest.fn(),
|
|
11
11
|
radio: jest.fn(),
|
|
12
|
+
dropdown: jest.fn(),
|
|
12
13
|
},
|
|
14
|
+
layout: {
|
|
15
|
+
ConfigLayout: (props) => <div>{props.children}</div>,
|
|
16
|
+
},
|
|
17
|
+
InputContainer: (props) => <div {...props}>{props.children}</div>,
|
|
13
18
|
}));
|
|
14
19
|
|
|
20
|
+
jest.mock('@pie-lib/editable-html', () => (props) => <div {...props} />);
|
|
21
|
+
|
|
22
|
+
jest.mock('@mui/material/Typography', () => (props) => <div {...props}>{props.children}</div>);
|
|
23
|
+
|
|
24
|
+
jest.mock('../image-container', () => (props) => <div {...props} />);
|
|
25
|
+
|
|
15
26
|
const model = () => ({
|
|
16
27
|
promptEnabled: true,
|
|
17
28
|
prompt: 'This is the question prompt',
|
|
@@ -22,8 +33,13 @@ const model = () => ({
|
|
|
22
33
|
},
|
|
23
34
|
});
|
|
24
35
|
|
|
25
|
-
jest.
|
|
26
|
-
|
|
36
|
+
const mockRender = jest.fn();
|
|
37
|
+
const mockUnmount = jest.fn();
|
|
38
|
+
jest.mock('react-dom/client', () => ({
|
|
39
|
+
createRoot: jest.fn(() => ({
|
|
40
|
+
render: mockRender,
|
|
41
|
+
unmount: mockUnmount,
|
|
42
|
+
})),
|
|
27
43
|
}));
|
|
28
44
|
|
|
29
45
|
describe('index', () => {
|
|
@@ -34,17 +50,23 @@ describe('index', () => {
|
|
|
34
50
|
|
|
35
51
|
beforeAll(() => {
|
|
36
52
|
Def = require('../index').default;
|
|
53
|
+
// Register the custom element if not already registered
|
|
54
|
+
if (!customElements.get('drawing-response-configure')) {
|
|
55
|
+
customElements.define('drawing-response-configure', Def);
|
|
56
|
+
}
|
|
37
57
|
});
|
|
38
58
|
|
|
39
59
|
beforeEach(() => {
|
|
40
|
-
|
|
60
|
+
// Create custom element using document.createElement to properly initialize
|
|
61
|
+
el = document.createElement('drawing-response-configure');
|
|
41
62
|
el.model = initialModel;
|
|
42
63
|
el.onModelChanged = onModelChanged;
|
|
43
64
|
});
|
|
44
65
|
|
|
45
66
|
describe('set model', () => {
|
|
46
67
|
it('calls ReactDOM.render', () => {
|
|
47
|
-
expect(
|
|
68
|
+
expect(createRoot).toHaveBeenCalled();
|
|
69
|
+
expect(mockRender).toHaveBeenCalled();
|
|
48
70
|
});
|
|
49
71
|
});
|
|
50
72
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
3
4
|
|
|
4
5
|
import { Root } from '../root';
|
|
5
6
|
import defaults from '../defaults';
|
|
@@ -14,8 +15,15 @@ jest.mock('@pie-lib/config-ui', () => ({
|
|
|
14
15
|
layout: {
|
|
15
16
|
ConfigLayout: (props) => <div>{props.children}</div>,
|
|
16
17
|
},
|
|
18
|
+
InputContainer: (props) => <div {...props}>{props.children}</div>,
|
|
17
19
|
}));
|
|
18
20
|
|
|
21
|
+
jest.mock('@pie-lib/editable-html', () => (props) => <div {...props} />);
|
|
22
|
+
|
|
23
|
+
jest.mock('../image-container', () => (props) => <div data-testid="image-container" {...props} />);
|
|
24
|
+
|
|
25
|
+
const theme = createTheme();
|
|
26
|
+
|
|
19
27
|
const model = {
|
|
20
28
|
prompt: 'Test Prompt',
|
|
21
29
|
promptEnabled: true,
|
|
@@ -29,40 +37,46 @@ const model = {
|
|
|
29
37
|
describe('Root', () => {
|
|
30
38
|
const onConfigurationChanged = jest.fn();
|
|
31
39
|
const onModelChanged = jest.fn();
|
|
32
|
-
let wrapper;
|
|
33
40
|
|
|
34
41
|
beforeEach(() => {
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
jest.clearAllMocks();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const renderRoot = (props = {}) => {
|
|
46
|
+
const defaultProps = {
|
|
37
47
|
model,
|
|
38
48
|
configuration: defaults.configuration,
|
|
39
49
|
onConfigurationChanged,
|
|
40
50
|
onModelChanged,
|
|
51
|
+
...props,
|
|
41
52
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
});
|
|
53
|
+
return render(
|
|
54
|
+
<ThemeProvider theme={theme}>
|
|
55
|
+
<Root {...defaultProps} />
|
|
56
|
+
</ThemeProvider>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
50
59
|
|
|
51
60
|
describe('logic', () => {
|
|
52
|
-
|
|
61
|
+
it('onPromptChanged calls onModelChanged', () => {
|
|
62
|
+
const { container } = renderRoot();
|
|
63
|
+
// Get the Root component instance by finding the component ref
|
|
64
|
+
const rootInstance = container.querySelector('[data-testid]')?.parentElement?.__reactFiber$?.return?.stateNode;
|
|
53
65
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
// Since we can't easily access instance methods in RTL, we'll verify the behavior
|
|
67
|
+
// by checking that the handler is correctly bound
|
|
68
|
+
expect(onModelChanged).not.toHaveBeenCalled();
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
// Create a new Root instance to test the method directly
|
|
71
|
+
const testInstance = new Root({ model, onModelChanged, configuration: defaults.configuration, onConfigurationChanged });
|
|
72
|
+
testInstance.onPromptChanged('New Prompt');
|
|
60
73
|
|
|
61
74
|
expect(onModelChanged).toHaveBeenCalledWith(expect.objectContaining({ prompt: 'New Prompt' }));
|
|
62
75
|
});
|
|
63
76
|
|
|
64
77
|
it('onTeacherInstructionsChanged calls onModelChanged', () => {
|
|
65
|
-
|
|
78
|
+
const testInstance = new Root({ model, onModelChanged, configuration: defaults.configuration, onConfigurationChanged });
|
|
79
|
+
testInstance.onTeacherInstructionsChanged('New Teacher Instructions');
|
|
66
80
|
|
|
67
81
|
expect(onModelChanged).toHaveBeenCalledWith(
|
|
68
82
|
expect.objectContaining({ teacherInstructions: 'New Teacher Instructions' }),
|
|
@@ -70,7 +84,8 @@ describe('Root', () => {
|
|
|
70
84
|
});
|
|
71
85
|
|
|
72
86
|
it('onUpdateImageDimension calls onModelChanged', () => {
|
|
73
|
-
|
|
87
|
+
const testInstance = new Root({ model, onModelChanged, configuration: defaults.configuration, onConfigurationChanged });
|
|
88
|
+
testInstance.onUpdateImageDimension({
|
|
74
89
|
height: 200,
|
|
75
90
|
width: 200,
|
|
76
91
|
});
|
|
@@ -86,7 +101,8 @@ describe('Root', () => {
|
|
|
86
101
|
});
|
|
87
102
|
|
|
88
103
|
it('onImageUpload calls onModelChanged', () => {
|
|
89
|
-
|
|
104
|
+
const testInstance = new Root({ model, onModelChanged, configuration: defaults.configuration, onConfigurationChanged });
|
|
105
|
+
testInstance.onImageUpload('url');
|
|
90
106
|
|
|
91
107
|
expect(onModelChanged).toHaveBeenCalledWith(expect.objectContaining({ imageUrl: 'url' }));
|
|
92
108
|
});
|
package/configure/src/button.jsx
CHANGED
|
@@ -1,43 +1,33 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
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
|
|
8
|
-
|
|
6
|
+
const StyledButton = styled(Button)({
|
|
7
|
+
marginLeft: 8,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const CustomButton = ({ label, onClick, disabled }) => (
|
|
11
|
+
<StyledButton
|
|
9
12
|
onClick={onClick}
|
|
10
13
|
disabled={disabled}
|
|
11
|
-
className={classNames(classes.addButton, className)}
|
|
12
14
|
size="small"
|
|
13
|
-
variant="contained"
|
|
14
|
-
color="default"
|
|
15
|
-
>
|
|
15
|
+
variant="contained">
|
|
16
16
|
{label}
|
|
17
|
-
</
|
|
17
|
+
</StyledButton>
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
classes: PropTypes.object.isRequired,
|
|
22
|
-
className: PropTypes.string,
|
|
20
|
+
CustomButton.propTypes = {
|
|
23
21
|
disabled: PropTypes.bool,
|
|
24
22
|
label: PropTypes.string,
|
|
25
23
|
onClick: PropTypes.func,
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
CustomButton.defaultProps = {
|
|
29
27
|
className: '',
|
|
30
28
|
disabled: false,
|
|
31
29
|
label: 'Add',
|
|
32
|
-
onClick: () => {},
|
|
30
|
+
onClick: () => { },
|
|
33
31
|
};
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
addButton: {
|
|
37
|
-
marginLeft: 8,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const ButtonStyled = withStyles(styles)(RawButton);
|
|
42
|
-
|
|
43
|
-
export default ButtonStyled;
|
|
33
|
+
export default CustomButton;
|