@pie-lib/editable-html-tip-tap 2.2.0-beta.7 → 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.
- package/package.json +3 -3
- package/lib/__tests__/EditableHtml.test.js +0 -831
- package/lib/__tests__/EditableHtml.test.js.map +0 -1
- package/lib/__tests__/constants.test.js +0 -21
- package/lib/__tests__/constants.test.js.map +0 -1
- package/lib/__tests__/div-to-paragraph-conversion.test.js +0 -213
- package/lib/__tests__/div-to-paragraph-conversion.test.js.map +0 -1
- package/lib/__tests__/extensions.test.js +0 -209
- package/lib/__tests__/extensions.test.js.map +0 -1
- package/lib/__tests__/index.test.js +0 -250
- package/lib/__tests__/index.test.js.map +0 -1
- package/lib/__tests__/size-utils.test.js +0 -57
- package/lib/__tests__/size-utils.test.js.map +0 -1
- package/lib/__tests__/theme.test.js +0 -17
- package/lib/__tests__/theme.test.js.map +0 -1
- package/lib/components/__tests__/AltDialog.test.js +0 -201
- package/lib/components/__tests__/AltDialog.test.js.map +0 -1
- package/lib/components/__tests__/CharacterPicker.test.js +0 -455
- package/lib/components/__tests__/CharacterPicker.test.js.map +0 -1
- package/lib/components/__tests__/CssIcon.test.js +0 -58
- package/lib/components/__tests__/CssIcon.test.js.map +0 -1
- package/lib/components/__tests__/DragInTheBlank.test.js +0 -295
- package/lib/components/__tests__/DragInTheBlank.test.js.map +0 -1
- package/lib/components/__tests__/ExplicitConstructedResponse.test.js +0 -345
- package/lib/components/__tests__/ExplicitConstructedResponse.test.js.map +0 -1
- package/lib/components/__tests__/ImageToolbar.test.js +0 -185
- package/lib/components/__tests__/ImageToolbar.test.js.map +0 -1
- package/lib/components/__tests__/InlineDropdown.test.js +0 -839
- package/lib/components/__tests__/InlineDropdown.test.js.map +0 -1
- package/lib/components/__tests__/InsertImageHandler.test.js +0 -171
- package/lib/components/__tests__/InsertImageHandler.test.js.map +0 -1
- package/lib/components/__tests__/MediaDialog.test.js +0 -433
- package/lib/components/__tests__/MediaDialog.test.js.map +0 -1
- package/lib/components/__tests__/MediaToolbar.test.js +0 -126
- package/lib/components/__tests__/MediaToolbar.test.js.map +0 -1
- package/lib/components/__tests__/MediaWrapper.test.js +0 -96
- package/lib/components/__tests__/MediaWrapper.test.js.map +0 -1
- package/lib/components/__tests__/MenuBar.test.js +0 -502
- package/lib/components/__tests__/MenuBar.test.js.map +0 -1
- package/lib/components/__tests__/RespArea.test.js +0 -171
- package/lib/components/__tests__/RespArea.test.js.map +0 -1
- package/lib/components/__tests__/TableIcons.test.js +0 -153
- package/lib/components/__tests__/TableIcons.test.js.map +0 -1
- package/lib/components/__tests__/TextAlign.test.js +0 -209
- package/lib/components/__tests__/TextAlign.test.js.map +0 -1
- package/lib/components/__tests__/TiptapContainer.test.js +0 -196
- package/lib/components/__tests__/TiptapContainer.test.js.map +0 -1
- package/lib/components/__tests__/characterUtils.test.js +0 -178
- package/lib/components/__tests__/characterUtils.test.js.map +0 -1
- package/lib/components/__tests__/choice.test.js +0 -213
- package/lib/components/__tests__/choice.test.js.map +0 -1
- package/lib/components/__tests__/custom-popper.test.js +0 -108
- package/lib/components/__tests__/custom-popper.test.js.map +0 -1
- package/lib/components/__tests__/done-button.test.js +0 -72
- package/lib/components/__tests__/done-button.test.js.map +0 -1
- package/lib/components/__tests__/toolbar-buttons.test.js +0 -277
- package/lib/components/__tests__/toolbar-buttons.test.js.map +0 -1
- package/lib/components/respArea/DragInTheBlank/__tests__/choice.test.js +0 -90
- package/lib/components/respArea/DragInTheBlank/__tests__/choice.test.js.map +0 -1
- package/lib/components/respArea/__tests__/MathTemplated.test.js +0 -217
- package/lib/components/respArea/__tests__/MathTemplated.test.js.map +0 -1
- package/lib/extensions/__tests__/css.test.js +0 -214
- package/lib/extensions/__tests__/css.test.js.map +0 -1
- package/lib/extensions/__tests__/custom-toolbar-wrapper.test.js +0 -175
- package/lib/extensions/__tests__/custom-toolbar-wrapper.test.js.map +0 -1
- package/lib/extensions/__tests__/divNode.test.js +0 -108
- package/lib/extensions/__tests__/divNode.test.js.map +0 -1
- package/lib/extensions/__tests__/ensure-empty-root-div.test.js +0 -50
- package/lib/extensions/__tests__/ensure-empty-root-div.test.js.map +0 -1
- package/lib/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -60
- package/lib/extensions/__tests__/ensure-list-item-content-is-div.test.js.map +0 -1
- package/lib/extensions/__tests__/extended-list-item.test.js +0 -13
- package/lib/extensions/__tests__/extended-list-item.test.js.map +0 -1
- package/lib/extensions/__tests__/extended-table-cell.test.js +0 -15
- package/lib/extensions/__tests__/extended-table-cell.test.js.map +0 -1
- package/lib/extensions/__tests__/extended-table.test.js +0 -200
- package/lib/extensions/__tests__/extended-table.test.js.map +0 -1
- package/lib/extensions/__tests__/image-component.test.js +0 -432
- package/lib/extensions/__tests__/image-component.test.js.map +0 -1
- package/lib/extensions/__tests__/image.test.js +0 -313
- package/lib/extensions/__tests__/image.test.js.map +0 -1
- package/lib/extensions/__tests__/math.test.js +0 -1411
- package/lib/extensions/__tests__/math.test.js.map +0 -1
- package/lib/extensions/__tests__/media-node-view.test.js +0 -307
- package/lib/extensions/__tests__/media-node-view.test.js.map +0 -1
- package/lib/extensions/__tests__/media.test.js +0 -292
- package/lib/extensions/__tests__/media.test.js.map +0 -1
- package/lib/extensions/__tests__/responseArea.test.js +0 -736
- package/lib/extensions/__tests__/responseArea.test.js.map +0 -1
- package/lib/utils/__tests__/helper.test.js +0 -107
- package/lib/utils/__tests__/helper.test.js.map +0 -1
- package/lib/utils/__tests__/toolbar.test.js +0 -38
- package/lib/utils/__tests__/toolbar.test.js.map +0 -1
- package/src/__tests__/EditableHtml.test.jsx +0 -588
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/extensions.test.js +0 -208
- package/src/__tests__/index.test.jsx +0 -154
- package/src/__tests__/size-utils.test.js +0 -64
- package/src/__tests__/theme.test.js +0 -17
- package/src/components/__tests__/AltDialog.test.jsx +0 -147
- package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
- package/src/components/__tests__/CssIcon.test.jsx +0 -46
- package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
- package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
- package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
- package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
- package/src/components/__tests__/InsertImageHandler.test.js +0 -161
- package/src/components/__tests__/MediaDialog.test.jsx +0 -293
- package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
- package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
- package/src/components/__tests__/MenuBar.test.jsx +0 -250
- package/src/components/__tests__/RespArea.test.jsx +0 -122
- package/src/components/__tests__/TableIcons.test.jsx +0 -149
- package/src/components/__tests__/TextAlign.test.jsx +0 -167
- package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
- package/src/components/__tests__/characterUtils.test.js +0 -166
- package/src/components/__tests__/choice.test.jsx +0 -171
- package/src/components/__tests__/custom-popper.test.jsx +0 -82
- package/src/components/__tests__/done-button.test.jsx +0 -54
- package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
- package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
- package/src/extensions/__tests__/css.test.js +0 -196
- package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
- package/src/extensions/__tests__/divNode.test.js +0 -87
- package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
- package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
- package/src/extensions/__tests__/extended-list-item.test.js +0 -13
- package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
- package/src/extensions/__tests__/extended-table.test.js +0 -183
- package/src/extensions/__tests__/image-component.test.jsx +0 -346
- package/src/extensions/__tests__/image.test.js +0 -237
- package/src/extensions/__tests__/math.test.js +0 -900
- package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
- package/src/extensions/__tests__/media.test.js +0 -271
- package/src/extensions/__tests__/responseArea.test.js +0 -655
- package/src/utils/__tests__/helper.test.js +0 -126
- 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
|
-
});
|