@pie-lib/editable-html-tip-tap 2.1.19 → 2.1.20-beta.1
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/CHANGELOG.md +0 -130
- package/lib/components/EditableHtml.js +0 -56
- package/lib/components/EditableHtml.js.map +1 -1
- package/lib/components/MenuBar.js +12 -81
- package/lib/components/MenuBar.js.map +1 -1
- package/lib/components/TiptapContainer.js +2 -2
- package/lib/components/TiptapContainer.js.map +1 -1
- package/lib/components/common/toolbar-buttons.js +5 -6
- package/lib/components/common/toolbar-buttons.js.map +1 -1
- package/lib/components/icons/TableIcons.js +1 -3
- package/lib/components/icons/TableIcons.js.map +1 -1
- package/lib/components/icons/TextAlign.js +5 -14
- package/lib/components/icons/TextAlign.js.map +1 -1
- package/lib/components/respArea/MathTemplated.js +8 -14
- package/lib/components/respArea/MathTemplated.js.map +1 -1
- package/lib/extensions/math.js +37 -19
- package/lib/extensions/math.js.map +1 -1
- package/lib/styles/editorContainerStyles.js +2 -2
- package/lib/styles/editorContainerStyles.js.map +1 -1
- package/package.json +9 -9
- package/src/components/EditableHtml.jsx +0 -52
- package/src/components/MenuBar.jsx +9 -91
- package/src/components/TiptapContainer.jsx +2 -2
- package/src/components/common/toolbar-buttons.jsx +4 -6
- package/src/components/icons/TableIcons.jsx +1 -9
- package/src/components/icons/TextAlign.jsx +5 -39
- package/src/components/respArea/MathTemplated.jsx +6 -13
- package/src/extensions/math.js +19 -11
- package/src/styles/editorContainerStyles.js +2 -2
- package/LICENSE.md +0 -5
- package/src/__tests__/EditableHtml.test.jsx +0 -668
- package/src/__tests__/constants.test.js +0 -19
- package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
- package/src/__tests__/editor-attributes.test.jsx +0 -77
- 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__/spellcheck.test.jsx +0 -63
- 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 -338
- 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 -247
- 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 -898
- 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,298 +0,0 @@
|
|
|
1
|
-
// Create a mockable insertDialog function
|
|
2
|
-
const mockInsertDialog = jest.fn();
|
|
3
|
-
|
|
4
|
-
// Mock react-dom BEFORE any imports that depend on it
|
|
5
|
-
jest.mock('react-dom', () => ({
|
|
6
|
-
...jest.requireActual('react-dom'),
|
|
7
|
-
render: jest.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
// Mock the insertDialog function in the media module
|
|
11
|
-
jest.mock('../media', () => {
|
|
12
|
-
const actual = jest.requireActual('../media');
|
|
13
|
-
return {
|
|
14
|
-
__esModule: true,
|
|
15
|
-
...actual,
|
|
16
|
-
default: actual.default, // Preserve the default export
|
|
17
|
-
insertDialog: (...args) => mockInsertDialog(...args),
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
import React from 'react';
|
|
22
|
-
import { render, fireEvent } from '@testing-library/react';
|
|
23
|
-
import MediaNodeView from '../media';
|
|
24
|
-
|
|
25
|
-
jest.mock('@tiptap/core', () => ({
|
|
26
|
-
Node: { create: jest.fn((config) => config) },
|
|
27
|
-
mergeAttributes: jest.fn((...args) => Object.assign({}, ...args)),
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
jest.mock('@tiptap/react', () => ({
|
|
31
|
-
NodeViewWrapper: ({ children }) => <div data-testid="node-view-wrapper">{children}</div>,
|
|
32
|
-
ReactNodeViewRenderer: jest.fn((component) => component),
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
jest.mock('../../components/media/MediaDialog', () => ({
|
|
36
|
-
__esModule: true,
|
|
37
|
-
default: jest.fn(() => <div data-testid="media-dialog" />),
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
jest.mock('../../components/media/MediaToolbar', () => ({
|
|
41
|
-
__esModule: true,
|
|
42
|
-
default: jest.fn(({ onEdit, onRemove }) => (
|
|
43
|
-
<div data-testid="media-toolbar">
|
|
44
|
-
<button onClick={onEdit} data-testid="edit-button">
|
|
45
|
-
Edit Settings
|
|
46
|
-
</button>
|
|
47
|
-
<button onClick={onRemove} data-testid="remove-button">
|
|
48
|
-
Remove
|
|
49
|
-
</button>
|
|
50
|
-
</div>
|
|
51
|
-
)),
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
describe('MediaNodeView Component', () => {
|
|
55
|
-
let mockEditor;
|
|
56
|
-
let mockUpdateAttributes;
|
|
57
|
-
let mockDeleteNode;
|
|
58
|
-
|
|
59
|
-
beforeEach(() => {
|
|
60
|
-
jest.clearAllMocks();
|
|
61
|
-
mockInsertDialog.mockClear();
|
|
62
|
-
|
|
63
|
-
// Clean up any existing dialogs in the DOM
|
|
64
|
-
document.body.innerHTML = '';
|
|
65
|
-
|
|
66
|
-
mockEditor = {
|
|
67
|
-
chain: jest.fn(() => ({
|
|
68
|
-
focus: jest.fn(() => ({
|
|
69
|
-
run: jest.fn(),
|
|
70
|
-
})),
|
|
71
|
-
})),
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
mockUpdateAttributes = jest.fn();
|
|
75
|
-
mockDeleteNode = jest.fn();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
afterEach(() => {
|
|
79
|
-
// Clean up DOM after each test
|
|
80
|
-
document.body.innerHTML = '';
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('dialog auto-opening behavior - verifies the fix', () => {
|
|
84
|
-
it('should NOT open dialog on mount when audio has existing src', () => {
|
|
85
|
-
const node = {
|
|
86
|
-
attrs: {
|
|
87
|
-
type: 'audio',
|
|
88
|
-
tag: 'audio',
|
|
89
|
-
src: 'https://example.com/audio.mp3',
|
|
90
|
-
width: null,
|
|
91
|
-
height: null,
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// This should render without opening any dialogs
|
|
96
|
-
const { container } = render(
|
|
97
|
-
<MediaNodeView
|
|
98
|
-
editor={mockEditor}
|
|
99
|
-
node={node}
|
|
100
|
-
updateAttributes={mockUpdateAttributes}
|
|
101
|
-
deleteNode={mockDeleteNode}
|
|
102
|
-
options={{}}
|
|
103
|
-
/>,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Verify the component rendered successfully
|
|
107
|
-
expect(container.querySelector('audio')).toBeTruthy();
|
|
108
|
-
// Verify mockInsertDialog was not called (dialog didn't open)
|
|
109
|
-
expect(mockInsertDialog).not.toHaveBeenCalled();
|
|
110
|
-
// Verify deleteNode was not called (media was not removed)
|
|
111
|
-
expect(mockDeleteNode).not.toHaveBeenCalled();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should NOT open dialog on mount when video has existing src', () => {
|
|
115
|
-
const node = {
|
|
116
|
-
attrs: {
|
|
117
|
-
type: 'video',
|
|
118
|
-
tag: 'iframe',
|
|
119
|
-
src: 'https://www.youtube.com/embed/dQw4w9WgXcQ',
|
|
120
|
-
width: '640',
|
|
121
|
-
height: '480',
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// This should render without opening any dialogs
|
|
126
|
-
const { container } = render(
|
|
127
|
-
<MediaNodeView
|
|
128
|
-
editor={mockEditor}
|
|
129
|
-
node={node}
|
|
130
|
-
updateAttributes={mockUpdateAttributes}
|
|
131
|
-
deleteNode={mockDeleteNode}
|
|
132
|
-
options={{}}
|
|
133
|
-
/>,
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
// Verify the component rendered successfully
|
|
137
|
-
expect(container.querySelector('iframe')).toBeTruthy();
|
|
138
|
-
// Verify mockInsertDialog was not called (dialog didn't open)
|
|
139
|
-
expect(mockInsertDialog).not.toHaveBeenCalled();
|
|
140
|
-
// Verify deleteNode was not called (media was not removed)
|
|
141
|
-
expect(mockDeleteNode).not.toHaveBeenCalled();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should render existing media with empty string src without opening dialog', () => {
|
|
145
|
-
const node = {
|
|
146
|
-
attrs: {
|
|
147
|
-
type: 'audio',
|
|
148
|
-
tag: 'audio',
|
|
149
|
-
src: '', // Empty string (falsy but not null)
|
|
150
|
-
width: null,
|
|
151
|
-
height: null,
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const { container } = render(
|
|
156
|
-
<MediaNodeView
|
|
157
|
-
editor={mockEditor}
|
|
158
|
-
node={node}
|
|
159
|
-
updateAttributes={mockUpdateAttributes}
|
|
160
|
-
deleteNode={mockDeleteNode}
|
|
161
|
-
options={{}}
|
|
162
|
-
/>,
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
// Empty string is falsy, so dialog WOULD open with current implementation
|
|
166
|
-
// This documents current behavior
|
|
167
|
-
expect(container).toBeTruthy();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe('toolbar interaction', () => {
|
|
172
|
-
it('should render edit and remove buttons', () => {
|
|
173
|
-
const node = {
|
|
174
|
-
attrs: {
|
|
175
|
-
type: 'audio',
|
|
176
|
-
tag: 'audio',
|
|
177
|
-
src: 'https://example.com/audio.mp3',
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const { getByTestId } = render(
|
|
182
|
-
<MediaNodeView
|
|
183
|
-
editor={mockEditor}
|
|
184
|
-
node={node}
|
|
185
|
-
updateAttributes={mockUpdateAttributes}
|
|
186
|
-
deleteNode={mockDeleteNode}
|
|
187
|
-
options={{}}
|
|
188
|
-
/>,
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
expect(getByTestId('edit-button')).toBeTruthy();
|
|
192
|
-
expect(getByTestId('remove-button')).toBeTruthy();
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe('rendering', () => {
|
|
197
|
-
it('should render audio element when tag is audio', () => {
|
|
198
|
-
const node = {
|
|
199
|
-
attrs: {
|
|
200
|
-
type: 'audio',
|
|
201
|
-
tag: 'audio',
|
|
202
|
-
src: 'https://example.com/audio.mp3',
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const { container } = render(
|
|
207
|
-
<MediaNodeView
|
|
208
|
-
editor={mockEditor}
|
|
209
|
-
node={node}
|
|
210
|
-
updateAttributes={mockUpdateAttributes}
|
|
211
|
-
deleteNode={mockDeleteNode}
|
|
212
|
-
options={{}}
|
|
213
|
-
/>,
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
const audio = container.querySelector('audio');
|
|
217
|
-
expect(audio).toBeTruthy();
|
|
218
|
-
const source = audio.querySelector('source');
|
|
219
|
-
expect(source.getAttribute('src')).toBe('https://example.com/audio.mp3');
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it('should render iframe when tag is iframe', () => {
|
|
223
|
-
const node = {
|
|
224
|
-
attrs: {
|
|
225
|
-
type: 'video',
|
|
226
|
-
tag: 'iframe',
|
|
227
|
-
src: 'https://www.youtube.com/embed/dQw4w9WgXcQ',
|
|
228
|
-
width: '640',
|
|
229
|
-
height: '480',
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
const { container } = render(
|
|
234
|
-
<MediaNodeView
|
|
235
|
-
editor={mockEditor}
|
|
236
|
-
node={node}
|
|
237
|
-
updateAttributes={mockUpdateAttributes}
|
|
238
|
-
deleteNode={mockDeleteNode}
|
|
239
|
-
options={{}}
|
|
240
|
-
/>,
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
const iframe = container.querySelector('iframe');
|
|
244
|
-
expect(iframe).toBeTruthy();
|
|
245
|
-
expect(iframe.getAttribute('src')).toBe('https://www.youtube.com/embed/dQw4w9WgXcQ');
|
|
246
|
-
expect(iframe.getAttribute('width')).toBe('640');
|
|
247
|
-
expect(iframe.getAttribute('height')).toBe('480');
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it('should render MediaToolbar', () => {
|
|
251
|
-
const node = {
|
|
252
|
-
attrs: {
|
|
253
|
-
type: 'audio',
|
|
254
|
-
tag: 'audio',
|
|
255
|
-
src: 'https://example.com/audio.mp3',
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const { getByTestId } = render(
|
|
260
|
-
<MediaNodeView
|
|
261
|
-
editor={mockEditor}
|
|
262
|
-
node={node}
|
|
263
|
-
updateAttributes={mockUpdateAttributes}
|
|
264
|
-
deleteNode={mockDeleteNode}
|
|
265
|
-
options={{}}
|
|
266
|
-
/>,
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
expect(getByTestId('media-toolbar')).toBeTruthy();
|
|
270
|
-
expect(getByTestId('edit-button')).toBeTruthy();
|
|
271
|
-
expect(getByTestId('remove-button')).toBeTruthy();
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it('should call deleteNode when remove button is clicked', () => {
|
|
275
|
-
const node = {
|
|
276
|
-
attrs: {
|
|
277
|
-
type: 'audio',
|
|
278
|
-
tag: 'audio',
|
|
279
|
-
src: 'https://example.com/audio.mp3',
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
const { getByTestId } = render(
|
|
284
|
-
<MediaNodeView
|
|
285
|
-
editor={mockEditor}
|
|
286
|
-
node={node}
|
|
287
|
-
updateAttributes={mockUpdateAttributes}
|
|
288
|
-
deleteNode={mockDeleteNode}
|
|
289
|
-
options={{}}
|
|
290
|
-
/>,
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
fireEvent.click(getByTestId('remove-button'));
|
|
294
|
-
|
|
295
|
-
expect(mockDeleteNode).toHaveBeenCalled();
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
});
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { insertDialog, Media } from '../media';
|
|
2
|
-
|
|
3
|
-
jest.mock('@tiptap/core', () => ({
|
|
4
|
-
Node: { create: jest.fn((config) => config) },
|
|
5
|
-
mergeAttributes: jest.fn((...args) => Object.assign({}, ...args)),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
jest.mock('@tiptap/react', () => ({
|
|
9
|
-
NodeViewWrapper: ({ children }) => <div data-testid="node-view-wrapper">{children}</div>,
|
|
10
|
-
ReactNodeViewRenderer: jest.fn((component) => component),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
jest.mock('react-dom', () => ({
|
|
14
|
-
render: jest.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
jest.mock('../../components/media/MediaDialog', () => ({
|
|
18
|
-
__esModule: true,
|
|
19
|
-
default: jest.fn(() => <div data-testid="media-dialog" />),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
jest.mock('../../components/media/MediaToolbar', () => ({
|
|
23
|
-
__esModule: true,
|
|
24
|
-
default: jest.fn(() => <div data-testid="media-toolbar" />),
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
describe('Media', () => {
|
|
28
|
-
describe('configuration', () => {
|
|
29
|
-
it('has correct name', () => {
|
|
30
|
-
expect(Media.name).toBe('media');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('is inline', () => {
|
|
34
|
-
expect(Media.inline).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('is in inline group', () => {
|
|
38
|
-
expect(Media.group).toBe('inline');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('is atomic', () => {
|
|
42
|
-
expect(Media.atom).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('addAttributes', () => {
|
|
47
|
-
it('returns all media attributes with defaults', () => {
|
|
48
|
-
const attributes = Media.addAttributes();
|
|
49
|
-
|
|
50
|
-
expect(attributes).toHaveProperty('type');
|
|
51
|
-
expect(attributes).toHaveProperty('src');
|
|
52
|
-
expect(attributes).toHaveProperty('width');
|
|
53
|
-
expect(attributes).toHaveProperty('height');
|
|
54
|
-
expect(attributes).toHaveProperty('title');
|
|
55
|
-
expect(attributes).toHaveProperty('starts');
|
|
56
|
-
expect(attributes).toHaveProperty('ends');
|
|
57
|
-
expect(attributes).toHaveProperty('editing');
|
|
58
|
-
expect(attributes).toHaveProperty('tag');
|
|
59
|
-
expect(attributes).toHaveProperty('url');
|
|
60
|
-
|
|
61
|
-
expect(attributes.type.default).toBe('video');
|
|
62
|
-
expect(attributes.src.default).toBeNull();
|
|
63
|
-
expect(attributes.tag.default).toBe('iframe');
|
|
64
|
-
expect(attributes.editing.default).toBe(false);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('parseHTML', () => {
|
|
69
|
-
it('returns parsing rules for iframe and audio', () => {
|
|
70
|
-
const rules = Media.parseHTML();
|
|
71
|
-
|
|
72
|
-
expect(Array.isArray(rules)).toBe(true);
|
|
73
|
-
expect(rules).toHaveLength(2);
|
|
74
|
-
expect(rules[0].tag).toBe('iframe[data-type="video"]');
|
|
75
|
-
expect(rules[1].tag).toBe('audio');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('parses video iframe attributes', () => {
|
|
79
|
-
const rules = Media.parseHTML();
|
|
80
|
-
const mockEl = {
|
|
81
|
-
getAttribute: jest.fn((attr) => {
|
|
82
|
-
const attrs = {
|
|
83
|
-
src: 'https://video.com/embed',
|
|
84
|
-
width: '640',
|
|
85
|
-
height: '480',
|
|
86
|
-
};
|
|
87
|
-
return attrs[attr] || null;
|
|
88
|
-
}),
|
|
89
|
-
dataset: {
|
|
90
|
-
title: 'Test Video',
|
|
91
|
-
starts: '10',
|
|
92
|
-
ends: '60',
|
|
93
|
-
url: 'https://video.com/watch',
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const result = rules[0].getAttrs(mockEl);
|
|
98
|
-
|
|
99
|
-
expect(result.type).toBe('video');
|
|
100
|
-
expect(result.tag).toBe('iframe');
|
|
101
|
-
expect(result.src).toBe('https://video.com/embed');
|
|
102
|
-
expect(result.width).toBe('640');
|
|
103
|
-
expect(result.height).toBe('480');
|
|
104
|
-
expect(result.title).toBe('Test Video');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('parses audio element attributes', () => {
|
|
108
|
-
const rules = Media.parseHTML();
|
|
109
|
-
const mockEl = {
|
|
110
|
-
querySelector: jest.fn(() => ({
|
|
111
|
-
getAttribute: jest.fn(() => 'https://audio.com/file.mp3'),
|
|
112
|
-
})),
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const result = rules[1].getAttrs(mockEl);
|
|
116
|
-
|
|
117
|
-
expect(result.type).toBe('audio');
|
|
118
|
-
expect(result.tag).toBe('audio');
|
|
119
|
-
expect(result.src).toBe('https://audio.com/file.mp3');
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('renderHTML', () => {
|
|
124
|
-
it('renders audio element for audio type', () => {
|
|
125
|
-
const HTMLAttributes = {
|
|
126
|
-
tag: 'audio',
|
|
127
|
-
src: 'test.mp3',
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const result = Media.renderHTML({ HTMLAttributes });
|
|
131
|
-
|
|
132
|
-
expect(result[0]).toBe('audio');
|
|
133
|
-
expect(result[1]).toEqual({ controls: 'controls', controlsList: 'nodownload' });
|
|
134
|
-
expect(result[2][0]).toBe('source');
|
|
135
|
-
expect(result[2][1]).toEqual({ src: 'test.mp3', type: 'audio/mp3' });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('renders iframe for video type', () => {
|
|
139
|
-
const HTMLAttributes = {
|
|
140
|
-
tag: 'iframe',
|
|
141
|
-
src: 'https://video.com/embed',
|
|
142
|
-
width: '640',
|
|
143
|
-
height: '480',
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const result = Media.renderHTML({ HTMLAttributes });
|
|
147
|
-
|
|
148
|
-
expect(result[0]).toBe('iframe');
|
|
149
|
-
expect(result[1]).toHaveProperty('data-type', 'video');
|
|
150
|
-
expect(result[1]).toHaveProperty('frameborder', '0');
|
|
151
|
-
expect(result[1]).toHaveProperty('src', 'https://video.com/embed');
|
|
152
|
-
expect(result[1]).toHaveProperty('width', '640');
|
|
153
|
-
expect(result[1]).toHaveProperty('height', '480');
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('renders iframe without dimensions if not provided', () => {
|
|
157
|
-
const HTMLAttributes = {
|
|
158
|
-
tag: 'iframe',
|
|
159
|
-
src: 'https://video.com/embed',
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const result = Media.renderHTML({ HTMLAttributes });
|
|
163
|
-
|
|
164
|
-
expect(result[1]).not.toHaveProperty('width');
|
|
165
|
-
expect(result[1]).not.toHaveProperty('height');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('addCommands', () => {
|
|
170
|
-
it('returns insertMedia and updateMedia commands', () => {
|
|
171
|
-
const commands = Media.addCommands();
|
|
172
|
-
|
|
173
|
-
expect(commands).toHaveProperty('insertMedia');
|
|
174
|
-
expect(commands).toHaveProperty('updateMedia');
|
|
175
|
-
expect(typeof commands.insertMedia).toBe('function');
|
|
176
|
-
expect(typeof commands.updateMedia).toBe('function');
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('insertMedia inserts content with attributes', () => {
|
|
180
|
-
const context = { name: 'media' };
|
|
181
|
-
const commands = Media.addCommands.call(context);
|
|
182
|
-
const mockCommands = {
|
|
183
|
-
insertContent: jest.fn(() => true),
|
|
184
|
-
};
|
|
185
|
-
const attrs = { type: 'video', src: 'test.mp4' };
|
|
186
|
-
|
|
187
|
-
const result = commands.insertMedia(attrs)({ commands: mockCommands });
|
|
188
|
-
|
|
189
|
-
expect(mockCommands.insertContent).toHaveBeenCalledWith({
|
|
190
|
-
type: 'media',
|
|
191
|
-
attrs,
|
|
192
|
-
});
|
|
193
|
-
expect(result).toBe(true);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('updateMedia updates attributes', () => {
|
|
197
|
-
const context = { name: 'media' };
|
|
198
|
-
const commands = Media.addCommands.call(context);
|
|
199
|
-
const mockCommands = {
|
|
200
|
-
updateAttributes: jest.fn(() => true),
|
|
201
|
-
};
|
|
202
|
-
const attrs = { width: '800' };
|
|
203
|
-
|
|
204
|
-
const result = commands.updateMedia(attrs)({ commands: mockCommands });
|
|
205
|
-
|
|
206
|
-
expect(mockCommands.updateAttributes).toHaveBeenCalledWith('media', attrs);
|
|
207
|
-
expect(result).toBe(true);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
describe('addNodeView', () => {
|
|
212
|
-
it('returns ReactNodeViewRenderer result', () => {
|
|
213
|
-
const result = Media.addNodeView();
|
|
214
|
-
|
|
215
|
-
expect(result).toBeDefined();
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe('insertDialog', () => {
|
|
221
|
-
beforeEach(() => {
|
|
222
|
-
document.body.innerHTML = '';
|
|
223
|
-
document.body.style.overflow = 'auto';
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('creates dialog element', () => {
|
|
227
|
-
const mockCallback = jest.fn();
|
|
228
|
-
const props = {
|
|
229
|
-
type: 'video',
|
|
230
|
-
callback: mockCallback,
|
|
231
|
-
options: {},
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
insertDialog(props);
|
|
235
|
-
|
|
236
|
-
const dialog = document.querySelector('.insert-media-dialog');
|
|
237
|
-
expect(dialog).toBeTruthy();
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('sets body overflow to hidden', () => {
|
|
241
|
-
const mockCallback = jest.fn();
|
|
242
|
-
const props = {
|
|
243
|
-
type: 'video',
|
|
244
|
-
callback: mockCallback,
|
|
245
|
-
options: {},
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
insertDialog(props);
|
|
249
|
-
|
|
250
|
-
expect(document.body.style.overflow).toBe('hidden');
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('removes previous dialogs', () => {
|
|
254
|
-
const existingDialog = document.createElement('div');
|
|
255
|
-
existingDialog.className = 'insert-media-dialog';
|
|
256
|
-
document.body.appendChild(existingDialog);
|
|
257
|
-
|
|
258
|
-
const mockCallback = jest.fn();
|
|
259
|
-
const props = {
|
|
260
|
-
type: 'video',
|
|
261
|
-
callback: mockCallback,
|
|
262
|
-
options: {},
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
insertDialog(props);
|
|
266
|
-
|
|
267
|
-
const dialogs = document.querySelectorAll('.insert-media-dialog');
|
|
268
|
-
expect(dialogs).toHaveLength(1);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|