@pie-lib/editable-html-tip-tap 1.1.0-next.6059 → 1.1.1-next.1
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 +44 -0
- package/lib/__tests__/EditableHtml.test.js +374 -0
- package/lib/__tests__/constants.test.js +28 -0
- package/lib/__tests__/extensions.test.js +214 -0
- package/lib/__tests__/index.test.js +246 -0
- package/lib/__tests__/size-utils.test.js +57 -0
- package/lib/__tests__/theme.test.js +17 -0
- package/lib/components/CharacterPicker.js +18 -0
- package/lib/components/CharacterPicker.js.map +1 -1
- package/lib/components/EditableHtml.js +22 -5
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +17 -0
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +16 -0
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/__tests__/AltDialog.test.js +201 -0
- package/lib/components/__tests__/CharacterPicker.test.js +313 -0
- package/lib/components/__tests__/CssIcon.test.js +58 -0
- package/lib/components/__tests__/DragInTheBlank.test.js +309 -0
- package/lib/components/__tests__/ExplicitConstructedResponse.test.js +263 -0
- package/lib/components/__tests__/ImageToolbar.test.js +195 -0
- package/lib/components/__tests__/InlineDropdown.test.js +297 -0
- package/lib/components/__tests__/InsertImageHandler.test.js +162 -0
- package/lib/components/__tests__/MediaDialog.test.js +435 -0
- package/lib/components/__tests__/MediaToolbar.test.js +126 -0
- package/lib/components/__tests__/MediaWrapper.test.js +96 -0
- package/lib/components/__tests__/MenuBar.test.js +459 -0
- package/lib/components/__tests__/RespArea.test.js +171 -0
- package/lib/components/__tests__/TableIcons.test.js +153 -0
- package/lib/components/__tests__/TextAlign.test.js +216 -0
- package/lib/components/__tests__/TiptapContainer.test.js +196 -0
- package/lib/components/__tests__/characterUtils.test.js +189 -0
- package/lib/components/__tests__/choice.test.js +213 -0
- package/lib/components/__tests__/custom-popper.test.js +108 -0
- package/lib/components/__tests__/done-button.test.js +72 -0
- package/lib/components/__tests__/toolbar-buttons.test.js +277 -0
- package/lib/components/characters/characterUtils.js +2 -0
- package/lib/components/characters/characterUtils.js.map +1 -1
- package/lib/components/characters/custom-popper.js +1 -0
- package/lib/components/characters/custom-popper.js.map +1 -1
- package/lib/components/common/done-button.js +1 -0
- package/lib/components/common/done-button.js.map +1 -1
- package/lib/components/common/toolbar-buttons.js +12 -0
- package/lib/components/common/toolbar-buttons.js.map +1 -1
- package/lib/components/icons/CssIcon.js +1 -0
- package/lib/components/icons/CssIcon.js.map +1 -1
- package/lib/components/icons/RespArea.js +10 -0
- package/lib/components/icons/RespArea.js.map +1 -1
- package/lib/components/icons/TableIcons.js +1 -0
- package/lib/components/icons/TableIcons.js.map +1 -1
- package/lib/components/icons/TextAlign.js +7 -0
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/image/AltDialog.js +5 -0
- package/lib/components/image/AltDialog.js.map +1 -1
- package/lib/components/image/ImageToolbar.js +13 -0
- package/lib/components/image/ImageToolbar.js.map +1 -1
- package/lib/components/image/InsertImageHandler.js +10 -0
- package/lib/components/image/InsertImageHandler.js.map +1 -1
- package/lib/components/media/MediaDialog.js +18 -0
- package/lib/components/media/MediaDialog.js.map +1 -1
- package/lib/components/media/MediaToolbar.js +2 -0
- package/lib/components/media/MediaToolbar.js.map +1 -1
- package/lib/components/media/MediaWrapper.js +11 -0
- package/lib/components/media/MediaWrapper.js.map +1 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +10 -0
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -1
- package/lib/components/respArea/DragInTheBlank/choice.js +8 -0
- package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -1
- package/lib/components/respArea/ExplicitConstructedResponse.js +8 -0
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -1
- package/lib/components/respArea/InlineDropdown.js +7 -0
- package/lib/components/respArea/InlineDropdown.js.map +1 -1
- package/lib/components/respArea/ToolbarIcon.js +10 -0
- package/lib/components/respArea/ToolbarIcon.js.map +1 -1
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/extensions/__tests__/component.test.js +314 -0
- package/lib/extensions/__tests__/css.test.js +218 -0
- package/lib/extensions/__tests__/custom-toolbar-wrapper.test.js +185 -0
- package/lib/extensions/__tests__/extended-table.test.js +114 -0
- package/lib/extensions/__tests__/image.test.js +178 -0
- package/lib/extensions/__tests__/media.test.js +296 -0
- package/lib/extensions/__tests__/responseArea.test.js +332 -0
- package/lib/extensions/component.js +22 -2
- package/lib/extensions/css.js +11 -0
- package/lib/extensions/css.js.map +1 -1
- package/lib/extensions/custom-toolbar-wrapper.js +15 -0
- package/lib/extensions/custom-toolbar-wrapper.js.map +1 -1
- package/lib/extensions/extended-table.js +4 -0
- package/lib/extensions/extended-table.js.map +1 -1
- package/lib/extensions/image-component.js +314 -0
- package/lib/extensions/image-component.js.map +1 -0
- package/lib/extensions/image.js +13 -2
- package/lib/extensions/image.js.map +1 -1
- package/lib/extensions/index.js +12 -2
- package/lib/extensions/index.js.map +1 -1
- package/lib/extensions/math.js +16 -0
- package/lib/extensions/math.js.map +1 -1
- package/lib/extensions/media.js +15 -0
- package/lib/extensions/media.js.map +1 -1
- package/lib/extensions/responseArea.js +22 -0
- package/lib/extensions/responseArea.js.map +1 -1
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib/styles/editorContainerStyles.js +1 -0
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/lib/theme.js +1 -0
- package/lib/theme.js.map +1 -1
- package/lib/utils/size.js +6 -0
- package/lib/utils/size.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/EditableHtml.test.jsx +266 -0
- package/src/__tests__/constants.test.js +20 -0
- package/src/__tests__/extensions.test.js +208 -0
- package/src/__tests__/index.test.jsx +146 -0
- package/src/__tests__/size-utils.test.js +64 -0
- package/src/__tests__/theme.test.js +17 -0
- package/src/components/EditableHtml.jsx +8 -6
- package/src/components/__tests__/AltDialog.test.jsx +147 -0
- package/src/components/__tests__/CharacterPicker.test.jsx +195 -0
- package/src/components/__tests__/CssIcon.test.jsx +46 -0
- package/src/components/__tests__/DragInTheBlank.test.jsx +255 -0
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +161 -0
- package/src/components/__tests__/ImageToolbar.test.jsx +128 -0
- package/src/components/__tests__/InlineDropdown.test.jsx +187 -0
- package/src/components/__tests__/InsertImageHandler.test.js +154 -0
- package/src/components/__tests__/MediaDialog.test.jsx +293 -0
- package/src/components/__tests__/MediaToolbar.test.jsx +74 -0
- package/src/components/__tests__/MediaWrapper.test.jsx +81 -0
- package/src/components/__tests__/MenuBar.test.jsx +217 -0
- package/src/components/__tests__/RespArea.test.jsx +122 -0
- package/src/components/__tests__/TableIcons.test.jsx +149 -0
- package/src/components/__tests__/TextAlign.test.jsx +167 -0
- package/src/components/__tests__/TiptapContainer.test.jsx +138 -0
- package/src/components/__tests__/characterUtils.test.js +166 -0
- package/src/components/__tests__/choice.test.jsx +171 -0
- package/src/components/__tests__/custom-popper.test.jsx +82 -0
- package/src/components/__tests__/done-button.test.jsx +54 -0
- package/src/components/__tests__/toolbar-buttons.test.jsx +234 -0
- package/src/extensions/__tests__/css.test.js +196 -0
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +180 -0
- package/src/extensions/__tests__/extended-table.test.js +107 -0
- package/src/extensions/__tests__/image-component.test.jsx +249 -0
- package/src/extensions/__tests__/image.test.js +136 -0
- package/src/extensions/__tests__/media.test.js +270 -0
- package/src/extensions/__tests__/responseArea.test.js +310 -0
- package/src/extensions/{component.jsx → image-component.jsx} +11 -1
- package/src/extensions/image.js +1 -1
- package/src/extensions/index.js +5 -1
- package/LICENSE.md +0 -5
- package/NEXT.CHANGELOG.json +0 -1
- package/lib/extensions/component.js.map +0 -1
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, waitFor } from '@testing-library/react';
|
|
3
|
+
import { EditableHtml } from '../components/EditableHtml';
|
|
4
|
+
|
|
5
|
+
// Mock TipTap dependencies
|
|
6
|
+
jest.mock('@tiptap/react', () => ({
|
|
7
|
+
EditorContent: ({ editor, ...props }) => <div data-testid="editor-content" {...props} />,
|
|
8
|
+
useEditor: jest.fn((config) => {
|
|
9
|
+
const mockEditor = {
|
|
10
|
+
getHTML: jest.fn(() => '<p>test content</p>'),
|
|
11
|
+
setEditable: jest.fn(),
|
|
12
|
+
commands: {
|
|
13
|
+
setContent: jest.fn(),
|
|
14
|
+
},
|
|
15
|
+
isActive: jest.fn(() => false),
|
|
16
|
+
isFocused: false,
|
|
17
|
+
};
|
|
18
|
+
return mockEditor;
|
|
19
|
+
}),
|
|
20
|
+
useEditorState: jest.fn(() => ({
|
|
21
|
+
isFocused: false,
|
|
22
|
+
})),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
jest.mock('@tiptap/starter-kit', () => ({
|
|
26
|
+
__esModule: true,
|
|
27
|
+
default: {},
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
jest.mock('@tiptap/extension-text-style', () => ({
|
|
31
|
+
TextStyleKit: {},
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
jest.mock('@tiptap/extension-character-count', () => ({
|
|
35
|
+
CharacterCount: {
|
|
36
|
+
configure: jest.fn(() => ({})),
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
jest.mock('@tiptap/extension-superscript', () => ({
|
|
41
|
+
__esModule: true,
|
|
42
|
+
default: {},
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
jest.mock('@tiptap/extension-subscript', () => ({
|
|
46
|
+
__esModule: true,
|
|
47
|
+
default: {},
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
jest.mock('@tiptap/extension-text-align', () => ({
|
|
51
|
+
__esModule: true,
|
|
52
|
+
default: {
|
|
53
|
+
configure: jest.fn(() => ({})),
|
|
54
|
+
},
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
jest.mock('@tiptap/extension-image', () => ({
|
|
58
|
+
__esModule: true,
|
|
59
|
+
default: {},
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
jest.mock('@tiptap/extension-table', () => ({
|
|
63
|
+
__esModule: true,
|
|
64
|
+
default: {},
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
jest.mock('@tiptap/extension-table-row', () => ({
|
|
68
|
+
TableRow: {},
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
jest.mock('@tiptap/extension-table-cell', () => ({
|
|
72
|
+
TableCell: {},
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
jest.mock('@tiptap/extension-table-header', () => ({
|
|
76
|
+
TableHeader: {},
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
jest.mock('../extensions/extended-table', () => ({
|
|
80
|
+
__esModule: true,
|
|
81
|
+
default: {},
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
jest.mock('../extensions/responseArea', () => ({
|
|
85
|
+
ExplicitConstructedResponseNode: {
|
|
86
|
+
configure: jest.fn(() => ({})),
|
|
87
|
+
},
|
|
88
|
+
DragInTheBlankNode: {
|
|
89
|
+
configure: jest.fn(() => ({})),
|
|
90
|
+
},
|
|
91
|
+
InlineDropdownNode: {
|
|
92
|
+
configure: jest.fn(() => ({})),
|
|
93
|
+
},
|
|
94
|
+
ResponseAreaExtension: {
|
|
95
|
+
configure: jest.fn(() => ({})),
|
|
96
|
+
},
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
jest.mock('../extensions/math', () => ({
|
|
100
|
+
MathNode: {
|
|
101
|
+
configure: jest.fn(() => ({})),
|
|
102
|
+
},
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
jest.mock('../extensions/image', () => ({
|
|
106
|
+
ImageUploadNode: {
|
|
107
|
+
configure: jest.fn(() => ({})),
|
|
108
|
+
},
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
jest.mock('../extensions/media', () => ({
|
|
112
|
+
Media: {
|
|
113
|
+
configure: jest.fn(() => ({})),
|
|
114
|
+
},
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
jest.mock('../extensions/css', () => ({
|
|
118
|
+
CSSMark: {
|
|
119
|
+
configure: jest.fn(() => ({})),
|
|
120
|
+
},
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
jest.mock('../components/TiptapContainer', () => ({
|
|
124
|
+
__esModule: true,
|
|
125
|
+
default: ({ children }) => <div data-testid="editor-container">{children}</div>,
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
jest.mock('../extensions', () => ({
|
|
129
|
+
...jest.requireActual('../extensions'),
|
|
130
|
+
buildExtensions: jest.fn(() => []),
|
|
131
|
+
}));
|
|
132
|
+
|
|
133
|
+
describe('EditableHtml', () => {
|
|
134
|
+
const defaultProps = {
|
|
135
|
+
markup: '<p>Hello World</p>',
|
|
136
|
+
onChange: jest.fn(),
|
|
137
|
+
onDone: jest.fn(),
|
|
138
|
+
disabled: false,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
jest.clearAllMocks();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('renders without crashing', () => {
|
|
146
|
+
const { container } = render(<EditableHtml {...defaultProps} />);
|
|
147
|
+
expect(container).toBeInTheDocument();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('renders editor container', () => {
|
|
151
|
+
const { getByTestId } = render(<EditableHtml {...defaultProps} />);
|
|
152
|
+
expect(getByTestId('editor-container')).toBeInTheDocument();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('renders editor content when editor is initialized', async () => {
|
|
156
|
+
const { getByTestId } = render(<EditableHtml {...defaultProps} />);
|
|
157
|
+
await waitFor(() => {
|
|
158
|
+
expect(getByTestId('editor-content')).toBeInTheDocument();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('accepts custom toolbar options', () => {
|
|
163
|
+
const toolbarOpts = {
|
|
164
|
+
position: 'top',
|
|
165
|
+
alignment: 'center',
|
|
166
|
+
alwaysVisible: true,
|
|
167
|
+
showDone: false,
|
|
168
|
+
doneOn: 'change',
|
|
169
|
+
};
|
|
170
|
+
const { container } = render(<EditableHtml {...defaultProps} toolbarOpts={toolbarOpts} />);
|
|
171
|
+
expect(container).toBeInTheDocument();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('accepts custom active plugins', () => {
|
|
175
|
+
const activePlugins = ['bold', 'italic', 'underline'];
|
|
176
|
+
const { container } = render(<EditableHtml {...defaultProps} activePlugins={activePlugins} />);
|
|
177
|
+
expect(container).toBeInTheDocument();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('accepts plugin props', () => {
|
|
181
|
+
const pluginProps = {
|
|
182
|
+
showParagraphs: { disabled: false },
|
|
183
|
+
separateParagraphs: { disabled: false },
|
|
184
|
+
};
|
|
185
|
+
const { container } = render(<EditableHtml {...defaultProps} pluginProps={pluginProps} />);
|
|
186
|
+
expect(container).toBeInTheDocument();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('accepts response area props', () => {
|
|
190
|
+
const responseAreaProps = {
|
|
191
|
+
type: 'explicit-constructed-response',
|
|
192
|
+
options: {},
|
|
193
|
+
};
|
|
194
|
+
const { container } = render(<EditableHtml {...defaultProps} responseAreaProps={responseAreaProps} />);
|
|
195
|
+
expect(container).toBeInTheDocument();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('accepts size props', () => {
|
|
199
|
+
const sizeProps = {
|
|
200
|
+
width: 500,
|
|
201
|
+
height: 300,
|
|
202
|
+
minHeight: 200,
|
|
203
|
+
maxHeight: 400,
|
|
204
|
+
minWidth: 300,
|
|
205
|
+
maxWidth: 600,
|
|
206
|
+
};
|
|
207
|
+
const { container } = render(<EditableHtml {...defaultProps} {...sizeProps} />);
|
|
208
|
+
expect(container).toBeInTheDocument();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('accepts character limit', () => {
|
|
212
|
+
const { container } = render(<EditableHtml {...defaultProps} charactersLimit={500} />);
|
|
213
|
+
expect(container).toBeInTheDocument();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('accepts image support props', () => {
|
|
217
|
+
const imageSupport = {
|
|
218
|
+
add: jest.fn(),
|
|
219
|
+
delete: jest.fn(),
|
|
220
|
+
};
|
|
221
|
+
const { container } = render(<EditableHtml {...defaultProps} imageSupport={imageSupport} />);
|
|
222
|
+
expect(container).toBeInTheDocument();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('accepts max image dimensions', () => {
|
|
226
|
+
const { container } = render(<EditableHtml {...defaultProps} maxImageWidth={800} maxImageHeight={600} />);
|
|
227
|
+
expect(container).toBeInTheDocument();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('accepts language characters props', () => {
|
|
231
|
+
const languageCharactersProps = [
|
|
232
|
+
{ label: 'Greek', value: 'greek' },
|
|
233
|
+
{ label: 'Cyrillic', value: 'cyrillic' },
|
|
234
|
+
];
|
|
235
|
+
const { container } = render(<EditableHtml {...defaultProps} languageCharactersProps={languageCharactersProps} />);
|
|
236
|
+
expect(container).toBeInTheDocument();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('accepts extra CSS rules', () => {
|
|
240
|
+
const extraCSSRules = {
|
|
241
|
+
'.custom-class': { color: 'red' },
|
|
242
|
+
};
|
|
243
|
+
const { container } = render(<EditableHtml {...defaultProps} extraCSSRules={extraCSSRules} />);
|
|
244
|
+
expect(container).toBeInTheDocument();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('accepts upload sound support', () => {
|
|
248
|
+
const uploadSoundSupport = {
|
|
249
|
+
add: jest.fn(),
|
|
250
|
+
delete: jest.fn(),
|
|
251
|
+
};
|
|
252
|
+
const { container } = render(<EditableHtml {...defaultProps} uploadSoundSupport={uploadSoundSupport} />);
|
|
253
|
+
expect(container).toBeInTheDocument();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('accepts onKeyDown handler', () => {
|
|
257
|
+
const onKeyDown = jest.fn();
|
|
258
|
+
const { container } = render(<EditableHtml {...defaultProps} onKeyDown={onKeyDown} />);
|
|
259
|
+
expect(container).toBeInTheDocument();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('accepts disableImageAlignmentButtons prop', () => {
|
|
263
|
+
const { container } = render(<EditableHtml {...defaultProps} disableImageAlignmentButtons={true} />);
|
|
264
|
+
expect(container).toBeInTheDocument();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PIE_TOOLBAR__CLASS } from '../constants';
|
|
2
|
+
import constants from '../constants';
|
|
3
|
+
|
|
4
|
+
describe('Constants', () => {
|
|
5
|
+
describe('PIE_TOOLBAR__CLASS', () => {
|
|
6
|
+
it('is defined', () => {
|
|
7
|
+
expect(PIE_TOOLBAR__CLASS).toBeDefined();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('has the correct value', () => {
|
|
11
|
+
expect(PIE_TOOLBAR__CLASS).toBe('pie-toolbar');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('default export', () => {
|
|
16
|
+
it('contains PIE_TOOLBAR__CLASS', () => {
|
|
17
|
+
expect(constants.PIE_TOOLBAR__CLASS).toBe('pie-toolbar');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { buildExtensions, ALL_PLUGINS, DEFAULT_PLUGINS } from '../extensions';
|
|
2
|
+
|
|
3
|
+
describe('Extensions', () => {
|
|
4
|
+
describe('ALL_PLUGINS', () => {
|
|
5
|
+
it('contains all expected plugins', () => {
|
|
6
|
+
expect(ALL_PLUGINS).toContain('bold');
|
|
7
|
+
expect(ALL_PLUGINS).toContain('italic');
|
|
8
|
+
expect(ALL_PLUGINS).toContain('underline');
|
|
9
|
+
expect(ALL_PLUGINS).toContain('strikethrough');
|
|
10
|
+
expect(ALL_PLUGINS).toContain('bulleted-list');
|
|
11
|
+
expect(ALL_PLUGINS).toContain('numbered-list');
|
|
12
|
+
expect(ALL_PLUGINS).toContain('image');
|
|
13
|
+
expect(ALL_PLUGINS).toContain('math');
|
|
14
|
+
expect(ALL_PLUGINS).toContain('languageCharacters');
|
|
15
|
+
expect(ALL_PLUGINS).toContain('text-align');
|
|
16
|
+
expect(ALL_PLUGINS).toContain('table');
|
|
17
|
+
expect(ALL_PLUGINS).toContain('video');
|
|
18
|
+
expect(ALL_PLUGINS).toContain('audio');
|
|
19
|
+
expect(ALL_PLUGINS).toContain('responseArea');
|
|
20
|
+
expect(ALL_PLUGINS).toContain('superscript');
|
|
21
|
+
expect(ALL_PLUGINS).toContain('subscript');
|
|
22
|
+
expect(ALL_PLUGINS).toContain('h3');
|
|
23
|
+
expect(ALL_PLUGINS).toContain('blockquote');
|
|
24
|
+
expect(ALL_PLUGINS).toContain('undo');
|
|
25
|
+
expect(ALL_PLUGINS).toContain('redo');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('DEFAULT_PLUGINS', () => {
|
|
30
|
+
it('excludes responseArea, h3, and blockquote', () => {
|
|
31
|
+
expect(DEFAULT_PLUGINS).not.toContain('responseArea');
|
|
32
|
+
expect(DEFAULT_PLUGINS).not.toContain('h3');
|
|
33
|
+
expect(DEFAULT_PLUGINS).not.toContain('blockquote');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('contains basic formatting plugins', () => {
|
|
37
|
+
expect(DEFAULT_PLUGINS).toContain('bold');
|
|
38
|
+
expect(DEFAULT_PLUGINS).toContain('italic');
|
|
39
|
+
expect(DEFAULT_PLUGINS).toContain('underline');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('buildExtensions', () => {
|
|
44
|
+
it('returns an array when called with default parameters', () => {
|
|
45
|
+
const result = buildExtensions(DEFAULT_PLUGINS, [], {});
|
|
46
|
+
expect(Array.isArray(result)).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('includes only active extensions', () => {
|
|
50
|
+
const activeExtensions = ['bold', 'italic'];
|
|
51
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
52
|
+
expect(result).toEqual(['bold', 'italic']);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('filters out undefined values', () => {
|
|
56
|
+
const result = buildExtensions(['bold', 'italic'], [], {});
|
|
57
|
+
expect(result.every((item) => item !== undefined)).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('excludes image plugin when opts.image.onDelete is not provided', () => {
|
|
61
|
+
const activeExtensions = ['image'];
|
|
62
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
63
|
+
expect(result).not.toContain('image');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('includes image plugin when opts.image.delete is provided', () => {
|
|
67
|
+
const activeExtensions = ['image'];
|
|
68
|
+
const opts = { image: { delete: jest.fn() } };
|
|
69
|
+
const result = buildExtensions(activeExtensions, [], opts);
|
|
70
|
+
expect(result).toContain('image');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('excludes math plugin when opts.math is not provided', () => {
|
|
74
|
+
const activeExtensions = ['math'];
|
|
75
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
76
|
+
expect(result).not.toContain('math');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('includes math plugin when opts.math is provided', () => {
|
|
80
|
+
const activeExtensions = ['math'];
|
|
81
|
+
const opts = { math: {} };
|
|
82
|
+
const result = buildExtensions(activeExtensions, [], opts);
|
|
83
|
+
expect(result).toContain('math');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('excludes responseArea plugin when opts.responseArea.type is not provided', () => {
|
|
87
|
+
const activeExtensions = ['responseArea'];
|
|
88
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
89
|
+
expect(result).not.toContain('responseArea');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('includes responseArea plugin when opts.responseArea.type is provided', () => {
|
|
93
|
+
const activeExtensions = ['responseArea'];
|
|
94
|
+
const opts = { responseArea: { type: 'explicit-constructed-response' } };
|
|
95
|
+
const result = buildExtensions(activeExtensions, [], opts);
|
|
96
|
+
expect(result).toContain('responseArea');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('excludes css plugin when opts.extraCSSRules is empty', () => {
|
|
100
|
+
const activeExtensions = ['css'];
|
|
101
|
+
const result = buildExtensions(activeExtensions, [], { extraCSSRules: {} });
|
|
102
|
+
expect(result).not.toContain('css');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('includes css plugin when opts.extraCSSRules has values', () => {
|
|
106
|
+
const activeExtensions = ['css'];
|
|
107
|
+
const opts = { extraCSSRules: { color: 'red' } };
|
|
108
|
+
const result = buildExtensions(activeExtensions, [], opts);
|
|
109
|
+
expect(result).toContain('css');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('excludes html plugin when opts.html is not provided', () => {
|
|
113
|
+
const activeExtensions = ['html'];
|
|
114
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
115
|
+
expect(result).not.toContain('html');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('includes html plugin when opts.html is provided', () => {
|
|
119
|
+
const activeExtensions = ['html'];
|
|
120
|
+
const opts = { html: true };
|
|
121
|
+
const result = buildExtensions(activeExtensions, [], opts);
|
|
122
|
+
expect(result).toContain('html');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('handles languageCharacters plugins array', () => {
|
|
126
|
+
const activeExtensions = ['languageCharacters'];
|
|
127
|
+
const opts = {
|
|
128
|
+
languageCharacters: [
|
|
129
|
+
{ label: 'Greek', value: 'greek' },
|
|
130
|
+
{ label: 'Cyrillic', value: 'cyrillic' },
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
const result = buildExtensions(activeExtensions, [], opts);
|
|
134
|
+
// Should include languageCharacters for each item in the array
|
|
135
|
+
const languageCharsCount = result.filter((item) => item === 'languageCharacters').length;
|
|
136
|
+
expect(languageCharsCount).toBe(2);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('uses DEFAULT_PLUGINS when activeExtensions is not provided', () => {
|
|
140
|
+
const result = buildExtensions(null, [], {});
|
|
141
|
+
expect(Array.isArray(result)).toBe(true);
|
|
142
|
+
expect(result.length).toBeGreaterThan(0);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('includes list plugins', () => {
|
|
146
|
+
const activeExtensions = ['bulleted-list', 'numbered-list'];
|
|
147
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
148
|
+
expect(result).toContain('bulleted-list');
|
|
149
|
+
expect(result).toContain('numbered-list');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('includes undo and redo plugins', () => {
|
|
153
|
+
const activeExtensions = ['undo', 'redo'];
|
|
154
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
155
|
+
expect(result).toContain('undo');
|
|
156
|
+
expect(result).toContain('redo');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('includes text formatting plugins', () => {
|
|
160
|
+
const activeExtensions = ['superscript', 'subscript', 'strikethrough', 'underline'];
|
|
161
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
162
|
+
expect(result).toContain('superscript');
|
|
163
|
+
expect(result).toContain('subscript');
|
|
164
|
+
expect(result).toContain('strikethrough');
|
|
165
|
+
expect(result).toContain('underline');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('includes media plugins', () => {
|
|
169
|
+
const activeExtensions = ['video', 'audio'];
|
|
170
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
171
|
+
expect(result).toContain('video');
|
|
172
|
+
expect(result).toContain('audio');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('includes table plugin', () => {
|
|
176
|
+
const activeExtensions = ['table'];
|
|
177
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
178
|
+
expect(result).toContain('table');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('includes text-align plugin', () => {
|
|
182
|
+
const activeExtensions = ['text-align'];
|
|
183
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
184
|
+
expect(result).toContain('text-align');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('includes blockquote and h3 plugins when in active list', () => {
|
|
188
|
+
const activeExtensions = ['blockquote', 'h3'];
|
|
189
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
190
|
+
expect(result).toContain('blockquote');
|
|
191
|
+
expect(result).toContain('h3');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('filters out inactive extensions', () => {
|
|
195
|
+
const activeExtensions = ['bold'];
|
|
196
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
197
|
+
expect(result).not.toContain('italic');
|
|
198
|
+
expect(result).not.toContain('underline');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('maintains order of extensions', () => {
|
|
202
|
+
const activeExtensions = ['table', 'bold', 'italic'];
|
|
203
|
+
const result = buildExtensions(activeExtensions, [], {});
|
|
204
|
+
expect(result.indexOf('table')).toBeLessThan(result.indexOf('bold'));
|
|
205
|
+
expect(result.indexOf('bold')).toBeLessThan(result.indexOf('italic'));
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import StyledEditor, { EditableHtml, ALL_PLUGINS, DEFAULT_PLUGINS } from '../index';
|
|
2
|
+
|
|
3
|
+
// Mock TipTap and dependencies
|
|
4
|
+
jest.mock('@tiptap/react', () => ({
|
|
5
|
+
EditorContent: () => <div data-testid="editor-content" />,
|
|
6
|
+
useEditor: jest.fn(() => ({
|
|
7
|
+
getHTML: jest.fn(() => '<p>test content</p>'),
|
|
8
|
+
setEditable: jest.fn(),
|
|
9
|
+
commands: { setContent: jest.fn() },
|
|
10
|
+
isActive: jest.fn(() => false),
|
|
11
|
+
isFocused: false,
|
|
12
|
+
})),
|
|
13
|
+
useEditorState: jest.fn(() => ({ isFocused: false })),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock('@tiptap/starter-kit', () => ({ __esModule: true, default: {} }));
|
|
17
|
+
jest.mock('@tiptap/extension-text-style', () => ({ TextStyleKit: {} }));
|
|
18
|
+
jest.mock('@tiptap/extension-character-count', () => ({
|
|
19
|
+
CharacterCount: { configure: jest.fn(() => ({})) },
|
|
20
|
+
}));
|
|
21
|
+
jest.mock('@tiptap/extension-superscript', () => ({ __esModule: true, default: {} }));
|
|
22
|
+
jest.mock('@tiptap/extension-subscript', () => ({ __esModule: true, default: {} }));
|
|
23
|
+
jest.mock('@tiptap/extension-text-align', () => ({
|
|
24
|
+
__esModule: true,
|
|
25
|
+
default: { configure: jest.fn(() => ({})) },
|
|
26
|
+
}));
|
|
27
|
+
jest.mock('@tiptap/extension-image', () => ({ __esModule: true, default: {} }));
|
|
28
|
+
jest.mock('@tiptap/extension-table', () => ({ __esModule: true, default: {} }));
|
|
29
|
+
jest.mock('@tiptap/extension-table-row', () => ({ TableRow: {} }));
|
|
30
|
+
jest.mock('@tiptap/extension-table-cell', () => ({ TableCell: {} }));
|
|
31
|
+
jest.mock('@tiptap/extension-table-header', () => ({ TableHeader: {} }));
|
|
32
|
+
jest.mock('../extensions/extended-table', () => ({ __esModule: true, default: {} }));
|
|
33
|
+
jest.mock('../extensions/responseArea', () => ({
|
|
34
|
+
ExplicitConstructedResponseNode: { configure: jest.fn(() => ({})) },
|
|
35
|
+
DragInTheBlankNode: { configure: jest.fn(() => ({})) },
|
|
36
|
+
InlineDropdownNode: { configure: jest.fn(() => ({})) },
|
|
37
|
+
ResponseAreaExtension: { configure: jest.fn(() => ({})) },
|
|
38
|
+
}));
|
|
39
|
+
jest.mock('../extensions/math', () => ({ MathNode: { configure: jest.fn(() => ({})) } }));
|
|
40
|
+
jest.mock('../extensions/image', () => ({ ImageUploadNode: { configure: jest.fn(() => ({})) } }));
|
|
41
|
+
jest.mock('../extensions/media', () => ({ Media: { configure: jest.fn(() => ({})) } }));
|
|
42
|
+
jest.mock('../extensions/css', () => ({ CSSMark: { configure: jest.fn(() => ({})) } }));
|
|
43
|
+
jest.mock('../components/TiptapContainer', () => ({
|
|
44
|
+
__esModule: true,
|
|
45
|
+
default: ({ children }) => <div data-testid="editor-container">{children}</div>,
|
|
46
|
+
}));
|
|
47
|
+
jest.mock('../extensions', () => ({
|
|
48
|
+
buildExtensions: jest.fn(() => []),
|
|
49
|
+
ALL_PLUGINS: [
|
|
50
|
+
'bold',
|
|
51
|
+
'html',
|
|
52
|
+
'extraCSSRules',
|
|
53
|
+
'italic',
|
|
54
|
+
'underline',
|
|
55
|
+
'strikethrough',
|
|
56
|
+
'bulleted-list',
|
|
57
|
+
'numbered-list',
|
|
58
|
+
'image',
|
|
59
|
+
'math',
|
|
60
|
+
'languageCharacters',
|
|
61
|
+
'text-align',
|
|
62
|
+
'blockquote',
|
|
63
|
+
'h3',
|
|
64
|
+
'table',
|
|
65
|
+
'video',
|
|
66
|
+
'audio',
|
|
67
|
+
'responseArea',
|
|
68
|
+
'redo',
|
|
69
|
+
'undo',
|
|
70
|
+
'superscript',
|
|
71
|
+
'subscript',
|
|
72
|
+
],
|
|
73
|
+
DEFAULT_PLUGINS: [
|
|
74
|
+
'bold',
|
|
75
|
+
'html',
|
|
76
|
+
'extraCSSRules',
|
|
77
|
+
'italic',
|
|
78
|
+
'underline',
|
|
79
|
+
'strikethrough',
|
|
80
|
+
'bulleted-list',
|
|
81
|
+
'numbered-list',
|
|
82
|
+
'image',
|
|
83
|
+
'math',
|
|
84
|
+
'languageCharacters',
|
|
85
|
+
'text-align',
|
|
86
|
+
'table',
|
|
87
|
+
'video',
|
|
88
|
+
'audio',
|
|
89
|
+
'redo',
|
|
90
|
+
'undo',
|
|
91
|
+
'superscript',
|
|
92
|
+
'subscript',
|
|
93
|
+
],
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
describe('editable-html-tip-tap module', () => {
|
|
97
|
+
describe('exports', () => {
|
|
98
|
+
it('exports StyledEditor as default', () => {
|
|
99
|
+
expect(StyledEditor).toBeDefined();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('exports EditableHtml as named export', () => {
|
|
103
|
+
expect(EditableHtml).toBeDefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('exports ALL_PLUGINS as named export', () => {
|
|
107
|
+
expect(ALL_PLUGINS).toBeDefined();
|
|
108
|
+
expect(Array.isArray(ALL_PLUGINS)).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('exports DEFAULT_PLUGINS as named export', () => {
|
|
112
|
+
expect(DEFAULT_PLUGINS).toBeDefined();
|
|
113
|
+
expect(Array.isArray(DEFAULT_PLUGINS)).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('StyledEditor and EditableHtml refer to the same component', () => {
|
|
117
|
+
expect(StyledEditor).toBe(EditableHtml);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('ALL_PLUGINS', () => {
|
|
122
|
+
it('contains expected plugins', () => {
|
|
123
|
+
expect(ALL_PLUGINS).toContain('bold');
|
|
124
|
+
expect(ALL_PLUGINS).toContain('italic');
|
|
125
|
+
expect(ALL_PLUGINS).toContain('underline');
|
|
126
|
+
expect(ALL_PLUGINS).toContain('math');
|
|
127
|
+
expect(ALL_PLUGINS).toContain('table');
|
|
128
|
+
expect(ALL_PLUGINS).toContain('responseArea');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('DEFAULT_PLUGINS', () => {
|
|
133
|
+
it('is a subset of ALL_PLUGINS', () => {
|
|
134
|
+
const allPluginsSet = new Set(ALL_PLUGINS);
|
|
135
|
+
DEFAULT_PLUGINS.forEach((plugin) => {
|
|
136
|
+
expect(allPluginsSet.has(plugin)).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('contains basic formatting plugins', () => {
|
|
141
|
+
expect(DEFAULT_PLUGINS).toContain('bold');
|
|
142
|
+
expect(DEFAULT_PLUGINS).toContain('italic');
|
|
143
|
+
expect(DEFAULT_PLUGINS).toContain('underline');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|