@pie-lib/editable-html-tip-tap 2.1.2-next.3 → 2.1.2-next.30
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/dist/components/CharacterPicker.d.ts +31 -0
- package/dist/components/CharacterPicker.js +131 -0
- package/dist/components/EditableHtml.d.ts +11 -0
- package/dist/components/EditableHtml.js +291 -0
- package/dist/components/MenuBar.d.ts +11 -0
- package/dist/components/MenuBar.js +462 -0
- package/dist/components/TiptapContainer.d.ts +11 -0
- package/dist/components/TiptapContainer.js +154 -0
- package/dist/components/characters/characterUtils.d.ts +35 -0
- package/dist/components/characters/characterUtils.js +465 -0
- package/dist/components/characters/custom-popper.d.ts +14 -0
- package/dist/components/characters/custom-popper.js +32 -0
- package/dist/components/common/done-button.d.ts +30 -0
- package/dist/components/common/done-button.js +26 -0
- package/dist/components/common/toolbar-buttons.d.ts +38 -0
- package/dist/components/common/toolbar-buttons.js +91 -0
- package/dist/components/icons/CssIcon.d.ts +11 -0
- package/dist/components/icons/CssIcon.js +14 -0
- package/dist/components/icons/RespArea.d.ts +26 -0
- package/dist/components/icons/RespArea.js +42 -0
- package/dist/components/icons/TableIcons.d.ts +14 -0
- package/dist/components/icons/TableIcons.js +32 -0
- package/dist/components/icons/TextAlign.d.ts +18 -0
- package/dist/components/icons/TextAlign.js +134 -0
- package/dist/components/image/AltDialog.d.ts +22 -0
- package/dist/components/image/AltDialog.js +61 -0
- package/dist/components/image/ImageToolbar.d.ts +24 -0
- package/dist/components/image/ImageToolbar.js +80 -0
- package/dist/components/image/InsertImageHandler.d.ts +32 -0
- package/dist/components/image/InsertImageHandler.js +53 -0
- package/dist/components/media/MediaDialog.d.ts +43 -0
- package/dist/components/media/MediaDialog.js +389 -0
- package/dist/components/media/MediaToolbar.d.ts +19 -0
- package/dist/components/media/MediaToolbar.js +41 -0
- package/dist/components/media/MediaWrapper.d.ts +19 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
- package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
- package/dist/components/respArea/DragInTheBlank/choice.js +156 -0
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
- package/dist/components/respArea/ExplicitConstructedResponse.js +83 -0
- package/dist/components/respArea/InlineDropdown.d.ts +18 -0
- package/dist/components/respArea/InlineDropdown.js +119 -0
- package/dist/components/respArea/MathTemplated.d.ts +19 -0
- package/dist/components/respArea/MathTemplated.js +97 -0
- package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
- package/dist/components/respArea/ToolbarIcon.js +17 -0
- package/dist/components/respArea/inlineDropdownUtils.d.ts +15 -0
- package/dist/components/respArea/inlineDropdownUtils.js +15 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +4 -0
- package/dist/extensions/css.d.ts +11 -0
- package/dist/extensions/css.js +115 -0
- package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
- package/dist/extensions/custom-toolbar-wrapper.js +61 -0
- package/dist/extensions/div-node.d.ts +10 -0
- package/dist/extensions/div-node.js +42 -0
- package/dist/extensions/ensure-empty-root-div.d.ts +14 -0
- package/dist/extensions/ensure-empty-root-div.js +24 -0
- package/dist/extensions/ensure-list-item-content-is-div.d.ts +15 -0
- package/dist/extensions/ensure-list-item-content-is-div.js +31 -0
- package/dist/extensions/extended-list-item.d.ts +13 -0
- package/dist/extensions/extended-list-item.js +5 -0
- package/dist/extensions/extended-table-cell.d.ts +10 -0
- package/dist/extensions/extended-table-cell.js +6 -0
- package/dist/extensions/extended-table.d.ts +17 -0
- package/dist/extensions/extended-table.js +34 -0
- package/dist/extensions/heading-paragraph.d.ts +17 -0
- package/dist/extensions/heading-paragraph.js +30 -0
- package/dist/extensions/image-component.d.ts +22 -0
- package/dist/extensions/image-component.js +220 -0
- package/dist/extensions/image.d.ts +10 -0
- package/dist/extensions/image.js +68 -0
- package/dist/extensions/index.d.ts +16 -0
- package/dist/extensions/index.js +64 -0
- package/dist/extensions/math.d.ts +15 -0
- package/dist/extensions/math.js +158 -0
- package/dist/extensions/media.d.ts +19 -0
- package/dist/extensions/media.js +149 -0
- package/dist/extensions/responseArea.d.ts +27 -0
- package/dist/extensions/responseArea.js +259 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/styles/editorContainerStyles.d.ts +134 -0
- package/dist/theme.d.ts +9 -0
- package/dist/utils/helper.d.ts +9 -0
- package/dist/utils/helper.js +27 -0
- package/dist/utils/size.d.ts +9 -0
- package/dist/utils/size.js +14 -0
- package/package.json +56 -40
- package/CHANGELOG.json +0 -32
- package/CHANGELOG.md +0 -2532
- package/LICENSE.md +0 -5
- package/lib/components/CharacterPicker.js +0 -195
- package/lib/components/CharacterPicker.js.map +0 -1
- package/lib/components/EditableHtml.js +0 -375
- package/lib/components/EditableHtml.js.map +0 -1
- package/lib/components/MenuBar.js +0 -693
- package/lib/components/MenuBar.js.map +0 -1
- package/lib/components/TiptapContainer.js +0 -234
- package/lib/components/TiptapContainer.js.map +0 -1
- package/lib/components/characters/characterUtils.js +0 -378
- package/lib/components/characters/characterUtils.js.map +0 -1
- package/lib/components/characters/custom-popper.js +0 -44
- package/lib/components/characters/custom-popper.js.map +0 -1
- package/lib/components/common/done-button.js +0 -34
- package/lib/components/common/done-button.js.map +0 -1
- package/lib/components/common/toolbar-buttons.js +0 -144
- package/lib/components/common/toolbar-buttons.js.map +0 -1
- package/lib/components/icons/CssIcon.js +0 -25
- package/lib/components/icons/CssIcon.js.map +0 -1
- package/lib/components/icons/RespArea.js +0 -72
- package/lib/components/icons/RespArea.js.map +0 -1
- package/lib/components/icons/TableIcons.js +0 -53
- package/lib/components/icons/TableIcons.js.map +0 -1
- package/lib/components/icons/TextAlign.js +0 -157
- package/lib/components/icons/TextAlign.js.map +0 -1
- package/lib/components/image/AltDialog.js +0 -98
- package/lib/components/image/AltDialog.js.map +0 -1
- package/lib/components/image/ImageToolbar.js +0 -137
- package/lib/components/image/ImageToolbar.js.map +0 -1
- package/lib/components/image/InsertImageHandler.js +0 -135
- package/lib/components/image/InsertImageHandler.js.map +0 -1
- package/lib/components/media/MediaDialog.js +0 -594
- package/lib/components/media/MediaDialog.js.map +0 -1
- package/lib/components/media/MediaToolbar.js +0 -74
- package/lib/components/media/MediaToolbar.js.map +0 -1
- package/lib/components/media/MediaWrapper.js +0 -67
- package/lib/components/media/MediaWrapper.js.map +0 -1
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +0 -84
- package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +0 -1
- package/lib/components/respArea/DragInTheBlank/choice.js +0 -250
- package/lib/components/respArea/DragInTheBlank/choice.js.map +0 -1
- package/lib/components/respArea/ExplicitConstructedResponse.js +0 -136
- package/lib/components/respArea/ExplicitConstructedResponse.js.map +0 -1
- package/lib/components/respArea/InlineDropdown.js +0 -165
- package/lib/components/respArea/InlineDropdown.js.map +0 -1
- package/lib/components/respArea/MathTemplated.js +0 -130
- package/lib/components/respArea/MathTemplated.js.map +0 -1
- package/lib/components/respArea/ToolbarIcon.js +0 -81
- package/lib/components/respArea/ToolbarIcon.js.map +0 -1
- package/lib/constants.js +0 -11
- package/lib/constants.js.map +0 -1
- package/lib/extensions/css.js +0 -217
- package/lib/extensions/css.js.map +0 -1
- package/lib/extensions/custom-toolbar-wrapper.js +0 -92
- package/lib/extensions/custom-toolbar-wrapper.js.map +0 -1
- package/lib/extensions/div-node.js +0 -83
- package/lib/extensions/div-node.js.map +0 -1
- package/lib/extensions/ensure-empty-root-div.js +0 -48
- package/lib/extensions/ensure-empty-root-div.js.map +0 -1
- package/lib/extensions/ensure-list-item-content-is-div.js +0 -64
- package/lib/extensions/ensure-list-item-content-is-div.js.map +0 -1
- package/lib/extensions/extended-list-item.js +0 -15
- package/lib/extensions/extended-list-item.js.map +0 -1
- package/lib/extensions/extended-table-cell.js +0 -22
- package/lib/extensions/extended-table-cell.js.map +0 -1
- package/lib/extensions/extended-table.js +0 -75
- package/lib/extensions/extended-table.js.map +0 -1
- package/lib/extensions/heading-paragraph.js +0 -61
- package/lib/extensions/heading-paragraph.js.map +0 -1
- package/lib/extensions/image-component.js +0 -348
- package/lib/extensions/image-component.js.map +0 -1
- package/lib/extensions/image.js +0 -134
- package/lib/extensions/image.js.map +0 -1
- package/lib/extensions/index.js +0 -46
- package/lib/extensions/index.js.map +0 -1
- package/lib/extensions/math.js +0 -343
- package/lib/extensions/math.js.map +0 -1
- package/lib/extensions/media.js +0 -243
- package/lib/extensions/media.js.map +0 -1
- package/lib/extensions/responseArea.js +0 -446
- package/lib/extensions/responseArea.js.map +0 -1
- package/lib/index.js +0 -30
- package/lib/index.js.map +0 -1
- package/lib/styles/editorContainerStyles.js +0 -137
- package/lib/styles/editorContainerStyles.js.map +0 -1
- package/lib/theme.js +0 -8
- package/lib/theme.js.map +0 -1
- package/lib/utils/helper.js +0 -73
- package/lib/utils/helper.js.map +0 -1
- package/lib/utils/size.js +0 -26
- package/lib/utils/size.js.map +0 -1
- package/src/__tests__/EditableHtml.test.jsx +0 -474
- 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/CharacterPicker.jsx +0 -200
- package/src/components/EditableHtml.jsx +0 -438
- package/src/components/MenuBar.jsx +0 -549
- package/src/components/TiptapContainer.jsx +0 -219
- package/src/components/__tests__/AltDialog.test.jsx +0 -147
- package/src/components/__tests__/CharacterPicker.test.jsx +0 -219
- 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 -204
- package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
- package/src/components/__tests__/InlineDropdown.test.jsx +0 -380
- 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 -249
- 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/characters/characterUtils.js +0 -447
- package/src/components/characters/custom-popper.js +0 -38
- package/src/components/common/done-button.jsx +0 -27
- package/src/components/common/toolbar-buttons.jsx +0 -122
- package/src/components/icons/CssIcon.jsx +0 -15
- package/src/components/icons/RespArea.jsx +0 -71
- package/src/components/icons/TableIcons.jsx +0 -52
- package/src/components/icons/TextAlign.jsx +0 -114
- package/src/components/image/AltDialog.jsx +0 -82
- package/src/components/image/ImageToolbar.jsx +0 -99
- package/src/components/image/InsertImageHandler.js +0 -107
- package/src/components/media/MediaDialog.jsx +0 -596
- package/src/components/media/MediaToolbar.jsx +0 -49
- package/src/components/media/MediaWrapper.jsx +0 -39
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.jsx +0 -76
- package/src/components/respArea/DragInTheBlank/choice.jsx +0 -256
- package/src/components/respArea/ExplicitConstructedResponse.jsx +0 -135
- package/src/components/respArea/InlineDropdown.jsx +0 -167
- package/src/components/respArea/MathTemplated.jsx +0 -124
- package/src/components/respArea/ToolbarIcon.jsx +0 -66
- package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
- package/src/constants.js +0 -5
- 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 -345
- package/src/extensions/__tests__/image.test.js +0 -237
- package/src/extensions/__tests__/math.test.js +0 -459
- 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 -601
- package/src/extensions/css.js +0 -220
- package/src/extensions/custom-toolbar-wrapper.jsx +0 -78
- package/src/extensions/div-node.js +0 -86
- package/src/extensions/ensure-empty-root-div.js +0 -47
- package/src/extensions/ensure-list-item-content-is-div.js +0 -62
- package/src/extensions/extended-list-item.js +0 -10
- package/src/extensions/extended-table-cell.js +0 -19
- package/src/extensions/extended-table.js +0 -60
- package/src/extensions/heading-paragraph.js +0 -53
- package/src/extensions/image-component.jsx +0 -338
- package/src/extensions/image.js +0 -109
- package/src/extensions/index.js +0 -81
- package/src/extensions/math.js +0 -327
- package/src/extensions/media.js +0 -188
- package/src/extensions/responseArea.js +0 -401
- package/src/index.jsx +0 -5
- package/src/styles/editorContainerStyles.js +0 -145
- package/src/theme.js +0 -1
- package/src/utils/__tests__/helper.test.js +0 -126
- package/src/utils/helper.js +0 -69
- package/src/utils/size.js +0 -32
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render, waitFor } from '@testing-library/react';
|
|
3
|
-
import InlineDropdown from '../respArea/InlineDropdown';
|
|
4
|
-
|
|
5
|
-
jest.mock('@tiptap/react', () => ({
|
|
6
|
-
NodeViewWrapper: ({ children, ...props }) => (
|
|
7
|
-
<div data-testid="node-view-wrapper" {...props}>
|
|
8
|
-
{children}
|
|
9
|
-
</div>
|
|
10
|
-
),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
jest.mock('react-dom', () => ({
|
|
14
|
-
...jest.requireActual('react-dom'),
|
|
15
|
-
createPortal: (node) => node,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
describe('InlineDropdown', () => {
|
|
19
|
-
const buildMockEditor = (overrides = {}) => {
|
|
20
|
-
const mockTr = {
|
|
21
|
-
delete: jest.fn(),
|
|
22
|
-
};
|
|
23
|
-
return {
|
|
24
|
-
state: {
|
|
25
|
-
selection: {
|
|
26
|
-
from: 0,
|
|
27
|
-
to: 1,
|
|
28
|
-
},
|
|
29
|
-
tr: mockTr,
|
|
30
|
-
},
|
|
31
|
-
view: {
|
|
32
|
-
coordsAtPos: jest.fn(() => ({ top: 100, left: 50 })),
|
|
33
|
-
dispatch: jest.fn(),
|
|
34
|
-
},
|
|
35
|
-
commands: {
|
|
36
|
-
focus: jest.fn(),
|
|
37
|
-
},
|
|
38
|
-
_tiptapContainerEl: document.createElement('div'),
|
|
39
|
-
_toolbarOpened: false,
|
|
40
|
-
...overrides,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
let mockEditor;
|
|
45
|
-
|
|
46
|
-
const mockNode = {
|
|
47
|
-
attrs: {
|
|
48
|
-
index: '0',
|
|
49
|
-
value: 'Selected Option',
|
|
50
|
-
error: false,
|
|
51
|
-
},
|
|
52
|
-
nodeSize: 1,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const mockOptions = {
|
|
56
|
-
respAreaToolbar: jest.fn(() => () => <div data-testid="inline-dropdown-toolbar">Toolbar</div>),
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const defaultProps = {
|
|
60
|
-
editor: mockEditor,
|
|
61
|
-
node: mockNode,
|
|
62
|
-
getPos: () => 5,
|
|
63
|
-
options: mockOptions,
|
|
64
|
-
selected: false,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
jest.clearAllMocks();
|
|
69
|
-
mockEditor = buildMockEditor();
|
|
70
|
-
defaultProps.editor = mockEditor;
|
|
71
|
-
Object.defineProperty(document.body, 'getBoundingClientRect', {
|
|
72
|
-
value: jest.fn(() => ({ top: 0, left: 0 })),
|
|
73
|
-
configurable: true,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('renders without crashing', () => {
|
|
78
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
79
|
-
expect(container).toBeInTheDocument();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('renders NodeViewWrapper', () => {
|
|
83
|
-
const { getByTestId } = render(<InlineDropdown {...defaultProps} />);
|
|
84
|
-
expect(getByTestId('node-view-wrapper')).toBeInTheDocument();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('displays selected value', () => {
|
|
88
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
89
|
-
const valueDiv = container.querySelector('div[style*="border"]');
|
|
90
|
-
expect(valueDiv).toBeInTheDocument();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('uses 2px horizontal margin on the value control and no horizontal margin on the wrapper', () => {
|
|
94
|
-
const { container, getByTestId } = render(<InlineDropdown {...defaultProps} />);
|
|
95
|
-
const valueDiv = container.querySelector('div[style*="border"]');
|
|
96
|
-
expect(valueDiv).toHaveStyle({ margin: '0 2px' });
|
|
97
|
-
const wrapper = getByTestId('node-view-wrapper');
|
|
98
|
-
expect(wrapper.getAttribute('style') || '').not.toMatch(/margin/);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('renders chevron icon', () => {
|
|
102
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
103
|
-
const chevron = container.querySelector('svg');
|
|
104
|
-
expect(chevron).toBeInTheDocument();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('shows toolbar when selected and only this node is selected', async () => {
|
|
108
|
-
const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
|
|
109
|
-
await waitFor(() => {
|
|
110
|
-
// Toolbar is shown via portal
|
|
111
|
-
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('does not show toolbar when not selected', () => {
|
|
116
|
-
const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={false} />);
|
|
117
|
-
expect(queryByTestId('inline-dropdown-toolbar')).not.toBeInTheDocument();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('shows toolbar on click', async () => {
|
|
121
|
-
const { container, queryByTestId } = render(<InlineDropdown {...defaultProps} />);
|
|
122
|
-
const dropdown = container.querySelector('div[style*="border"]');
|
|
123
|
-
if (dropdown) {
|
|
124
|
-
fireEvent.click(dropdown);
|
|
125
|
-
await waitFor(() => {
|
|
126
|
-
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
127
|
-
});
|
|
128
|
-
} else {
|
|
129
|
-
// If dropdown is not found, just verify the component rendered
|
|
130
|
-
expect(container).toBeInTheDocument();
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('has correct minimum dimensions', () => {
|
|
135
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
136
|
-
const wrapper = container.querySelector('[data-testid="node-view-wrapper"]');
|
|
137
|
-
expect(wrapper).toHaveStyle({ height: '50px' });
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('has inline-flex display', () => {
|
|
141
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
142
|
-
const wrapper = container.querySelector('[data-testid="node-view-wrapper"]');
|
|
143
|
-
expect(wrapper).toHaveStyle({ display: 'inline-flex' });
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('has cursor pointer style', () => {
|
|
147
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
148
|
-
const wrapper = container.querySelector('[data-testid="node-view-wrapper"]');
|
|
149
|
-
expect(wrapper).toHaveStyle({ cursor: 'pointer' });
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('renders with empty value as nbsp', () => {
|
|
153
|
-
const emptyNode = { ...mockNode, attrs: { ...mockNode.attrs, value: '' } };
|
|
154
|
-
const { container } = render(<InlineDropdown {...defaultProps} node={emptyNode} />);
|
|
155
|
-
expect(container).toBeInTheDocument();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('calls respAreaToolbar with correct params', () => {
|
|
159
|
-
render(<InlineDropdown {...defaultProps} />);
|
|
160
|
-
expect(mockOptions.respAreaToolbar).toHaveBeenCalledWith([mockNode, 5], mockEditor, expect.any(Function));
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('closes toolbar on outside click', async () => {
|
|
164
|
-
const { container, queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
|
|
165
|
-
await waitFor(() => {
|
|
166
|
-
fireEvent.mouseDown(document.body);
|
|
167
|
-
});
|
|
168
|
-
// After clicking outside, toolbar should be hidden
|
|
169
|
-
await waitFor(() => {
|
|
170
|
-
expect(queryByTestId('inline-dropdown-toolbar')).not.toBeInTheDocument();
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('has correct border styling', () => {
|
|
175
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
176
|
-
const dropdownDiv = container.querySelector('div[style*="border"]');
|
|
177
|
-
expect(dropdownDiv).toHaveStyle({ border: '1px solid #C0C3CF' });
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('has correct min width', () => {
|
|
181
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
182
|
-
const dropdownDiv = container.querySelector('div[style*="border"]');
|
|
183
|
-
expect(dropdownDiv).toHaveStyle({ minWidth: '178px' });
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('positions chevron correctly', () => {
|
|
187
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
188
|
-
const chevron = container.querySelector('svg');
|
|
189
|
-
// Chevron styling is applied inline, just verify it rendered
|
|
190
|
-
if (chevron) {
|
|
191
|
-
expect(chevron).toBeInTheDocument();
|
|
192
|
-
} else {
|
|
193
|
-
expect(container).toBeInTheDocument();
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('has ellipsis for overflow text', () => {
|
|
198
|
-
const { container } = render(<InlineDropdown {...defaultProps} />);
|
|
199
|
-
const textContainer = container.querySelector('div[style*="overflow"]');
|
|
200
|
-
expect(textContainer).toHaveStyle({ textOverflow: 'ellipsis', whiteSpace: 'nowrap' });
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it('renders toolbar with z-index', async () => {
|
|
204
|
-
const { container } = render(<InlineDropdown {...defaultProps} selected={true} />);
|
|
205
|
-
await waitFor(() => {
|
|
206
|
-
const toolbarContainer = container.querySelector('div[style*="zIndex"]');
|
|
207
|
-
if (toolbarContainer) {
|
|
208
|
-
expect(toolbarContainer).toHaveStyle({ zIndex: '1' });
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('passes editorCallback to InlineDropdownToolbar', async () => {
|
|
214
|
-
const mockToolbarComponent = jest.fn(({ editorCallback }) => {
|
|
215
|
-
editorCallback?.({ instanceId: 'test-instance' });
|
|
216
|
-
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
const mockOptionsWithCallback = {
|
|
220
|
-
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
const { queryByTestId } = render(
|
|
224
|
-
<InlineDropdown {...defaultProps} options={mockOptionsWithCallback} selected={true} />,
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
await waitFor(() => {
|
|
228
|
-
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('stores toolbar editor instance in ref when editorCallback is called', async () => {
|
|
233
|
-
let capturedCallback;
|
|
234
|
-
const mockToolbarComponent = ({ editorCallback }) => {
|
|
235
|
-
capturedCallback = editorCallback;
|
|
236
|
-
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
const mockOptionsWithCallback = {
|
|
240
|
-
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const { queryByTestId } = render(
|
|
244
|
-
<InlineDropdown {...defaultProps} options={mockOptionsWithCallback} selected={true} />,
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
await waitFor(() => {
|
|
248
|
-
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// Verify callback exists
|
|
252
|
-
expect(capturedCallback).toBeDefined();
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it('handles click outside logic with data-toolbar-for attribute', async () => {
|
|
256
|
-
const editorWithInstanceId = {
|
|
257
|
-
...mockEditor,
|
|
258
|
-
instanceId: 'editor-123',
|
|
259
|
-
_toolbarOpened: false,
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// Mock the toolbar callback to set the toolbar editor instance
|
|
263
|
-
let capturedCallback;
|
|
264
|
-
const mockToolbarComponent = ({ editorCallback }) => {
|
|
265
|
-
React.useEffect(() => {
|
|
266
|
-
capturedCallback = editorCallback;
|
|
267
|
-
if (editorCallback) {
|
|
268
|
-
editorCallback({ instanceId: 'editor-123' });
|
|
269
|
-
}
|
|
270
|
-
}, [editorCallback]);
|
|
271
|
-
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const mockOptionsWithCallback = {
|
|
275
|
-
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
const { container, queryByTestId } = render(
|
|
279
|
-
<InlineDropdown
|
|
280
|
-
{...defaultProps}
|
|
281
|
-
editor={editorWithInstanceId}
|
|
282
|
-
options={mockOptionsWithCallback}
|
|
283
|
-
selected={true}
|
|
284
|
-
/>,
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
await waitFor(() => {
|
|
288
|
-
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// Create an element with data-toolbar-for attribute
|
|
292
|
-
const otherToolbar = document.createElement('div');
|
|
293
|
-
otherToolbar.setAttribute('data-toolbar-for', 'editor-456');
|
|
294
|
-
document.body.appendChild(otherToolbar);
|
|
295
|
-
|
|
296
|
-
await waitFor(() => {
|
|
297
|
-
fireEvent.mouseDown(otherToolbar);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
// Cleanup
|
|
301
|
-
document.body.removeChild(otherToolbar);
|
|
302
|
-
expect(container).toBeInTheDocument();
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it('does not close when clicking inside same editor toolbar', async () => {
|
|
306
|
-
const editorWithInstanceId = {
|
|
307
|
-
...mockEditor,
|
|
308
|
-
instanceId: 'editor-123',
|
|
309
|
-
_toolbarOpened: false,
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
let toolbarEditorInstance;
|
|
313
|
-
const mockToolbarComponent = ({ editorCallback }) => {
|
|
314
|
-
React.useEffect(() => {
|
|
315
|
-
if (editorCallback) {
|
|
316
|
-
editorCallback({ instanceId: 'editor-123' });
|
|
317
|
-
toolbarEditorInstance = { instanceId: 'editor-123' };
|
|
318
|
-
}
|
|
319
|
-
}, [editorCallback]);
|
|
320
|
-
return <div data-testid="inline-dropdown-toolbar">Toolbar</div>;
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
const mockOptionsWithCallback = {
|
|
324
|
-
respAreaToolbar: jest.fn(() => mockToolbarComponent),
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
render(
|
|
328
|
-
<InlineDropdown
|
|
329
|
-
{...defaultProps}
|
|
330
|
-
editor={editorWithInstanceId}
|
|
331
|
-
options={mockOptionsWithCallback}
|
|
332
|
-
selected={true}
|
|
333
|
-
/>,
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
await waitFor(() => {
|
|
337
|
-
expect(mockOptionsWithCallback.respAreaToolbar).toHaveBeenCalled();
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('checks editor._toolbarOpened in click outside handler', async () => {
|
|
342
|
-
const editorWithToolbarOpened = buildMockEditor({ _toolbarOpened: true });
|
|
343
|
-
|
|
344
|
-
const { queryByTestId } = render(
|
|
345
|
-
<InlineDropdown {...defaultProps} editor={editorWithToolbarOpened} selected={true} />,
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
await waitFor(() => {
|
|
349
|
-
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
// When _toolbarOpened is true, clicking outside should not close
|
|
353
|
-
fireEvent.mouseDown(document.body);
|
|
354
|
-
|
|
355
|
-
// Toolbar should still be visible
|
|
356
|
-
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('renders delete control on portaled custom toolbar when container el is set', async () => {
|
|
360
|
-
const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
|
|
361
|
-
expect(await findByLabelText('Delete')).toBeInTheDocument();
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it('does not render portaled delete control when _tiptapContainerEl is missing', async () => {
|
|
365
|
-
const editor = buildMockEditor({ _tiptapContainerEl: undefined });
|
|
366
|
-
const { queryByLabelText, findByTestId } = render(<InlineDropdown {...defaultProps} editor={editor} selected />);
|
|
367
|
-
expect(await findByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
|
|
368
|
-
expect(queryByLabelText('Delete')).not.toBeInTheDocument();
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it('delete clears toolbar flag, removes node range, dispatches, and focuses', async () => {
|
|
372
|
-
mockEditor._toolbarOpened = true;
|
|
373
|
-
const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
|
|
374
|
-
fireEvent.mouseDown(await findByLabelText('Delete'));
|
|
375
|
-
expect(mockEditor.state.tr.delete).toHaveBeenCalledWith(5, 6);
|
|
376
|
-
expect(mockEditor.view.dispatch).toHaveBeenCalledWith(mockEditor.state.tr);
|
|
377
|
-
expect(mockEditor._toolbarOpened).toBe(false);
|
|
378
|
-
expect(mockEditor.commands.focus).toHaveBeenCalled();
|
|
379
|
-
});
|
|
380
|
-
});
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import InsertImageHandler from '../image/InsertImageHandler';
|
|
2
|
-
|
|
3
|
-
describe('InsertImageHandler', () => {
|
|
4
|
-
const mockNode = {
|
|
5
|
-
attrs: {},
|
|
6
|
-
nodeSize: 1,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const NODE_POS = 5;
|
|
10
|
-
|
|
11
|
-
const nodeInfo = (node = mockNode, pos = NODE_POS) => [node, pos];
|
|
12
|
-
|
|
13
|
-
const createMockEditor = () => ({
|
|
14
|
-
_insertingImage: true,
|
|
15
|
-
state: {
|
|
16
|
-
doc: {},
|
|
17
|
-
tr: {
|
|
18
|
-
setNodeMarkup: jest.fn((pos, type, attrs) => ({ setNodeMarkup: jest.fn() })),
|
|
19
|
-
delete: jest.fn((from, to) => ({ delete: jest.fn() })),
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
view: {
|
|
23
|
-
dispatch: jest.fn(),
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const mockOnFinish = jest.fn();
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
jest.clearAllMocks();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('creates handler instance', () => {
|
|
34
|
-
const editor = createMockEditor();
|
|
35
|
-
const info = nodeInfo();
|
|
36
|
-
const handler = new InsertImageHandler(editor, info, mockOnFinish);
|
|
37
|
-
expect(handler).toBeDefined();
|
|
38
|
-
expect(handler.editor).toBe(editor);
|
|
39
|
-
expect(handler.nodeInfo).toBe(info);
|
|
40
|
-
expect(handler.node).toBe(mockNode);
|
|
41
|
-
expect(handler.onFinish).toBe(mockOnFinish);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('stores nodePos from nodeInfo tuple', () => {
|
|
45
|
-
const editor = createMockEditor();
|
|
46
|
-
const handler = new InsertImageHandler(editor, nodeInfo(mockNode, 42), mockOnFinish);
|
|
47
|
-
expect(handler.nodePos).toBe(42);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('stores isPasted parameter', () => {
|
|
51
|
-
const editor = createMockEditor();
|
|
52
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish, true);
|
|
53
|
-
expect(handler.isPasted).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('defaults isPasted to false', () => {
|
|
57
|
-
const editor = createMockEditor();
|
|
58
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
59
|
-
expect(handler.isPasted).toBe(false);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('cancel deletes node and calls onFinish', () => {
|
|
63
|
-
const editor = createMockEditor();
|
|
64
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
65
|
-
handler.cancel();
|
|
66
|
-
expect(mockOnFinish).toHaveBeenCalledWith(false);
|
|
67
|
-
expect(editor._insertingImage).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('updateNode dispatches transaction with new attributes', () => {
|
|
71
|
-
const editor = createMockEditor();
|
|
72
|
-
const mockNodeAt = jest.fn(() => ({ attrs: { existing: 'value' } }));
|
|
73
|
-
editor.state.doc.nodeAt = mockNodeAt;
|
|
74
|
-
|
|
75
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
76
|
-
handler.updateNode({ newAttr: 'newValue' });
|
|
77
|
-
|
|
78
|
-
expect(mockNodeAt).toHaveBeenCalledWith(NODE_POS);
|
|
79
|
-
expect(editor.view.dispatch).toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('done calls onFinish with false on error', () => {
|
|
83
|
-
const editor = createMockEditor();
|
|
84
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
85
|
-
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
86
|
-
|
|
87
|
-
handler.done('error', null);
|
|
88
|
-
|
|
89
|
-
expect(consoleLogSpy).toHaveBeenCalledWith('error');
|
|
90
|
-
expect(mockOnFinish).toHaveBeenCalledWith(false);
|
|
91
|
-
expect(editor._insertingImage).toBe(false);
|
|
92
|
-
consoleLogSpy.mockRestore();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('done updates node and calls onFinish with true on success', () => {
|
|
96
|
-
const editor = createMockEditor();
|
|
97
|
-
const mockNodeAt = jest.fn(() => ({ attrs: {} }));
|
|
98
|
-
editor.state.doc.nodeAt = mockNodeAt;
|
|
99
|
-
|
|
100
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
101
|
-
handler.done(null, 'http://example.com/image.jpg');
|
|
102
|
-
|
|
103
|
-
expect(editor.view.dispatch).toHaveBeenCalled();
|
|
104
|
-
expect(mockOnFinish).toHaveBeenCalledWith(true);
|
|
105
|
-
expect(editor._insertingImage).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('fileChosen returns early when no file provided', () => {
|
|
109
|
-
const editor = createMockEditor();
|
|
110
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
111
|
-
handler.fileChosen(null);
|
|
112
|
-
expect(editor.view.dispatch).not.toHaveBeenCalled();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('fileChosen saves file and reads it as data URL', () => {
|
|
116
|
-
const editor = createMockEditor();
|
|
117
|
-
const mockNodeAt = jest.fn(() => ({ attrs: {} }));
|
|
118
|
-
editor.state.doc.nodeAt = mockNodeAt;
|
|
119
|
-
|
|
120
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
121
|
-
const mockFile = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
122
|
-
|
|
123
|
-
global.FileReader = jest.fn(function () {
|
|
124
|
-
this.readAsDataURL = jest.fn(function () {
|
|
125
|
-
this.result = 'data:image/jpeg;base64,abc123';
|
|
126
|
-
this.onload();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
handler.fileChosen(mockFile);
|
|
131
|
-
|
|
132
|
-
expect(handler.chosenFile).toBe(mockFile);
|
|
133
|
-
expect(editor._insertingImage).toBe(false);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('progress updates node with percent', () => {
|
|
137
|
-
const editor = createMockEditor();
|
|
138
|
-
const mockNodeAt = jest.fn(() => ({ attrs: {} }));
|
|
139
|
-
editor.state.doc.nodeAt = mockNodeAt;
|
|
140
|
-
|
|
141
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
142
|
-
handler.progress(50, 500, 1000);
|
|
143
|
-
|
|
144
|
-
expect(editor.view.dispatch).toHaveBeenCalled();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('getChosenFile returns the chosen file', () => {
|
|
148
|
-
const editor = createMockEditor();
|
|
149
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
150
|
-
const mockFile = new File(['content'], 'test.jpg', { type: 'image/jpeg' });
|
|
151
|
-
handler.chosenFile = mockFile;
|
|
152
|
-
|
|
153
|
-
expect(handler.getChosenFile()).toBe(mockFile);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('getChosenFile returns null initially', () => {
|
|
157
|
-
const editor = createMockEditor();
|
|
158
|
-
const handler = new InsertImageHandler(editor, nodeInfo(), mockOnFinish);
|
|
159
|
-
expect(handler.getChosenFile()).toBeNull();
|
|
160
|
-
});
|
|
161
|
-
});
|