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