@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.
Files changed (78) hide show
  1. package/CHANGELOG.md +0 -130
  2. package/lib/components/EditableHtml.js +0 -56
  3. package/lib/components/EditableHtml.js.map +1 -1
  4. package/lib/components/MenuBar.js +12 -81
  5. package/lib/components/MenuBar.js.map +1 -1
  6. package/lib/components/TiptapContainer.js +2 -2
  7. package/lib/components/TiptapContainer.js.map +1 -1
  8. package/lib/components/common/toolbar-buttons.js +5 -6
  9. package/lib/components/common/toolbar-buttons.js.map +1 -1
  10. package/lib/components/icons/TableIcons.js +1 -3
  11. package/lib/components/icons/TableIcons.js.map +1 -1
  12. package/lib/components/icons/TextAlign.js +5 -14
  13. package/lib/components/icons/TextAlign.js.map +1 -1
  14. package/lib/components/respArea/MathTemplated.js +8 -14
  15. package/lib/components/respArea/MathTemplated.js.map +1 -1
  16. package/lib/extensions/math.js +37 -19
  17. package/lib/extensions/math.js.map +1 -1
  18. package/lib/styles/editorContainerStyles.js +2 -2
  19. package/lib/styles/editorContainerStyles.js.map +1 -1
  20. package/package.json +9 -9
  21. package/src/components/EditableHtml.jsx +0 -52
  22. package/src/components/MenuBar.jsx +9 -91
  23. package/src/components/TiptapContainer.jsx +2 -2
  24. package/src/components/common/toolbar-buttons.jsx +4 -6
  25. package/src/components/icons/TableIcons.jsx +1 -9
  26. package/src/components/icons/TextAlign.jsx +5 -39
  27. package/src/components/respArea/MathTemplated.jsx +6 -13
  28. package/src/extensions/math.js +19 -11
  29. package/src/styles/editorContainerStyles.js +2 -2
  30. package/LICENSE.md +0 -5
  31. package/src/__tests__/EditableHtml.test.jsx +0 -668
  32. package/src/__tests__/constants.test.js +0 -19
  33. package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
  34. package/src/__tests__/editor-attributes.test.jsx +0 -77
  35. package/src/__tests__/extensions.test.js +0 -208
  36. package/src/__tests__/index.test.jsx +0 -154
  37. package/src/__tests__/size-utils.test.js +0 -64
  38. package/src/__tests__/spellcheck.test.jsx +0 -63
  39. package/src/__tests__/theme.test.js +0 -17
  40. package/src/components/__tests__/AltDialog.test.jsx +0 -147
  41. package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
  42. package/src/components/__tests__/CssIcon.test.jsx +0 -46
  43. package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
  44. package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
  45. package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
  46. package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
  47. package/src/components/__tests__/InsertImageHandler.test.js +0 -161
  48. package/src/components/__tests__/MediaDialog.test.jsx +0 -293
  49. package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
  50. package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
  51. package/src/components/__tests__/MenuBar.test.jsx +0 -338
  52. package/src/components/__tests__/RespArea.test.jsx +0 -122
  53. package/src/components/__tests__/TableIcons.test.jsx +0 -149
  54. package/src/components/__tests__/TextAlign.test.jsx +0 -167
  55. package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
  56. package/src/components/__tests__/characterUtils.test.js +0 -166
  57. package/src/components/__tests__/choice.test.jsx +0 -171
  58. package/src/components/__tests__/custom-popper.test.jsx +0 -82
  59. package/src/components/__tests__/done-button.test.jsx +0 -54
  60. package/src/components/__tests__/toolbar-buttons.test.jsx +0 -247
  61. package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
  62. package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
  63. package/src/extensions/__tests__/css.test.js +0 -196
  64. package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
  65. package/src/extensions/__tests__/divNode.test.js +0 -87
  66. package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
  67. package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
  68. package/src/extensions/__tests__/extended-list-item.test.js +0 -13
  69. package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
  70. package/src/extensions/__tests__/extended-table.test.js +0 -183
  71. package/src/extensions/__tests__/image-component.test.jsx +0 -346
  72. package/src/extensions/__tests__/image.test.js +0 -237
  73. package/src/extensions/__tests__/math.test.js +0 -898
  74. package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
  75. package/src/extensions/__tests__/media.test.js +0 -271
  76. package/src/extensions/__tests__/responseArea.test.js +0 -655
  77. package/src/utils/__tests__/helper.test.js +0 -126
  78. package/src/utils/__tests__/toolbar.test.js +0 -43
