@pie-lib/editable-html-tip-tap 2.2.0-beta.8 → 2.2.0-beta.9

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 (47) hide show
  1. package/package.json +3 -3
  2. package/src/__tests__/EditableHtml.test.jsx +0 -588
  3. package/src/__tests__/constants.test.js +0 -19
  4. package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
  5. package/src/__tests__/extensions.test.js +0 -208
  6. package/src/__tests__/index.test.jsx +0 -154
  7. package/src/__tests__/size-utils.test.js +0 -64
  8. package/src/__tests__/theme.test.js +0 -17
  9. package/src/components/__tests__/AltDialog.test.jsx +0 -147
  10. package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
  11. package/src/components/__tests__/CssIcon.test.jsx +0 -46
  12. package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
  13. package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
  14. package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
  15. package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
  16. package/src/components/__tests__/InsertImageHandler.test.js +0 -161
  17. package/src/components/__tests__/MediaDialog.test.jsx +0 -293
  18. package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
  19. package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
  20. package/src/components/__tests__/MenuBar.test.jsx +0 -250
  21. package/src/components/__tests__/RespArea.test.jsx +0 -122
  22. package/src/components/__tests__/TableIcons.test.jsx +0 -149
  23. package/src/components/__tests__/TextAlign.test.jsx +0 -167
  24. package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
  25. package/src/components/__tests__/characterUtils.test.js +0 -166
  26. package/src/components/__tests__/choice.test.jsx +0 -171
  27. package/src/components/__tests__/custom-popper.test.jsx +0 -82
  28. package/src/components/__tests__/done-button.test.jsx +0 -54
  29. package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
  30. package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
  31. package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
  32. package/src/extensions/__tests__/css.test.js +0 -196
  33. package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
  34. package/src/extensions/__tests__/divNode.test.js +0 -87
  35. package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
  36. package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
  37. package/src/extensions/__tests__/extended-list-item.test.js +0 -13
  38. package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
  39. package/src/extensions/__tests__/extended-table.test.js +0 -183
  40. package/src/extensions/__tests__/image-component.test.jsx +0 -346
  41. package/src/extensions/__tests__/image.test.js +0 -237
  42. package/src/extensions/__tests__/math.test.js +0 -900
  43. package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
  44. package/src/extensions/__tests__/media.test.js +0 -271
  45. package/src/extensions/__tests__/responseArea.test.js +0 -655
  46. package/src/utils/__tests__/helper.test.js +0 -126
  47. package/src/utils/__tests__/toolbar.test.js +0 -43
