@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,557 +0,0 @@
1
- import React from 'react';
2
- import { fireEvent, render, waitFor } from '@testing-library/react';
3
- import { renderMath } from '@pie-lib/math-rendering';
4
- import InlineDropdown from '../respArea/InlineDropdown';
5
-
6
- jest.mock('@pie-lib/math-rendering', () => ({
7
- renderMath: jest.fn(),
8
- }));
9
-
10
- jest.mock('@tiptap/react', () => ({
11
- NodeViewWrapper: ({ children, ...props }) => (
12
- <div data-testid="node-view-wrapper" {...props}>
13
- {children}
14
- </div>
15
- ),
16
- }));
17
-
18
- const mockCreatePortal = jest.fn((node) => node);
19
-
20
- jest.mock('react-dom', () => ({
21
- ...jest.requireActual('react-dom'),
22
- createPortal: (...args) => mockCreatePortal(...args),
23
- }));
24
-
25
- describe('InlineDropdown', () => {
26
- const buildMockEditor = (overrides = {}) => {
27
- const mockNodeAt = jest.fn((pos) => (pos === 5 ? { nodeSize: 1 } : null));
28
- const mockDoc = {
29
- descendants: jest.fn(),
30
- nodeAt: mockNodeAt,
31
- };
32
- const mockTr = {
33
- delete: jest.fn(),
34
- doc: { nodeAt: mockNodeAt },
35
- setSelection: jest.fn(),
36
- setMeta: jest.fn(function setMeta() {
37
- return mockTr;
38
- }),
39
- };
40
- return {
41
- state: {
42
- selection: {
43
- from: 0,
44
- to: 1,
45
- },
46
- tr: mockTr,
47
- doc: mockDoc,
48
- },
49
- view: {
50
- coordsAtPos: jest.fn(() => ({ top: 100, left: 50 })),
51
- dispatch: jest.fn(),
52
- },
53
- commands: {
54
- focus: jest.fn(),
55
- },
56
- _tiptapContainerEl: document.createElement('div'),
57
- _toolbarOpened: false,
58
- ...overrides,
59
- };
60
- };
61
-
62
- let mockEditor;
63
-
64
- const mockNode = {
65
- attrs: {
66
- index: '0',
67
- value: 'Selected Option',
68
- error: false,
69
- },
70
- nodeSize: 1,
71
- };
72
-
73
- const mockOptions = {
74
- respAreaToolbar: jest.fn(() => () => <div data-testid="inline-dropdown-toolbar">Toolbar</div>),
75
- };
76
-
77
- const defaultProps = {
78
- editor: mockEditor,
79
- node: mockNode,
80
- getPos: () => 5,
81
- options: mockOptions,
82
- selected: false,
83
- };
84
-
85
- beforeEach(() => {
86
- jest.clearAllMocks();
87
- mockCreatePortal.mockClear();
88
- mockEditor = buildMockEditor();
89
- defaultProps.editor = mockEditor;
90
- Object.defineProperty(document.body, 'getBoundingClientRect', {
91
- value: jest.fn(() => ({ top: 0, left: 0 })),
92
- configurable: true,
93
- });
94
- });
95
-
96
- it('renders without crashing', () => {
97
- const { container } = render(<InlineDropdown {...defaultProps} />);
98
- expect(container).toBeInTheDocument();
99
- });
100
-
101
- it('renders NodeViewWrapper', () => {
102
- const { getByTestId } = render(<InlineDropdown {...defaultProps} />);
103
- expect(getByTestId('node-view-wrapper')).toBeInTheDocument();
104
- });
105
-
106
- it('displays selected value', () => {
107
- const { container } = render(<InlineDropdown {...defaultProps} />);
108
- const valueDiv = container.querySelector('div[style*="border"]');
109
- expect(valueDiv).toBeInTheDocument();
110
- });
111
-
112
- it('renders math inside the value control on mount', () => {
113
- const { container } = render(<InlineDropdown {...defaultProps} />);
114
- const valueDiv = container.querySelector('div[style*="border"]');
115
-
116
- expect(renderMath).toHaveBeenCalledWith(valueDiv);
117
- });
118
-
119
- it('re-renders math when the value changes', () => {
120
- const updatedNode = {
121
- ...mockNode,
122
- attrs: {
123
- ...mockNode.attrs,
124
- value: '<span>Updated math</span>',
125
- },
126
- };
127
-
128
- const { container, rerender } = render(<InlineDropdown {...defaultProps} />);
129
-
130
- renderMath.mockClear();
131
-
132
- rerender(<InlineDropdown {...defaultProps} node={updatedNode} />);
133
-
134
- const valueDiv = container.querySelector('div[style*="border"]');
135
- expect(renderMath).toHaveBeenCalledWith(valueDiv);
136
- });
137
-
138
- it('uses 2px horizontal margin on the value control and no horizontal margin on the wrapper', () => {
139
- const { container, getByTestId } = render(<InlineDropdown {...defaultProps} />);
140
- const valueDiv = container.querySelector('div[style*="border"]');
141
- expect(valueDiv).toHaveStyle({ margin: '0 2px' });
142
- const wrapper = getByTestId('node-view-wrapper');
143
- expect(wrapper.getAttribute('style') || '').not.toMatch(/margin/);
144
- });
145
-
146
- it('renders chevron icon', () => {
147
- const { container } = render(<InlineDropdown {...defaultProps} />);
148
- const chevron = container.querySelector('svg');
149
- expect(chevron).toBeInTheDocument();
150
- });
151
-
152
- it('shows toolbar when selected and only this node is selected', async () => {
153
- const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
154
- await waitFor(() => {
155
- // Toolbar is shown via portal
156
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
157
- });
158
- });
159
-
160
- it('does not show toolbar when not selected', () => {
161
- const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={false} />);
162
- expect(queryByTestId('inline-dropdown-toolbar')).not.toBeInTheDocument();
163
- });
164
-
165
- it('shows toolbar on click', async () => {
166
- const { container, queryByTestId } = render(<InlineDropdown {...defaultProps} />);
167
- const dropdown = container.querySelector('div[style*="border"]');
168
- if (dropdown) {
169
- fireEvent.click(dropdown);
170
- await waitFor(() => {
171
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
172
- });
173
- } else {
174
- // If dropdown is not found, just verify the component rendered
175
- expect(container).toBeInTheDocument();
176
- }
177
- });
178
-
179
- it('has correct minimum dimensions', () => {
180
- const { container } = render(<InlineDropdown {...defaultProps} />);
181
- const wrapper = container.querySelector('[data-testid="node-view-wrapper"]');
182
- expect(wrapper).toHaveStyle({ height: '50px' });
183
- });
184
-
185
- it('has inline-flex display', () => {
186
- const { container } = render(<InlineDropdown {...defaultProps} />);
187
- const wrapper = container.querySelector('[data-testid="node-view-wrapper"]');
188
- expect(wrapper).toHaveStyle({ display: 'inline-flex' });
189
- });
190
-
191
- it('has cursor pointer style', () => {
192
- const { container } = render(<InlineDropdown {...defaultProps} />);
193
- const wrapper = container.querySelector('[data-testid="node-view-wrapper"]');
194
- expect(wrapper).toHaveStyle({ cursor: 'pointer' });
195
- });
196
-
197
- it('renders with empty value as nbsp', () => {
198
- const emptyNode = { ...mockNode, attrs: { ...mockNode.attrs, value: '' } };
199
- const { container } = render(<InlineDropdown {...defaultProps} node={emptyNode} />);
200
- expect(container).toBeInTheDocument();
201
- });
202
-
203
- it('calls respAreaToolbar with correct params', () => {
204
- render(<InlineDropdown {...defaultProps} />);
205
- expect(mockOptions.respAreaToolbar).toHaveBeenCalledWith([mockNode, 5], mockEditor, expect.any(Function));
206
- });
207
-
208
- it('closes toolbar on outside click', async () => {
209
- const { container, queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
210
- await waitFor(() => {
211
- fireEvent.mouseDown(document.body);
212
- });
213
- // After clicking outside, toolbar should be hidden
214
- await waitFor(() => {
215
- expect(queryByTestId('inline-dropdown-toolbar')).not.toBeInTheDocument();
216
- });
217
- });
218
-
219
- it('calls close callback when toolbar closes on outside click', async () => {
220
- const onInlineDropdownToolbarClose = jest.fn();
221
- const options = {
222
- ...mockOptions,
223
- onInlineDropdownToolbarClose,
224
- };
225
-
226
- const { queryByTestId } = render(<InlineDropdown {...defaultProps} options={options} selected={true} />);
227
-
228
- await waitFor(() => {
229
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
230
- });
231
-
232
- fireEvent.mouseDown(document.body);
233
-
234
- await waitFor(() => {
235
- expect(queryByTestId('inline-dropdown-toolbar')).not.toBeInTheDocument();
236
- });
237
-
238
- expect(onInlineDropdownToolbarClose).toHaveBeenCalledWith(mockEditor);
239
- });
240
-
241
- it('uses the current node when closing on outside click after the node prop changes', async () => {
242
- const onToolbarCloseRequest = jest.fn((_tuple, _editor, onConfirm) => onConfirm());
243
- const options = {
244
- ...mockOptions,
245
- onToolbarCloseRequest,
246
- };
247
- const updatedNode = {
248
- attrs: { index: '1', value: 'Updated Option', error: false },
249
- nodeSize: 1,
250
- };
251
-
252
- const { queryByTestId, rerender } = render(<InlineDropdown {...defaultProps} options={options} selected={true} />);
253
-
254
- await waitFor(() => {
255
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
256
- });
257
-
258
- rerender(<InlineDropdown {...defaultProps} options={options} node={updatedNode} selected={true} />);
259
-
260
- fireEvent.mouseDown(document.body);
261
-
262
- await waitFor(() => {
263
- expect(onToolbarCloseRequest).toHaveBeenCalledWith(
264
- [updatedNode, 5],
265
- expect.anything(),
266
- expect.any(Function),
267
- expect.any(Function),
268
- );
269
- });
270
- });
271
-
272
- it('respects hold state for the current node after the node prop changes', async () => {
273
- const updatedNode = {
274
- attrs: { index: '1', value: 'Updated Option', error: false },
275
- nodeSize: 1,
276
- };
277
-
278
- mockEditor._holdInlineDropdownToolbarIndex = '1';
279
-
280
- const { queryByTestId, rerender } = render(<InlineDropdown {...defaultProps} selected={true} />);
281
-
282
- await waitFor(() => {
283
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
284
- });
285
-
286
- rerender(<InlineDropdown {...defaultProps} node={updatedNode} selected={true} />);
287
-
288
- fireEvent.mouseDown(document.body);
289
-
290
- await waitFor(() => {
291
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
292
- });
293
- });
294
-
295
- it('rebinds the outside-click listener when the node prop changes while the toolbar is open', async () => {
296
- const addSpy = jest.spyOn(document, 'addEventListener');
297
- const removeSpy = jest.spyOn(document, 'removeEventListener');
298
- const updatedNode = { ...mockNode, attrs: { ...mockNode.attrs, value: 'Updated Option' } };
299
-
300
- const { rerender } = render(<InlineDropdown {...defaultProps} selected={true} />);
301
-
302
- await waitFor(() => {
303
- expect(addSpy).toHaveBeenCalledWith('mousedown', expect.any(Function));
304
- });
305
-
306
- const removeCallsBeforeRerender = removeSpy.mock.calls.filter(([type]) => type === 'mousedown').length;
307
-
308
- rerender(<InlineDropdown {...defaultProps} node={updatedNode} selected={true} />);
309
-
310
- await waitFor(() => {
311
- const removeCallsAfterRerender = removeSpy.mock.calls.filter(([type]) => type === 'mousedown').length;
312
- expect(removeCallsAfterRerender).toBeGreaterThan(removeCallsBeforeRerender);
313
- expect(addSpy).toHaveBeenCalledWith('mousedown', expect.any(Function));
314
- });
315
-
316
- addSpy.mockRestore();
317
- removeSpy.mockRestore();
318
- });
319
-
320
- it('has correct border styling', () => {
321
- const { container } = render(<InlineDropdown {...defaultProps} />);
322
- const dropdownDiv = container.querySelector('div[style*="border"]');
323
- expect(dropdownDiv).toHaveStyle({ border: '1px solid #C0C3CF' });
324
- });
325
-
326
- it('has correct min width', () => {
327
- const { container } = render(<InlineDropdown {...defaultProps} />);
328
- const dropdownDiv = container.querySelector('div[style*="border"]');
329
- expect(dropdownDiv).toHaveStyle({ minWidth: '178px' });
330
- });
331
-
332
- it('positions chevron correctly', () => {
333
- const { container } = render(<InlineDropdown {...defaultProps} />);
334
- const chevron = container.querySelector('svg');
335
- // Chevron styling is applied inline, just verify it rendered
336
- if (chevron) {
337
- expect(chevron).toBeInTheDocument();
338
- } else {
339
- expect(container).toBeInTheDocument();
340
- }
341
- });
342
-
343
- it('has ellipsis for overflow text', () => {
344
- const { container } = render(<InlineDropdown {...defaultProps} />);
345
- const textContainer = container.querySelector('div[style*="overflow"]');
346
- expect(textContainer).toHaveStyle({ textOverflow: 'ellipsis', whiteSpace: 'nowrap' });
347
- });
348
-
349
- it('portals toolbar into editor container when _tiptapContainerEl is set', async () => {
350
- const containerEl = document.createElement('div');
351
- const editor = buildMockEditor({ _tiptapContainerEl: containerEl });
352
-
353
- render(<InlineDropdown {...defaultProps} editor={editor} selected={true} />);
354
-
355
- await waitFor(() => {
356
- expect(mockCreatePortal).toHaveBeenCalled();
357
- });
358
-
359
- expect(mockCreatePortal.mock.calls[0][1]).toBe(containerEl);
360
- });
361
-
362
- it('portals toolbar into document.body when _tiptapContainerEl is missing', async () => {
363
- const editor = buildMockEditor({ _tiptapContainerEl: undefined });
364
-
365
- render(<InlineDropdown {...defaultProps} editor={editor} selected={true} />);
366
-
367
- await waitFor(() => {
368
- expect(mockCreatePortal).toHaveBeenCalled();
369
- });
370
-
371
- expect(mockCreatePortal.mock.calls[0][1]).toBe(document.body);
372
- });
373
-
374
- it('passes editorCallback to InlineDropdownToolbar', async () => {
375
- const mockToolbarComponent = jest.fn(({ editorCallback }) => {
376
- editorCallback?.({ instanceId: 'test-instance' });
377
- return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
378
- });
379
-
380
- const mockOptionsWithCallback = {
381
- respAreaToolbar: jest.fn(() => mockToolbarComponent),
382
- };
383
-
384
- const { queryByTestId } = render(
385
- <InlineDropdown {...defaultProps} options={mockOptionsWithCallback} selected={true} />,
386
- );
387
-
388
- await waitFor(() => {
389
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
390
- });
391
- });
392
-
393
- it('stores toolbar editor instance in ref when editorCallback is called', async () => {
394
- let capturedCallback;
395
- const mockToolbarComponent = ({ editorCallback }) => {
396
- capturedCallback = editorCallback;
397
- return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
398
- };
399
-
400
- const mockOptionsWithCallback = {
401
- respAreaToolbar: jest.fn(() => mockToolbarComponent),
402
- };
403
-
404
- const { queryByTestId } = render(
405
- <InlineDropdown {...defaultProps} options={mockOptionsWithCallback} selected={true} />,
406
- );
407
-
408
- await waitFor(() => {
409
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
410
- });
411
-
412
- // Verify callback exists
413
- expect(capturedCallback).toBeDefined();
414
- });
415
-
416
- it('handles click outside logic with data-toolbar-for attribute', async () => {
417
- const editorWithInstanceId = {
418
- ...mockEditor,
419
- instanceId: 'editor-123',
420
- _toolbarOpened: false,
421
- };
422
-
423
- // Mock the toolbar callback to set the toolbar editor instance
424
- let capturedCallback;
425
- const mockToolbarComponent = ({ editorCallback }) => {
426
- React.useEffect(() => {
427
- capturedCallback = editorCallback;
428
- if (editorCallback) {
429
- editorCallback({ instanceId: 'editor-123' });
430
- }
431
- }, [editorCallback]);
432
- return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
433
- };
434
-
435
- const mockOptionsWithCallback = {
436
- respAreaToolbar: jest.fn(() => mockToolbarComponent),
437
- };
438
-
439
- const { container, queryByTestId } = render(
440
- <InlineDropdown
441
- {...defaultProps}
442
- editor={editorWithInstanceId}
443
- options={mockOptionsWithCallback}
444
- selected={true}
445
- />,
446
- );
447
-
448
- await waitFor(() => {
449
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
450
- });
451
-
452
- // Create an element with data-toolbar-for attribute
453
- const otherToolbar = document.createElement('div');
454
- otherToolbar.setAttribute('data-toolbar-for', 'editor-456');
455
- document.body.appendChild(otherToolbar);
456
-
457
- await waitFor(() => {
458
- fireEvent.mouseDown(otherToolbar);
459
- });
460
-
461
- // Cleanup
462
- document.body.removeChild(otherToolbar);
463
- expect(container).toBeInTheDocument();
464
- });
465
-
466
- it('does not close when clicking inside same editor toolbar', async () => {
467
- const editorWithInstanceId = {
468
- ...mockEditor,
469
- instanceId: 'editor-123',
470
- _toolbarOpened: false,
471
- };
472
-
473
- let toolbarEditorInstance;
474
- const mockToolbarComponent = ({ editorCallback }) => {
475
- React.useEffect(() => {
476
- if (editorCallback) {
477
- editorCallback({ instanceId: 'editor-123' });
478
- toolbarEditorInstance = { instanceId: 'editor-123' };
479
- }
480
- }, [editorCallback]);
481
- return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
482
- };
483
-
484
- const mockOptionsWithCallback = {
485
- respAreaToolbar: jest.fn(() => mockToolbarComponent),
486
- };
487
-
488
- render(
489
- <InlineDropdown
490
- {...defaultProps}
491
- editor={editorWithInstanceId}
492
- options={mockOptionsWithCallback}
493
- selected={true}
494
- />,
495
- );
496
-
497
- await waitFor(() => {
498
- expect(mockOptionsWithCallback.respAreaToolbar).toHaveBeenCalled();
499
- });
500
- });
501
-
502
- it('checks editor._toolbarOpened in click outside handler', async () => {
503
- const editorWithToolbarOpened = buildMockEditor({ _toolbarOpened: true });
504
-
505
- const { queryByTestId } = render(
506
- <InlineDropdown {...defaultProps} editor={editorWithToolbarOpened} selected={true} />,
507
- );
508
-
509
- await waitFor(() => {
510
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
511
- });
512
-
513
- // When _toolbarOpened is true, clicking outside should not close
514
- fireEvent.mouseDown(document.body);
515
-
516
- // Toolbar should still be visible
517
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
518
- });
519
-
520
- it('does not close toolbar when clicking the page scrollbar (documentElement)', async () => {
521
- const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
522
-
523
- await waitFor(() => {
524
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
525
- });
526
-
527
- fireEvent.mouseDown(document.documentElement);
528
-
529
- await waitFor(() => {
530
- expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
531
- });
532
- });
533
-
534
- it('renders delete control on portaled custom toolbar when container el is set', async () => {
535
- const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
536
- expect(await findByLabelText('Delete')).toBeInTheDocument();
537
- });
538
-
539
- it('does not render portaled delete control when _tiptapContainerEl is missing', async () => {
540
- const editor = buildMockEditor({ _tiptapContainerEl: undefined });
541
- const { queryByLabelText, findByTestId } = render(<InlineDropdown {...defaultProps} editor={editor} selected />);
542
- expect(await findByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
543
- expect(queryByLabelText('Delete')).not.toBeInTheDocument();
544
- });
545
-
546
- it('delete clears toolbar flag, removes node range, dispatches, and focuses', async () => {
547
- mockEditor._toolbarOpened = true;
548
- const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
549
- fireEvent.mouseDown(await findByLabelText('Delete'));
550
- expect(mockEditor.state.tr.delete).toHaveBeenCalledWith(5, 6);
551
- expect(mockEditor.view.dispatch).toHaveBeenCalledTimes(2);
552
- expect(mockEditor.view.dispatch).toHaveBeenNthCalledWith(1, mockEditor.state.tr);
553
- expect(mockEditor.view.dispatch).toHaveBeenNthCalledWith(2, mockEditor.state.tr);
554
- expect(mockEditor._toolbarOpened).toBe(false);
555
- expect(mockEditor.commands.focus).toHaveBeenCalled();
556
- });
557
- });