@@ -1,125 +0,0 @@
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
- });
@@ -1,77 +0,0 @@
1
- import React from 'react';
2
- import { render, waitFor } from '@testing-library/react';
3
- import { EditableHtml } from '../components/EditableHtml';
4
-
5
- const renderEditor = (props) =>
6
- render(<EditableHtml markup="<p>hello</p>" onChange={() => {}} pluginProps={{}} {...props} />);
7
-
8
- const prosemirror = (container) => container.querySelector('.ProseMirror');
9
-
10
- const waitForEditor = async (container) => {
11
- await waitFor(() => {
12
- expect(prosemirror(container)).toBeInTheDocument();
13
- });
14
- };
15
-
16
- describe('contenteditable attributes', () => {
17
- // PIE-1015: 2.1.17 lost role="textbox" on a plain mount, because setEditable re-pushes
18
- // editorProps through setOptions and ProseMirror drops any attribute no longer listed.
19
- it('announces the editor as a textbox on a plain mount', async () => {
20
- const { container } = renderEditor();
21
-
22
- await waitForEditor(container);
23
-
24
- expect(prosemirror(container).getAttribute('role')).toBe('textbox');
25
- });
26
-
27
- // PIE-1016: a PIE-owned hook external consumers can target, unlike role or .tiptap.ProseMirror.
28
- it('exposes the PIE-owned editor hook on a plain mount', async () => {
29
- const { container } = renderEditor();
30
-
31
- await waitForEditor(container);
32
-
33
- expect(prosemirror(container).getAttribute('data-pie-editor')).toBe('true');
34
- });
35
-
36
- it('keeps both attributes when spellCheck changes on a mounted editor', async () => {
37
- const { container, rerender } = renderEditor({ spellCheck: true });
38
-
39
- await waitForEditor(container);
40
-
41
- rerender(<EditableHtml markup="<p>hello</p>" onChange={() => {}} pluginProps={{}} spellCheck={false} />);
42
-
43
- await waitFor(() => {
44
- expect(prosemirror(container).getAttribute('spellcheck')).toBe('false');
45
- });
46
-
47
- expect(prosemirror(container).getAttribute('role')).toBe('textbox');
48
- expect(prosemirror(container).getAttribute('data-pie-editor')).toBe('true');
49
- });
50
-
51
- it('keeps both attributes when the editor is disabled on a mounted editor', async () => {
52
- const { container, rerender } = renderEditor();
53
-
54
- await waitForEditor(container);
55
-
56
- rerender(<EditableHtml markup="<p>hello</p>" onChange={() => {}} pluginProps={{}} disabled />);
57
-
58
- await waitFor(() => {
59
- expect(prosemirror(container).getAttribute('contenteditable')).toBe('false');
60
- });
61
-
62
- expect(prosemirror(container).getAttribute('role')).toBe('textbox');
63
- expect(prosemirror(container).getAttribute('data-pie-editor')).toBe('true');
64
- });
65
-
66
- // Online Testing queries [data-pie-editor][contenteditable="true"] to attach its answer-save
67
- // listener, so a read-only render has to carry the hook but not match that selector.
68
- it('marks a read-only editor as not editable so the hook can be filtered on it', async () => {
69
- const { container } = renderEditor({ disabled: true });
70
-
71
- await waitForEditor(container);
72
-
73
- expect(prosemirror(container).getAttribute('data-pie-editor')).toBe('true');
74
- expect(prosemirror(container).getAttribute('contenteditable')).toBe('false');
75
- expect(container.querySelector('[data-pie-editor][contenteditable="true"]')).toBeNull();
76
- });
77
- });
@@ -1,208 +0,0 @@
1
- import { ALL_PLUGINS, buildExtensions, 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
- });
@@ -1,154 +0,0 @@
1
- import StyledEditor, { ALL_PLUGINS, DEFAULT_PLUGINS, EditableHtml } 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', () => ({
17
- __esModule: true,
18
- default: { configure: jest.fn(() => ({})) },
19
- }));
20
- jest.mock('@tiptap/extension-text-style', () => ({ TextStyleKit: {} }));
21
- jest.mock('@tiptap/extension-character-count', () => ({
22
- CharacterCount: { configure: jest.fn(() => ({})) },
23
- }));
24
- jest.mock('@tiptap/extension-superscript', () => ({ __esModule: true, default: {} }));
25
- jest.mock('@tiptap/extension-subscript', () => ({ __esModule: true, default: {} }));
26
- jest.mock('@tiptap/extension-text-align', () => ({
27
- __esModule: true,
28
- default: { configure: jest.fn(() => ({})) },
29
- }));
30
- jest.mock('@tiptap/extension-image', () => ({ __esModule: true, default: {} }));
31
- jest.mock('@tiptap/extension-table', () => ({ __esModule: true, default: {} }));
32
- jest.mock('@tiptap/extension-table-row', () => ({ TableRow: {} }));
33
- jest.mock('../extensions/extended-table-cell', () => ({
34
- ExtendedTableCell: {},
35
- ExtendedTableHeader: {},
36
- }));
37
- jest.mock('../extensions/extended-table', () => ({ __esModule: true, default: {} }));
38
- jest.mock('../extensions/ensure-empty-root-div', () => ({ EnsureEmptyRootIsDiv: {} }));
39
- jest.mock('../extensions/extended-list-item', () => ({ ExtendedListItem: {} }));
40
- jest.mock('../extensions/ensure-list-item-content-is-div', () => ({ EnsureListItemContentIsDiv: {} }));
41
- jest.mock('../extensions/responseArea', () => ({
42
- ExplicitConstructedResponseNode: { configure: jest.fn(() => ({})) },
43
- DragInTheBlankNode: { configure: jest.fn(() => ({})) },
44
- InlineDropdownNode: { configure: jest.fn(() => ({})) },
45
- ResponseAreaExtension: { configure: jest.fn(() => ({})) },
46
- }));
47
- jest.mock('../extensions/math', () => ({ MathNode: { configure: jest.fn(() => ({})) } }));
48
- jest.mock('../extensions/image', () => ({ ImageUploadNode: { configure: jest.fn(() => ({})) } }));
49
- jest.mock('../extensions/media', () => ({ Media: { configure: jest.fn(() => ({})) } }));
50
- jest.mock('../extensions/css', () => ({ CSSMark: { configure: jest.fn(() => ({})) } }));
51
- jest.mock('../components/TiptapContainer', () => ({
52
- __esModule: true,
53
- default: ({ children }) => <div data-testid="editor-container">{children}</div>,
54
- }));
55
- jest.mock('../extensions', () => ({
56
- buildExtensions: jest.fn(() => []),
57
- ALL_PLUGINS: [
58
- 'bold',
59
- 'html',
60
- 'extraCSSRules',
61
- 'italic',
62
- 'underline',
63
- 'strikethrough',
64
- 'bulleted-list',
65
- 'numbered-list',
66
- 'image',
67
- 'math',
68
- 'languageCharacters',
69
- 'text-align',
70
- 'blockquote',
71
- 'h3',
72
- 'table',
73
- 'video',
74
- 'audio',
75
- 'responseArea',
76
- 'redo',
77
- 'undo',
78
- 'superscript',
79
- 'subscript',
80
- ],
81
- DEFAULT_PLUGINS: [
82
- 'bold',
83
- 'html',
84
- 'extraCSSRules',
85
- 'italic',
86
- 'underline',
87
- 'strikethrough',
88
- 'bulleted-list',
89
- 'numbered-list',
90
- 'image',
91
- 'math',
92
- 'languageCharacters',
93
- 'text-align',
94
- 'table',
95
- 'video',
96
- 'audio',
97
- 'redo',
98
- 'undo',
99
- 'superscript',
100
- 'subscript',
101
- ],
102
- }));
103
-
104
- describe('editable-html-tip-tap module', () => {
105
- describe('exports', () => {
106
- it('exports StyledEditor as default', () => {
107
- expect(StyledEditor).toBeDefined();
108
- });
109
-
110
- it('exports EditableHtml as named export', () => {
111
- expect(EditableHtml).toBeDefined();
112
- });
113
-
114
- it('exports ALL_PLUGINS as named export', () => {
115
- expect(ALL_PLUGINS).toBeDefined();
116
- expect(Array.isArray(ALL_PLUGINS)).toBe(true);
117
- });
118
-
119
- it('exports DEFAULT_PLUGINS as named export', () => {
120
- expect(DEFAULT_PLUGINS).toBeDefined();
121
- expect(Array.isArray(DEFAULT_PLUGINS)).toBe(true);
122
- });
123
-
124
- it('StyledEditor and EditableHtml refer to the same component', () => {
125
- expect(StyledEditor).toBe(EditableHtml);
126
- });
127
- });
128
-
129
- describe('ALL_PLUGINS', () => {
130
- it('contains expected plugins', () => {
131
- expect(ALL_PLUGINS).toContain('bold');
132
- expect(ALL_PLUGINS).toContain('italic');
133
- expect(ALL_PLUGINS).toContain('underline');
134
- expect(ALL_PLUGINS).toContain('math');
135
- expect(ALL_PLUGINS).toContain('table');
136
- expect(ALL_PLUGINS).toContain('responseArea');
137
- });
138
- });
139
-
140
- describe('DEFAULT_PLUGINS', () => {
141
- it('is a subset of ALL_PLUGINS', () => {
142
- const allPluginsSet = new Set(ALL_PLUGINS);
143
- DEFAULT_PLUGINS.forEach((plugin) => {
144
- expect(allPluginsSet.has(plugin)).toBe(true);
145
- });
146
- });
147
-
148
- it('contains basic formatting plugins', () => {
149
- expect(DEFAULT_PLUGINS).toContain('bold');
150
- expect(DEFAULT_PLUGINS).toContain('italic');
151
- expect(DEFAULT_PLUGINS).toContain('underline');
152
- });
153
- });
154
- });
@@ -1,64 +0,0 @@
1
- import { valueToSize } from '../utils/size';
2
-
3
- describe('Size Utilities', () => {
4
- describe('valueToSize', () => {
5
- it('returns undefined for falsy values', () => {
6
- expect(valueToSize(null)).toBeUndefined();
7
- expect(valueToSize(undefined)).toBeUndefined();
8
- expect(valueToSize('')).toBeUndefined();
9
- expect(valueToSize(0)).toBeUndefined();
10
- });
11
-
12
- it('converts number to px string', () => {
13
- expect(valueToSize(100)).toBe('100px');
14
- expect(valueToSize(50)).toBe('50px');
15
- expect(valueToSize(0)).toBeUndefined();
16
- });
17
-
18
- it('returns undefined for percentage strings', () => {
19
- expect(valueToSize('100%')).toBeUndefined();
20
- expect(valueToSize('50%')).toBeUndefined();
21
- expect(valueToSize('0%')).toBeUndefined();
22
- });
23
-
24
- it('preserves valid CSS unit strings', () => {
25
- expect(valueToSize('100px')).toBe('100px');
26
- expect(valueToSize('10vh')).toBe('10vh');
27
- expect(valueToSize('50vw')).toBe('50vw');
28
- expect(valueToSize('9ch')).toBe('9ch');
29
- expect(valueToSize('2em')).toBe('2em');
30
- });
31
-
32
- it('preserves calc() expressions', () => {
33
- expect(valueToSize('calc(10em + 42px)')).toBe('calc(10em + 42px)');
34
- expect(valueToSize('calc(100% - 20px)')).toBe('calc(100% - 20px)');
35
- expect(valueToSize('calc(50vh + 10px)')).toBe('calc(50vh + 10px)');
36
- });
37
-
38
- it('converts numeric strings to px', () => {
39
- expect(valueToSize('100')).toBe('100px');
40
- expect(valueToSize('50')).toBe('50px');
41
- expect(valueToSize('250')).toBe('250px');
42
- });
43
-
44
- it('handles invalid numeric strings', () => {
45
- const result = valueToSize('invalid');
46
- expect(isNaN(result)).toBe(true);
47
- });
48
-
49
- it('handles edge cases with whitespace', () => {
50
- const result = valueToSize(' ');
51
- expect(isNaN(result)).toBe(true);
52
- });
53
-
54
- it('handles negative numbers', () => {
55
- expect(valueToSize(-100)).toBe('-100px');
56
- expect(valueToSize('-50')).toBe('-50px');
57
- });
58
-
59
- it('handles decimal numbers', () => {
60
- expect(valueToSize(100.5)).toBe('100.5px');
61
- expect(valueToSize('100.5')).toBe('100px'); // parseInt truncates
62
- });
63
- });
64
- });