@@ -1,183 +0,0 @@
1
- import ExtendedTable, { applyPresentationToTableElement, ExtendedTableView } from '../extended-table';
2
-
3
- const mockTableViewState = { updateReturns: true };
4
-
5
- jest.mock('@tiptap/extension-table', () => ({
6
- Table: {
7
- extend: jest.fn((config) => config),
8
- },
9
- TableView: class TableView {
10
- constructor() {
11
- this.table = {
12
- style: { setProperty: jest.fn() },
13
- setAttribute: jest.fn(),
14
- };
15
- }
16
-
17
- update() {
18
- return mockTableViewState.updateReturns;
19
- }
20
- },
21
- }));
22
-
23
- describe('ExtendedTable', () => {
24
- beforeEach(() => {
25
- mockTableViewState.updateReturns = true;
26
- });
27
-
28
- describe('applyPresentationToTableElement', () => {
29
- it('sets default border and theme styles', () => {
30
- const table = document.createElement('table');
31
- const setProperty = jest.spyOn(table.style, 'setProperty');
32
-
33
- applyPresentationToTableElement(table, {});
34
-
35
- expect(table.getAttribute('border')).toBe('1');
36
- expect(setProperty).toHaveBeenCalledWith('color', 'var(--pie-text, black)');
37
- expect(setProperty).toHaveBeenCalledWith('background-color', 'var(--pie-background, rgba(255, 255, 255))');
38
- setProperty.mockRestore();
39
- });
40
-
41
- it('uses explicit border from attrs', () => {
42
- const table = document.createElement('table');
43
- applyPresentationToTableElement(table, { border: '0' });
44
-
45
- expect(table.getAttribute('border')).toBe('0');
46
- });
47
-
48
- it('treats empty border as default', () => {
49
- const table = document.createElement('table');
50
- applyPresentationToTableElement(table, { border: '' });
51
-
52
- expect(table.getAttribute('border')).toBe('1');
53
- });
54
- });
55
-
56
- describe('ExtendedTableView', () => {
57
- it('applies presentation after construction', () => {
58
- const node = { attrs: { border: '2' } };
59
- const view = new ExtendedTableView(node, 25);
60
-
61
- expect(view.table.setAttribute).toHaveBeenCalledWith('border', '2');
62
- expect(view.table.style.setProperty).toHaveBeenCalledWith('color', 'var(--pie-text, black)');
63
- expect(view.table.style.setProperty).toHaveBeenCalledWith(
64
- 'background-color',
65
- 'var(--pie-background, rgba(255, 255, 255))',
66
- );
67
- });
68
-
69
- it('reapplies presentation when super.update returns true', () => {
70
- const view = new ExtendedTableView({ attrs: { border: '1' } }, 25);
71
- view.table.setAttribute.mockClear();
72
- view.table.style.setProperty.mockClear();
73
-
74
- view.update({ attrs: { border: '0' } });
75
-
76
- expect(view.table.setAttribute).toHaveBeenCalledWith('border', '0');
77
- expect(view.table.style.setProperty).toHaveBeenCalledWith('color', 'var(--pie-text, black)');
78
- expect(view.table.style.setProperty).toHaveBeenCalledWith(
79
- 'background-color',
80
- 'var(--pie-background, rgba(255, 255, 255))',
81
- );
82
- });
83
-
84
- it('does not reapply presentation when super.update returns false', () => {
85
- mockTableViewState.updateReturns = false;
86
- const view = new ExtendedTableView({ attrs: { border: '1' } }, 25);
87
- view.table.setAttribute.mockClear();
88
- view.table.style.setProperty.mockClear();
89
-
90
- const ok = view.update({ attrs: { border: '0' } });
91
-
92
- expect(ok).toBe(false);
93
- expect(view.table.setAttribute).not.toHaveBeenCalled();
94
- expect(view.table.style.setProperty).not.toHaveBeenCalled();
95
- });
96
- });
97
-
98
- describe('addOptions', () => {
99
- it('enables resizable table view with zero handle width for colgroup sync', () => {
100
- const options = ExtendedTable.addOptions();
101
- expect(options.resizable).toBe(true);
102
- expect(options.handleWidth).toBe(0);
103
- expect(options.View).toBe(ExtendedTableView);
104
- });
105
- });
106
-
107
- describe('addAttributes', () => {
108
- it('returns border attribute with default value', () => {
109
- const attributes = ExtendedTable.addAttributes();
110
- expect(attributes).toHaveProperty('border');
111
- expect(attributes.border).toEqual({ default: '1' });
112
- });
113
- });
114
-
115
- describe('renderHTML', () => {
116
- it('renders table with default border', () => {
117
- const props = {
118
- HTMLAttributes: {},
119
- };
120
-
121
- const mockParent = jest.fn(() => ['table', { style: '' }]);
122
-
123
- const context = {
124
- parent: mockParent,
125
- };
126
-
127
- const result = ExtendedTable.renderHTML.call(context, props);
128
-
129
- expect(mockParent).toHaveBeenCalledWith(props);
130
- expect(result[0]).toBe('table');
131
- expect(result[1]).toHaveProperty('style');
132
- });
133
-
134
- it('renders table with custom border', () => {
135
- const props = {
136
- HTMLAttributes: { border: '2' },
137
- };
138
-
139
- const mockParent = jest.fn(() => ['table', { style: '' }]);
140
-
141
- const context = {
142
- parent: mockParent,
143
- };
144
-
145
- const result = ExtendedTable.renderHTML.call(context, props);
146
-
147
- expect(result[1].border).toBe('2');
148
- });
149
-
150
- it('handles styles ending with semicolon', () => {
151
- const props = {
152
- HTMLAttributes: {},
153
- };
154
-
155
- const mockParent = jest.fn(() => ['table', { style: 'padding: 5px;' }]);
156
-
157
- const context = {
158
- parent: mockParent,
159
- };
160
-
161
- const result = ExtendedTable.renderHTML.call(context, props);
162
-
163
- expect(result[1].style).toContain('padding: 5px;');
164
- });
165
-
166
- it('includes CSS custom properties', () => {
167
- const props = {
168
- HTMLAttributes: {},
169
- };
170
-
171
- const mockParent = jest.fn(() => ['table', { style: '' }]);
172
-
173
- const context = {
174
- parent: mockParent,
175
- };
176
-
177
- const result = ExtendedTable.renderHTML.call(context, props);
178
-
179
- expect(result[1].style).toContain('color: var(--pie-text, black)');
180
- expect(result[1].style).toContain('background-color: var(--pie-background, rgba(255, 255, 255))');
181
- });
182
- });
183
- });
@@ -1,346 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render, waitFor } from '@testing-library/react';
3
- import ImageComponent from '../image-component';
4
-
5
- jest.mock('@tiptap/react', () => ({
6
- NodeViewWrapper: ({ children }) => <div data-testid="node-view-wrapper">{children}</div>,
7
- }));
8
-
9
- jest.mock('../../components/image/InsertImageHandler', () => ({
10
- __esModule: true,
11
- default: jest.fn(),
12
- }));
13
-
14
- jest.mock('../../components/image/ImageToolbar', () => ({
15
- __esModule: true,
16
- default: ({ onChange, alignment, alt }) => (
17
- <div data-testid="image-toolbar">
18
- <button onClick={() => onChange({ alignment: 'center' })}>Center</button>
19
- <span>{alignment}</span>
20
- <span>{alt}</span>
21
- </div>
22
- ),
23
- }));
24
-
25
- jest.mock('../custom-toolbar-wrapper', () => ({
26
- __esModule: true,
27
- default: ({ children, onDone }) => (
28
- <div data-testid="custom-toolbar-wrapper">
29
- {children}
30
- <button onClick={onDone} data-testid="done-button">
31
- Done
32
- </button>
33
- </div>
34
- ),
35
- }));
36
-
37
- describe('ImageComponent', () => {
38
- const MOCK_NODE_POS = 7;
39
-
40
- const createMockEditor = (selection = { from: 0, to: 1 }) => ({
41
- _tiptapContainerEl: document.body,
42
- isEditable: true,
43
- commands: {
44
- updateAttributes: jest.fn(),
45
- focus: jest.fn(),
46
- },
47
- state: {
48
- selection,
49
- doc: {
50
- descendants: jest.fn(),
51
- nodeAt: jest.fn(),
52
- },
53
- tr: {
54
- setNodeMarkup: jest.fn().mockReturnThis(),
55
- delete: jest.fn().mockReturnThis(),
56
- },
57
- },
58
- view: {
59
- dispatch: jest.fn(),
60
- },
61
- });
62
-
63
- let mockEditor = createMockEditor();
64
-
65
- const mockNode = {
66
- type: { name: 'imageUploadNode' },
67
- attrs: {
68
- nodeKey: 'test-key-123',
69
- src: 'test.jpg',
70
- width: 100,
71
- height: 100,
72
- loaded: true,
73
- percent: 100,
74
- alt: 'Test image',
75
- alignment: 'left',
76
- deleteStatus: null,
77
- },
78
- nodeSize: 1,
79
- };
80
-
81
- const mockOptions = {
82
- imageHandling: {
83
- insertImageRequested: jest.fn(),
84
- onDone: jest.fn(),
85
- onDelete: jest.fn(),
86
- },
87
- disableImageAlignmentButtons: false,
88
- };
89
-
90
- const defaultProps = {
91
- node: mockNode,
92
- editor: mockEditor,
93
- selected: false,
94
- options: mockOptions,
95
- attributes: {},
96
- onFocus: jest.fn(),
97
- getPos: jest.fn(() => MOCK_NODE_POS),
98
- };
99
-
100
- beforeEach(() => {
101
- jest.clearAllMocks();
102
- mockEditor = createMockEditor();
103
- defaultProps.editor = mockEditor;
104
- defaultProps.getPos = jest.fn(() => MOCK_NODE_POS);
105
- mockEditor.state.doc.descendants.mockImplementation((cb) => cb(mockNode, 0));
106
- mockEditor.state.doc.nodeAt.mockReturnValue(mockNode);
107
- });
108
-
109
- it('renders without crashing', () => {
110
- const { getByTestId } = render(<ImageComponent {...defaultProps} />);
111
- expect(getByTestId('node-view-wrapper')).toBeInTheDocument();
112
- });
113
-
114
- it('renders image with correct src', () => {
115
- const { container } = render(<ImageComponent {...defaultProps} />);
116
- const img = container.querySelector('img');
117
- expect(img).toBeInTheDocument();
118
- expect(img.src).toContain('test.jpg');
119
- });
120
-
121
- it('renders image with correct dimensions', () => {
122
- const { container } = render(<ImageComponent {...defaultProps} />);
123
- const img = container.querySelector('img');
124
- expect(img.style.width).toBe('100px');
125
- expect(img.style.height).toBe('100px');
126
- });
127
-
128
- it('renders image with alt text', () => {
129
- const { container } = render(<ImageComponent {...defaultProps} />);
130
- const img = container.querySelector('img');
131
- expect(img.alt).toBe('Test image');
132
- });
133
-
134
- it('does not show toolbar when not selected', () => {
135
- const { queryByTestId } = render(<ImageComponent {...defaultProps} selected={false} />);
136
- expect(queryByTestId('image-toolbar')).not.toBeInTheDocument();
137
- });
138
-
139
- it('shows toolbar when selected', async () => {
140
- const { getByTestId } = render(<ImageComponent {...defaultProps} selected={true} />);
141
-
142
- await waitFor(() => {
143
- expect(getByTestId('image-toolbar')).toBeInTheDocument();
144
- });
145
- });
146
-
147
- it('applies loading opacity when image not loaded', () => {
148
- const notLoadedNode = {
149
- ...mockNode,
150
- attrs: {
151
- ...mockNode.attrs,
152
- loaded: false,
153
- },
154
- };
155
-
156
- const { container } = render(<ImageComponent {...defaultProps} node={notLoadedNode} />);
157
- const root = container.querySelector('[data-testid="node-view-wrapper"] > div');
158
- expect(root).toHaveStyle({ opacity: 0.3 });
159
- });
160
-
161
- it('applies pending delete opacity', () => {
162
- const pendingDeleteNode = {
163
- ...mockNode,
164
- attrs: {
165
- ...mockNode.attrs,
166
- deleteStatus: 'pending',
167
- },
168
- };
169
-
170
- const { container } = render(<ImageComponent {...defaultProps} node={pendingDeleteNode} />);
171
- const root = container.querySelector('[data-testid="node-view-wrapper"] > div');
172
- expect(root).toHaveStyle({ opacity: 0.3 });
173
- });
174
-
175
- it('aligns image to left by default', () => {
176
- const { container } = render(<ImageComponent {...defaultProps} />);
177
- const root = container.querySelector('[data-testid="node-view-wrapper"] > div');
178
- expect(root).toHaveStyle({ justifyContent: 'flex-start' });
179
- });
180
-
181
- it('aligns image to center', () => {
182
- const centerNode = {
183
- ...mockNode,
184
- attrs: {
185
- ...mockNode.attrs,
186
- alignment: 'center',
187
- },
188
- };
189
-
190
- const { container } = render(<ImageComponent {...defaultProps} node={centerNode} />);
191
- const root = container.querySelector('[data-testid="node-view-wrapper"] > div');
192
- expect(root).toHaveStyle({ justifyContent: 'center' });
193
- });
194
-
195
- it('aligns image to right', () => {
196
- const rightNode = {
197
- ...mockNode,
198
- attrs: {
199
- ...mockNode.attrs,
200
- alignment: 'right',
201
- },
202
- };
203
-
204
- const { container } = render(<ImageComponent {...defaultProps} node={rightNode} />);
205
- const root = container.querySelector('[data-testid="node-view-wrapper"] > div');
206
- expect(root).toHaveStyle({ justifyContent: 'flex-end' });
207
- });
208
-
209
- it('does not call insertImageRequested when image already has src', () => {
210
- render(<ImageComponent {...defaultProps} selected={true} />);
211
- expect(mockOptions.imageHandling.insertImageRequested).not.toHaveBeenCalled();
212
- });
213
-
214
- it('does not call insertImageRequested for empty placeholder on mount when not selected', () => {
215
- const placeholderNode = {
216
- ...mockNode,
217
- attrs: {
218
- ...mockNode.attrs,
219
- src: null,
220
- loaded: false,
221
- percent: null,
222
- },
223
- };
224
- render(<ImageComponent {...defaultProps} node={placeholderNode} selected={false} />);
225
- expect(mockOptions.imageHandling.insertImageRequested).not.toHaveBeenCalled();
226
- });
227
-
228
- it('calls insertImageRequested with editor and [node, pos] when empty placeholder is solely selected', async () => {
229
- const placeholderNode = {
230
- ...mockNode,
231
- nodeSize: 1,
232
- attrs: {
233
- ...mockNode.attrs,
234
- src: null,
235
- loaded: false,
236
- percent: null,
237
- },
238
- };
239
- mockEditor = createMockEditor({ from: 0, to: 1 });
240
-
241
- render(<ImageComponent {...defaultProps} editor={mockEditor} node={placeholderNode} selected={true} />);
242
-
243
- await waitFor(() => {
244
- expect(mockOptions.imageHandling.insertImageRequested).toHaveBeenCalled();
245
- });
246
-
247
- expect(mockOptions.imageHandling.insertImageRequested).toHaveBeenCalledWith(
248
- mockEditor,
249
- [placeholderNode, MOCK_NODE_POS],
250
- expect.any(Function),
251
- );
252
- expect(defaultProps.getPos).toHaveBeenCalled();
253
- });
254
-
255
- it('does not call insertImageRequested when selection spans beyond the image node', () => {
256
- const placeholderNode = {
257
- ...mockNode,
258
- nodeSize: 1,
259
- attrs: {
260
- ...mockNode.attrs,
261
- src: null,
262
- loaded: false,
263
- percent: null,
264
- },
265
- };
266
- mockEditor = createMockEditor({ from: 0, to: 5 });
267
-
268
- render(<ImageComponent {...defaultProps} editor={mockEditor} node={placeholderNode} selected={true} />);
269
- expect(mockOptions.imageHandling.insertImageRequested).not.toHaveBeenCalled();
270
- });
271
-
272
- it('updates attributes through toolbar onChange', async () => {
273
- const { getByTestId } = render(<ImageComponent {...defaultProps} selected={true} />);
274
-
275
- await waitFor(() => {
276
- const centerButton = getByTestId('image-toolbar').querySelector('button');
277
- fireEvent.click(centerButton);
278
- });
279
-
280
- expect(mockEditor.state.tr.setNodeMarkup).toHaveBeenCalledWith(
281
- 0,
282
- undefined,
283
- expect.objectContaining({ alignment: 'center' }),
284
- );
285
- expect(mockEditor.view.dispatch).toHaveBeenCalled();
286
- });
287
-
288
- it('toolbar is shown when selected', async () => {
289
- const { container, queryByTestId } = render(<ImageComponent {...defaultProps} selected={true} />);
290
-
291
- // Wait for toolbar to potentially appear
292
- await waitFor(() => {
293
- // The toolbar might not be visible due to mocking but check if custom-toolbar-wrapper shows up
294
- const toolbar = container.querySelector('[data-testid="custom-toolbar-wrapper"]');
295
- // In a real test environment, the toolbar would be visible
296
- // For now, just verify the component renders without errors when selected
297
- expect(container).toBeInTheDocument();
298
- });
299
- });
300
-
301
- it('respects maxImageWidth prop', () => {
302
- const props = {
303
- ...defaultProps,
304
- maxImageWidth: 500,
305
- };
306
-
307
- const { container } = render(<ImageComponent {...props} />);
308
- expect(container).toBeInTheDocument();
309
- });
310
-
311
- it('respects maxImageHeight prop', () => {
312
- const props = {
313
- ...defaultProps,
314
- maxImageHeight: 800,
315
- };
316
-
317
- const { container } = render(<ImageComponent {...props} />);
318
- expect(container).toBeInTheDocument();
319
- });
320
-
321
- it('handles missing alt attribute', () => {
322
- const noAltNode = {
323
- ...mockNode,
324
- attrs: {
325
- ...mockNode.attrs,
326
- alt: undefined,
327
- },
328
- };
329
-
330
- const { container } = render(<ImageComponent {...defaultProps} node={noAltNode} />);
331
- const img = container.querySelector('img');
332
- expect(img).toBeInTheDocument();
333
- });
334
-
335
- it('passes editor to imageHandling onDone when Done is clicked', async () => {
336
- const { getByTestId } = render(<ImageComponent {...defaultProps} selected={true} />);
337
-
338
- await waitFor(() => {
339
- expect(getByTestId('done-button')).toBeInTheDocument();
340
- });
341
-
342
- fireEvent.click(getByTestId('done-button'));
343
-
344
- expect(mockOptions.imageHandling.onDone).toHaveBeenCalledWith(mockEditor);
345
- });
346
- });