@pie-lib/editable-html-tip-tap 2.1.19 → 2.1.20-beta.2
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/CHANGELOG.md +0 -130
- package/lib/components/EditableHtml.js +0 -56
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +12 -81
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +2 -2
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/common/toolbar-buttons.js +5 -6
- package/lib/components/common/toolbar-buttons.js.map +1 -1
- package/lib/components/icons/TableIcons.js +1 -3
- package/lib/components/icons/TableIcons.js.map +1 -1
- package/lib/components/icons/TextAlign.js +5 -14
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/respArea/MathTemplated.js +8 -14
- package/lib/components/respArea/MathTemplated.js.map +1 -1
- package/lib/extensions/math.js +37 -19
- package/lib/extensions/math.js.map +1 -1
- package/lib/styles/editorContainerStyles.js +2 -2
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/package.json +9 -9
- package/src/components/EditableHtml.jsx +0 -52
- package/src/components/MenuBar.jsx +9 -91
- package/src/components/TiptapContainer.jsx +2 -2
- package/src/components/common/toolbar-buttons.jsx +4 -6
- package/src/components/icons/TableIcons.jsx +1 -9
- package/src/components/icons/TextAlign.jsx +5 -39
- package/src/components/respArea/MathTemplated.jsx +6 -13
- package/src/extensions/math.js +19 -11
- package/src/styles/editorContainerStyles.js +2 -2
- package/LICENSE.md +0 -5
- package/src/__tests__/EditableHtml.test.jsx +0 -668
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/editor-attributes.test.jsx +0 -77
- package/src/__tests__/extensions.test.js +0 -208
- package/src/__tests__/index.test.jsx +0 -154
- package/src/__tests__/size-utils.test.js +0 -64
- package/src/__tests__/spellcheck.test.jsx +0 -63
- package/src/__tests__/theme.test.js +0 -17
- package/src/components/__tests__/AltDialog.test.jsx +0 -147
- package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
- package/src/components/__tests__/CssIcon.test.jsx +0 -46
- package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
- package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
- package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
- package/src/components/__tests__/InsertImageHandler.test.js +0 -161
- package/src/components/__tests__/MediaDialog.test.jsx +0 -293
- package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
- package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
- package/src/components/__tests__/MenuBar.test.jsx +0 -338
- package/src/components/__tests__/RespArea.test.jsx +0 -122
- package/src/components/__tests__/TableIcons.test.jsx +0 -149
- package/src/components/__tests__/TextAlign.test.jsx +0 -167
- package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
- package/src/components/__tests__/characterUtils.test.js +0 -166
- package/src/components/__tests__/choice.test.jsx +0 -171
- package/src/components/__tests__/custom-popper.test.jsx +0 -82
- package/src/components/__tests__/done-button.test.jsx +0 -54
- package/src/components/__tests__/toolbar-buttons.test.jsx +0 -247
- package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
- package/src/extensions/__tests__/css.test.js +0 -196
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
- package/src/extensions/__tests__/divNode.test.js +0 -87
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
- package/src/extensions/__tests__/extended-list-item.test.js +0 -13
- package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
- package/src/extensions/__tests__/extended-table.test.js +0 -183
- package/src/extensions/__tests__/image-component.test.jsx +0 -346
- package/src/extensions/__tests__/image.test.js +0 -237
- package/src/extensions/__tests__/math.test.js +0 -898
- package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
- package/src/extensions/__tests__/media.test.js +0 -271
- package/src/extensions/__tests__/responseArea.test.js +0 -655
- package/src/utils/__tests__/helper.test.js +0 -126
- package/src/utils/__tests__/toolbar.test.js +0 -43
|
@@ -1,668 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, waitFor } from '@testing-library/react';
|
|
3
|
-
import { useEditor } from '@tiptap/react';
|
|
4
|
-
import { EditableHtml } from '../components/EditableHtml';
|
|
5
|
-
import { InlineDropdownNode } from '../extensions/responseArea';
|
|
6
|
-
|
|
7
|
-
// Mock TipTap dependencies
|
|
8
|
-
jest.mock('@tiptap/react', () => ({
|
|
9
|
-
EditorContent: ({ editor, ...props }) => <div data-testid="editor-content" {...props} />,
|
|
10
|
-
useEditor: jest.fn((config) => {
|
|
11
|
-
const mockEditor = {
|
|
12
|
-
getHTML: jest.fn(() => '<p>test content</p>'),
|
|
13
|
-
setEditable: jest.fn(),
|
|
14
|
-
setOptions: jest.fn(),
|
|
15
|
-
commands: {
|
|
16
|
-
setContent: jest.fn(),
|
|
17
|
-
},
|
|
18
|
-
isActive: jest.fn(() => false),
|
|
19
|
-
isFocused: false,
|
|
20
|
-
};
|
|
21
|
-
return mockEditor;
|
|
22
|
-
}),
|
|
23
|
-
useEditorState: jest.fn(() => ({
|
|
24
|
-
isFocused: false,
|
|
25
|
-
})),
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
jest.mock('@tiptap/starter-kit', () => ({
|
|
29
|
-
__esModule: true,
|
|
30
|
-
default: {
|
|
31
|
-
configure: jest.fn(() => ({})),
|
|
32
|
-
},
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
jest.mock('@tiptap/extension-text-style', () => ({
|
|
36
|
-
TextStyleKit: {},
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
jest.mock('@tiptap/extension-character-count', () => ({
|
|
40
|
-
CharacterCount: {
|
|
41
|
-
configure: jest.fn(() => ({})),
|
|
42
|
-
},
|
|
43
|
-
}));
|
|
44
|
-
|
|
45
|
-
jest.mock('@tiptap/extension-superscript', () => ({
|
|
46
|
-
__esModule: true,
|
|
47
|
-
default: {},
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
jest.mock('@tiptap/extension-subscript', () => ({
|
|
51
|
-
__esModule: true,
|
|
52
|
-
default: {},
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
jest.mock('@tiptap/extension-text-align', () => ({
|
|
56
|
-
__esModule: true,
|
|
57
|
-
default: {
|
|
58
|
-
configure: jest.fn(() => ({})),
|
|
59
|
-
},
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
jest.mock('@tiptap/extension-image', () => ({
|
|
63
|
-
__esModule: true,
|
|
64
|
-
default: {},
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
jest.mock('@tiptap/extension-table', () => ({
|
|
68
|
-
__esModule: true,
|
|
69
|
-
default: {},
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
jest.mock('@tiptap/extension-table-row', () => ({
|
|
73
|
-
TableRow: {},
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
jest.mock('../extensions/extended-table-cell', () => ({
|
|
77
|
-
ExtendedTableCell: {},
|
|
78
|
-
ExtendedTableHeader: {},
|
|
79
|
-
}));
|
|
80
|
-
|
|
81
|
-
jest.mock('../extensions/extended-table', () => ({
|
|
82
|
-
__esModule: true,
|
|
83
|
-
default: {},
|
|
84
|
-
}));
|
|
85
|
-
|
|
86
|
-
jest.mock('../extensions/ensure-empty-root-div', () => ({
|
|
87
|
-
EnsureEmptyRootIsDiv: {},
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
jest.mock('../extensions/extended-list-item', () => ({
|
|
91
|
-
ExtendedListItem: {},
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
jest.mock('../extensions/ensure-list-item-content-is-div', () => ({
|
|
95
|
-
EnsureListItemContentIsDiv: {},
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
jest.mock('../extensions/responseArea', () => ({
|
|
99
|
-
ExplicitConstructedResponseNode: {
|
|
100
|
-
configure: jest.fn(() => ({})),
|
|
101
|
-
},
|
|
102
|
-
DragInTheBlankNode: {
|
|
103
|
-
configure: jest.fn(() => ({})),
|
|
104
|
-
},
|
|
105
|
-
InlineDropdownNode: {
|
|
106
|
-
configure: jest.fn(() => ({})),
|
|
107
|
-
},
|
|
108
|
-
MathTemplatedNode: {
|
|
109
|
-
configure: jest.fn(() => ({})),
|
|
110
|
-
},
|
|
111
|
-
ResponseAreaExtension: {
|
|
112
|
-
configure: jest.fn(() => ({})),
|
|
113
|
-
},
|
|
114
|
-
}));
|
|
115
|
-
|
|
116
|
-
jest.mock('../extensions/math', () => ({
|
|
117
|
-
MathNode: {
|
|
118
|
-
configure: jest.fn(() => ({})),
|
|
119
|
-
},
|
|
120
|
-
}));
|
|
121
|
-
|
|
122
|
-
jest.mock('../extensions/image', () => ({
|
|
123
|
-
ImageUploadNode: {
|
|
124
|
-
configure: jest.fn(() => ({})),
|
|
125
|
-
},
|
|
126
|
-
}));
|
|
127
|
-
|
|
128
|
-
jest.mock('../extensions/media', () => ({
|
|
129
|
-
Media: {
|
|
130
|
-
configure: jest.fn(() => ({})),
|
|
131
|
-
},
|
|
132
|
-
}));
|
|
133
|
-
|
|
134
|
-
jest.mock('../extensions/css', () => ({
|
|
135
|
-
CSSMark: {
|
|
136
|
-
configure: jest.fn(() => ({})),
|
|
137
|
-
},
|
|
138
|
-
}));
|
|
139
|
-
|
|
140
|
-
jest.mock('../components/TiptapContainer', () => ({
|
|
141
|
-
__esModule: true,
|
|
142
|
-
default: ({ children }) => <div data-testid="editor-container">{children}</div>,
|
|
143
|
-
}));
|
|
144
|
-
|
|
145
|
-
jest.mock('../extensions', () => ({
|
|
146
|
-
...jest.requireActual('../extensions'),
|
|
147
|
-
buildExtensions: jest.fn(() => []),
|
|
148
|
-
}));
|
|
149
|
-
|
|
150
|
-
describe('EditableHtml', () => {
|
|
151
|
-
const defaultProps = {
|
|
152
|
-
markup: '<p>Hello World</p>',
|
|
153
|
-
onChange: jest.fn(),
|
|
154
|
-
onDone: jest.fn(),
|
|
155
|
-
disabled: false,
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
beforeEach(() => {
|
|
159
|
-
jest.clearAllMocks();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('renders without crashing', () => {
|
|
163
|
-
const { container } = render(<EditableHtml {...defaultProps} />);
|
|
164
|
-
expect(container).toBeInTheDocument();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('renders editor container', () => {
|
|
168
|
-
const { getByTestId } = render(<EditableHtml {...defaultProps} />);
|
|
169
|
-
expect(getByTestId('editor-container')).toBeInTheDocument();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('renders editor content when editor is initialized', async () => {
|
|
173
|
-
const { getByTestId } = render(<EditableHtml {...defaultProps} />);
|
|
174
|
-
await waitFor(() => {
|
|
175
|
-
expect(getByTestId('editor-content')).toBeInTheDocument();
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('accepts custom toolbar options', () => {
|
|
180
|
-
const toolbarOpts = {
|
|
181
|
-
position: 'top',
|
|
182
|
-
alignment: 'center',
|
|
183
|
-
alwaysVisible: true,
|
|
184
|
-
showDone: false,
|
|
185
|
-
doneOn: 'change',
|
|
186
|
-
};
|
|
187
|
-
const { container } = render(<EditableHtml {...defaultProps} toolbarOpts={toolbarOpts} />);
|
|
188
|
-
expect(container).toBeInTheDocument();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('accepts custom active plugins', () => {
|
|
192
|
-
const activePlugins = ['bold', 'italic', 'underline'];
|
|
193
|
-
const { container } = render(<EditableHtml {...defaultProps} activePlugins={activePlugins} />);
|
|
194
|
-
expect(container).toBeInTheDocument();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('accepts plugin props', () => {
|
|
198
|
-
const pluginProps = {
|
|
199
|
-
showParagraphs: { disabled: false },
|
|
200
|
-
separateParagraphs: { disabled: false },
|
|
201
|
-
};
|
|
202
|
-
const { container } = render(<EditableHtml {...defaultProps} pluginProps={pluginProps} />);
|
|
203
|
-
expect(container).toBeInTheDocument();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('accepts response area props', () => {
|
|
207
|
-
const responseAreaProps = {
|
|
208
|
-
type: 'explicit-constructed-response',
|
|
209
|
-
options: {},
|
|
210
|
-
};
|
|
211
|
-
const { container } = render(<EditableHtml {...defaultProps} responseAreaProps={responseAreaProps} />);
|
|
212
|
-
expect(container).toBeInTheDocument();
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('passes blur done behavior to inline dropdown toolbar close', async () => {
|
|
216
|
-
const onChange = jest.fn();
|
|
217
|
-
const onDone = jest.fn();
|
|
218
|
-
const html = '<p>from inline dropdown close</p>';
|
|
219
|
-
|
|
220
|
-
render(
|
|
221
|
-
<EditableHtml
|
|
222
|
-
{...defaultProps}
|
|
223
|
-
markup="<p>Hello World</p>"
|
|
224
|
-
onChange={onChange}
|
|
225
|
-
onDone={onDone}
|
|
226
|
-
toolbarOpts={{ doneOn: 'blur' }}
|
|
227
|
-
responseAreaProps={{ type: 'inline-dropdown' }}
|
|
228
|
-
/>,
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
await waitFor(() => {
|
|
232
|
-
expect(InlineDropdownNode.configure).toHaveBeenCalled();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const configureCall = InlineDropdownNode.configure.mock.calls[InlineDropdownNode.configure.mock.calls.length - 1];
|
|
236
|
-
const inlineDropdownOptions = configureCall[0];
|
|
237
|
-
const editor = {
|
|
238
|
-
getHTML: jest.fn(() => html),
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
inlineDropdownOptions.onInlineDropdownToolbarClose(editor);
|
|
242
|
-
|
|
243
|
-
expect(editor.getHTML).toHaveBeenCalledTimes(1);
|
|
244
|
-
expect(onChange).toHaveBeenCalledWith(html);
|
|
245
|
-
expect(onDone).toHaveBeenCalledWith(html);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('accepts size props', () => {
|
|
249
|
-
const sizeProps = {
|
|
250
|
-
width: 500,
|
|
251
|
-
height: 300,
|
|
252
|
-
minHeight: 200,
|
|
253
|
-
maxHeight: 400,
|
|
254
|
-
minWidth: 300,
|
|
255
|
-
maxWidth: 600,
|
|
256
|
-
};
|
|
257
|
-
const { container } = render(<EditableHtml {...defaultProps} {...sizeProps} />);
|
|
258
|
-
expect(container).toBeInTheDocument();
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('accepts character limit', () => {
|
|
262
|
-
const { container } = render(<EditableHtml {...defaultProps} charactersLimit={500} />);
|
|
263
|
-
expect(container).toBeInTheDocument();
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('accepts image support props', () => {
|
|
267
|
-
const imageSupport = {
|
|
268
|
-
add: jest.fn(),
|
|
269
|
-
delete: jest.fn(),
|
|
270
|
-
};
|
|
271
|
-
const { container } = render(<EditableHtml {...defaultProps} imageSupport={imageSupport} />);
|
|
272
|
-
expect(container).toBeInTheDocument();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('accepts max image dimensions', () => {
|
|
276
|
-
const { container } = render(<EditableHtml {...defaultProps} maxImageWidth={800} maxImageHeight={600} />);
|
|
277
|
-
expect(container).toBeInTheDocument();
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('accepts language characters props', () => {
|
|
281
|
-
const languageCharactersProps = [
|
|
282
|
-
{ label: 'Greek', value: 'greek' },
|
|
283
|
-
{ label: 'Cyrillic', value: 'cyrillic' },
|
|
284
|
-
];
|
|
285
|
-
const { container } = render(<EditableHtml {...defaultProps} languageCharactersProps={languageCharactersProps} />);
|
|
286
|
-
expect(container).toBeInTheDocument();
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it('accepts extra CSS rules', () => {
|
|
290
|
-
const extraCSSRules = {
|
|
291
|
-
'.custom-class': { color: 'red' },
|
|
292
|
-
};
|
|
293
|
-
const { container } = render(<EditableHtml {...defaultProps} extraCSSRules={extraCSSRules} />);
|
|
294
|
-
expect(container).toBeInTheDocument();
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('accepts upload sound support', () => {
|
|
298
|
-
const uploadSoundSupport = {
|
|
299
|
-
add: jest.fn(),
|
|
300
|
-
delete: jest.fn(),
|
|
301
|
-
};
|
|
302
|
-
const { container } = render(<EditableHtml {...defaultProps} uploadSoundSupport={uploadSoundSupport} />);
|
|
303
|
-
expect(container).toBeInTheDocument();
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('accepts onKeyDown handler', () => {
|
|
307
|
-
const onKeyDown = jest.fn();
|
|
308
|
-
const { container } = render(<EditableHtml {...defaultProps} onKeyDown={onKeyDown} />);
|
|
309
|
-
expect(container).toBeInTheDocument();
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
it('accepts disableImageAlignmentButtons prop', () => {
|
|
313
|
-
const { container } = render(<EditableHtml {...defaultProps} disableImageAlignmentButtons={true} />);
|
|
314
|
-
expect(container).toBeInTheDocument();
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it('calls editorRef callback when editor is initialized', async () => {
|
|
318
|
-
const editorRef = jest.fn();
|
|
319
|
-
render(<EditableHtml {...defaultProps} editorRef={editorRef} />);
|
|
320
|
-
|
|
321
|
-
await waitFor(() => {
|
|
322
|
-
expect(editorRef).toHaveBeenCalled();
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it('calls editorRef with the editor instance', async () => {
|
|
327
|
-
const editorRef = jest.fn();
|
|
328
|
-
render(<EditableHtml {...defaultProps} editorRef={editorRef} />);
|
|
329
|
-
|
|
330
|
-
await waitFor(() => {
|
|
331
|
-
expect(editorRef).toHaveBeenCalled();
|
|
332
|
-
// Verify it was called with an object that has editor-like properties
|
|
333
|
-
const callArg = editorRef.mock.calls[0][0];
|
|
334
|
-
expect(callArg).toHaveProperty('getHTML');
|
|
335
|
-
expect(callArg).toHaveProperty('commands');
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
it('handles editorRef being undefined', () => {
|
|
340
|
-
const { container } = render(<EditableHtml {...defaultProps} editorRef={undefined} />);
|
|
341
|
-
expect(container).toBeInTheDocument();
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('applies flex display to StyledEditorContent', async () => {
|
|
345
|
-
const { getByTestId } = render(<EditableHtml {...defaultProps} />);
|
|
346
|
-
await waitFor(() => {
|
|
347
|
-
const editorContent = getByTestId('editor-content');
|
|
348
|
-
expect(editorContent).toBeInTheDocument();
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it('does not run blur onChange/onDone while an image insert flow is active', async () => {
|
|
353
|
-
jest.useFakeTimers();
|
|
354
|
-
const onChange = jest.fn();
|
|
355
|
-
const onDone = jest.fn();
|
|
356
|
-
|
|
357
|
-
render(
|
|
358
|
-
<EditableHtml
|
|
359
|
-
{...defaultProps}
|
|
360
|
-
markup="<p>Hello World</p>"
|
|
361
|
-
onChange={onChange}
|
|
362
|
-
onDone={onDone}
|
|
363
|
-
toolbarOpts={{ ...defaultProps.toolbarOpts, doneOn: 'blur' }}
|
|
364
|
-
/>,
|
|
365
|
-
);
|
|
366
|
-
|
|
367
|
-
await waitFor(() => {
|
|
368
|
-
expect(useEditor).toHaveBeenCalled();
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
372
|
-
const blurEditor = {
|
|
373
|
-
getHTML: jest.fn(() => '<p>changed</p>'),
|
|
374
|
-
schema: {},
|
|
375
|
-
_insertingImage: true,
|
|
376
|
-
_toolbarOpened: false,
|
|
377
|
-
isActive: jest.fn(() => false),
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
editorConfig.onBlur({ editor: blurEditor });
|
|
381
|
-
jest.advanceTimersByTime(200);
|
|
382
|
-
|
|
383
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
384
|
-
expect(onDone).not.toHaveBeenCalled();
|
|
385
|
-
|
|
386
|
-
jest.useRealTimers();
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it('does not run blur onChange/onDone when editor has no schema', async () => {
|
|
390
|
-
jest.useFakeTimers();
|
|
391
|
-
const onChange = jest.fn();
|
|
392
|
-
const onDone = jest.fn();
|
|
393
|
-
|
|
394
|
-
render(
|
|
395
|
-
<EditableHtml
|
|
396
|
-
{...defaultProps}
|
|
397
|
-
markup="<p>Hello World</p>"
|
|
398
|
-
onChange={onChange}
|
|
399
|
-
onDone={onDone}
|
|
400
|
-
toolbarOpts={{ doneOn: 'blur' }}
|
|
401
|
-
/>,
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
await waitFor(() => {
|
|
405
|
-
expect(useEditor).toHaveBeenCalled();
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
409
|
-
const getHTML = jest.fn(() => '<p>changed</p>');
|
|
410
|
-
const blurEditor = {
|
|
411
|
-
getHTML,
|
|
412
|
-
schema: undefined,
|
|
413
|
-
_insertingImage: false,
|
|
414
|
-
_toolbarOpened: false,
|
|
415
|
-
isActive: jest.fn(() => false),
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
editorConfig.onBlur({ editor: blurEditor });
|
|
419
|
-
jest.advanceTimersByTime(200);
|
|
420
|
-
|
|
421
|
-
expect(getHTML).not.toHaveBeenCalled();
|
|
422
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
423
|
-
expect(onDone).not.toHaveBeenCalled();
|
|
424
|
-
|
|
425
|
-
jest.useRealTimers();
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it('calls getHTML once on blur and passes the same html to onChange and onDone', async () => {
|
|
429
|
-
jest.useFakeTimers();
|
|
430
|
-
const onChange = jest.fn();
|
|
431
|
-
const onDone = jest.fn();
|
|
432
|
-
const html = '<p>from editor</p>';
|
|
433
|
-
|
|
434
|
-
render(
|
|
435
|
-
<EditableHtml
|
|
436
|
-
{...defaultProps}
|
|
437
|
-
markup="<p>Hello World</p>"
|
|
438
|
-
onChange={onChange}
|
|
439
|
-
onDone={onDone}
|
|
440
|
-
toolbarOpts={{ doneOn: 'blur' }}
|
|
441
|
-
/>,
|
|
442
|
-
);
|
|
443
|
-
|
|
444
|
-
await waitFor(() => {
|
|
445
|
-
expect(useEditor).toHaveBeenCalled();
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
449
|
-
const getHTML = jest.fn(() => html);
|
|
450
|
-
const blurEditor = {
|
|
451
|
-
getHTML,
|
|
452
|
-
schema: {},
|
|
453
|
-
_insertingImage: false,
|
|
454
|
-
_toolbarOpened: false,
|
|
455
|
-
isActive: jest.fn(() => false),
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
editorConfig.onBlur({ editor: blurEditor });
|
|
459
|
-
jest.advanceTimersByTime(200);
|
|
460
|
-
|
|
461
|
-
expect(getHTML).toHaveBeenCalledTimes(1);
|
|
462
|
-
expect(onChange).toHaveBeenCalledWith(html);
|
|
463
|
-
expect(onDone).toHaveBeenCalledWith(html);
|
|
464
|
-
|
|
465
|
-
jest.useRealTimers();
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
describe('onUpdate callback', () => {
|
|
469
|
-
it('calls onChange when transaction.isDone is true', async () => {
|
|
470
|
-
const onChange = jest.fn();
|
|
471
|
-
const markup = '<p>Initial content</p>';
|
|
472
|
-
|
|
473
|
-
render(<EditableHtml {...defaultProps} markup={markup} onChange={onChange} />);
|
|
474
|
-
|
|
475
|
-
await waitFor(() => {
|
|
476
|
-
expect(useEditor).toHaveBeenCalled();
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
480
|
-
const mockEditor = {
|
|
481
|
-
getHTML: jest.fn(() => '<p>Updated content</p>'),
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
const mockTransaction = {
|
|
485
|
-
isDone: true,
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
editorConfig.onUpdate({ editor: mockEditor, transaction: mockTransaction });
|
|
489
|
-
|
|
490
|
-
expect(onChange).toHaveBeenCalledWith('<p>Updated content</p>');
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
it('does not call onChange when transaction.isDone is false even if markup differs from editor HTML', async () => {
|
|
494
|
-
const onChange = jest.fn();
|
|
495
|
-
const markup = '<p>Initial content</p>';
|
|
496
|
-
|
|
497
|
-
render(<EditableHtml {...defaultProps} markup={markup} onChange={onChange} />);
|
|
498
|
-
|
|
499
|
-
await waitFor(() => {
|
|
500
|
-
expect(useEditor).toHaveBeenCalled();
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
504
|
-
const mockEditor = {
|
|
505
|
-
getHTML: jest.fn(() => '<p>Different content</p>'),
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
const mockTransaction = {
|
|
509
|
-
isDone: false,
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
editorConfig.onUpdate({ editor: mockEditor, transaction: mockTransaction });
|
|
513
|
-
|
|
514
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
it('does not call onChange when transaction.isDone is false and markup matches editor HTML', async () => {
|
|
518
|
-
const onChange = jest.fn();
|
|
519
|
-
const markup = '<p>Same content</p>';
|
|
520
|
-
|
|
521
|
-
render(<EditableHtml {...defaultProps} markup={markup} onChange={onChange} />);
|
|
522
|
-
|
|
523
|
-
await waitFor(() => {
|
|
524
|
-
expect(useEditor).toHaveBeenCalled();
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
528
|
-
const mockEditor = {
|
|
529
|
-
getHTML: jest.fn(() => '<p>Same content</p>'),
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
const mockTransaction = {
|
|
533
|
-
isDone: false,
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
editorConfig.onUpdate({ editor: mockEditor, transaction: mockTransaction });
|
|
537
|
-
|
|
538
|
-
expect(onChange).not.toHaveBeenCalled();
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
it('calls onChange when transaction.isDone is true even if markup matches', async () => {
|
|
542
|
-
const onChange = jest.fn();
|
|
543
|
-
const markup = '<p>Same content</p>';
|
|
544
|
-
|
|
545
|
-
render(<EditableHtml {...defaultProps} markup={markup} onChange={onChange} />);
|
|
546
|
-
|
|
547
|
-
await waitFor(() => {
|
|
548
|
-
expect(useEditor).toHaveBeenCalled();
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
552
|
-
const mockEditor = {
|
|
553
|
-
getHTML: jest.fn(() => '<p>Same content</p>'),
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
const mockTransaction = {
|
|
557
|
-
isDone: true,
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
editorConfig.onUpdate({ editor: mockEditor, transaction: mockTransaction });
|
|
561
|
-
|
|
562
|
-
expect(onChange).toHaveBeenCalledWith('<p>Same content</p>');
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
it('does not call onChange when onChange is not provided', async () => {
|
|
566
|
-
const markup = '<p>Content</p>';
|
|
567
|
-
|
|
568
|
-
render(<EditableHtml {...defaultProps} markup={markup} onChange={undefined} />);
|
|
569
|
-
|
|
570
|
-
await waitFor(() => {
|
|
571
|
-
expect(useEditor).toHaveBeenCalled();
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
575
|
-
const mockEditor = {
|
|
576
|
-
getHTML: jest.fn(() => '<p>Updated content</p>'),
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
const mockTransaction = {
|
|
580
|
-
isDone: true,
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
// Should not throw error when onChange is undefined
|
|
584
|
-
expect(() => {
|
|
585
|
-
editorConfig.onUpdate({ editor: mockEditor, transaction: mockTransaction });
|
|
586
|
-
}).not.toThrow();
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
describe('spellCheck', () => {
|
|
591
|
-
const lastEditorAttributes = () => {
|
|
592
|
-
const editorConfig = useEditor.mock.calls[useEditor.mock.calls.length - 1][0];
|
|
593
|
-
|
|
594
|
-
return editorConfig.editorProps.attributes;
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
it('disables browser spellcheck on the contenteditable when spellCheck is false', async () => {
|
|
598
|
-
render(<EditableHtml {...defaultProps} spellCheck={false} />);
|
|
599
|
-
|
|
600
|
-
await waitFor(() => {
|
|
601
|
-
expect(useEditor).toHaveBeenCalled();
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
expect(lastEditorAttributes()).toEqual({
|
|
605
|
-
role: 'textbox',
|
|
606
|
-
'data-pie-editor': 'true',
|
|
607
|
-
spellcheck: 'false',
|
|
608
|
-
autocorrect: 'off',
|
|
609
|
-
autocapitalize: 'off',
|
|
610
|
-
});
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
it('enables browser spellcheck when spellCheck is true', async () => {
|
|
614
|
-
render(<EditableHtml {...defaultProps} spellCheck={true} />);
|
|
615
|
-
|
|
616
|
-
await waitFor(() => {
|
|
617
|
-
expect(useEditor).toHaveBeenCalled();
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
expect(lastEditorAttributes()).toEqual({
|
|
621
|
-
role: 'textbox',
|
|
622
|
-
'data-pie-editor': 'true',
|
|
623
|
-
spellcheck: 'true',
|
|
624
|
-
autocorrect: 'on',
|
|
625
|
-
autocapitalize: 'on',
|
|
626
|
-
});
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
it('keeps the browser default when spellCheck is not provided', async () => {
|
|
630
|
-
render(<EditableHtml {...defaultProps} />);
|
|
631
|
-
|
|
632
|
-
await waitFor(() => {
|
|
633
|
-
expect(useEditor).toHaveBeenCalled();
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
expect(lastEditorAttributes().spellcheck).toEqual('true');
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
it('pushes spellCheck changes onto an existing editor', async () => {
|
|
640
|
-
const editorRef = jest.fn();
|
|
641
|
-
const { rerender } = render(<EditableHtml {...defaultProps} spellCheck={true} editorRef={editorRef} />);
|
|
642
|
-
|
|
643
|
-
await waitFor(() => {
|
|
644
|
-
expect(editorRef).toHaveBeenCalled();
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
rerender(<EditableHtml {...defaultProps} spellCheck={false} editorRef={editorRef} />);
|
|
648
|
-
|
|
649
|
-
await waitFor(() => {
|
|
650
|
-
expect(lastEditorAttributes().spellcheck).toEqual('false');
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
const editor = editorRef.mock.calls[editorRef.mock.calls.length - 1][0];
|
|
654
|
-
|
|
655
|
-
expect(editor.setOptions).toHaveBeenCalledWith({
|
|
656
|
-
editorProps: expect.objectContaining({
|
|
657
|
-
attributes: {
|
|
658
|
-
role: 'textbox',
|
|
659
|
-
'data-pie-editor': 'true',
|
|
660
|
-
spellcheck: 'false',
|
|
661
|
-
autocorrect: 'off',
|
|
662
|
-
autocapitalize: 'off',
|
|
663
|
-
},
|
|
664
|
-
}),
|
|
665
|
-
});
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import constants, { PIE_TOOLBAR__CLASS } from '../constants';
|
|
2
|
-
|
|
3
|
-
describe('Constants', () => {
|
|
4
|
-
describe('PIE_TOOLBAR__CLASS', () => {
|
|
5
|
-
it('is defined', () => {
|
|
6
|
-
expect(PIE_TOOLBAR__CLASS).toBeDefined();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('has the correct value', () => {
|
|
10
|
-
expect(PIE_TOOLBAR__CLASS).toBe('pie-toolbar');
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('default export', () => {
|
|
15
|
-
it('contains PIE_TOOLBAR__CLASS', () => {
|
|
16
|
-
expect(constants.PIE_TOOLBAR__CLASS).toBe('pie-toolbar');
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
});
|