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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/package.json +3 -3
  2. package/src/__tests__/EditableHtml.test.jsx +0 -588
  3. package/src/__tests__/constants.test.js +0 -19
  4. package/src/__tests__/div-to-paragraph-conversion.test.jsx +0 -125
  5. package/src/__tests__/extensions.test.js +0 -208
  6. package/src/__tests__/index.test.jsx +0 -154
  7. package/src/__tests__/size-utils.test.js +0 -64
  8. package/src/__tests__/theme.test.js +0 -17
  9. package/src/components/__tests__/AltDialog.test.jsx +0 -147
  10. package/src/components/__tests__/CharacterPicker.test.jsx +0 -270
  11. package/src/components/__tests__/CssIcon.test.jsx +0 -46
  12. package/src/components/__tests__/DragInTheBlank.test.jsx +0 -255
  13. package/src/components/__tests__/ExplicitConstructedResponse.test.jsx +0 -209
  14. package/src/components/__tests__/ImageToolbar.test.jsx +0 -128
  15. package/src/components/__tests__/InlineDropdown.test.jsx +0 -557
  16. package/src/components/__tests__/InsertImageHandler.test.js +0 -161
  17. package/src/components/__tests__/MediaDialog.test.jsx +0 -293
  18. package/src/components/__tests__/MediaToolbar.test.jsx +0 -74
  19. package/src/components/__tests__/MediaWrapper.test.jsx +0 -81
  20. package/src/components/__tests__/MenuBar.test.jsx +0 -250
  21. package/src/components/__tests__/RespArea.test.jsx +0 -122
  22. package/src/components/__tests__/TableIcons.test.jsx +0 -149
  23. package/src/components/__tests__/TextAlign.test.jsx +0 -167
  24. package/src/components/__tests__/TiptapContainer.test.jsx +0 -138
  25. package/src/components/__tests__/characterUtils.test.js +0 -166
  26. package/src/components/__tests__/choice.test.jsx +0 -171
  27. package/src/components/__tests__/custom-popper.test.jsx +0 -82
  28. package/src/components/__tests__/done-button.test.jsx +0 -54
  29. package/src/components/__tests__/toolbar-buttons.test.jsx +0 -234
  30. package/src/components/respArea/DragInTheBlank/__tests__/choice.test.jsx +0 -72
  31. package/src/components/respArea/__tests__/MathTemplated.test.jsx +0 -210
  32. package/src/extensions/__tests__/css.test.js +0 -196
  33. package/src/extensions/__tests__/custom-toolbar-wrapper.test.jsx +0 -180
  34. package/src/extensions/__tests__/divNode.test.js +0 -87
  35. package/src/extensions/__tests__/ensure-empty-root-div.test.js +0 -57
  36. package/src/extensions/__tests__/ensure-list-item-content-is-div.test.js +0 -44
  37. package/src/extensions/__tests__/extended-list-item.test.js +0 -13
  38. package/src/extensions/__tests__/extended-table-cell.test.js +0 -22
  39. package/src/extensions/__tests__/extended-table.test.js +0 -183
  40. package/src/extensions/__tests__/image-component.test.jsx +0 -346
  41. package/src/extensions/__tests__/image.test.js +0 -237
  42. package/src/extensions/__tests__/math.test.js +0 -900
  43. package/src/extensions/__tests__/media-node-view.test.jsx +0 -298
  44. package/src/extensions/__tests__/media.test.js +0 -271
  45. package/src/extensions/__tests__/responseArea.test.js +0 -655
  46. package/src/utils/__tests__/helper.test.js +0 -126
  47. package/src/utils/__tests__/toolbar.test.js +0 -43
@@ -1,237 +0,0 @@
1
- jest.mock('@tiptap/core', () => ({
2
- Node: { create: jest.fn((config) => config) },
3
- mergeAttributes: jest.fn((...args) => Object.assign({}, ...args)),
4
- }));
5
-
6
- jest.mock('@tiptap/pm/state', () => ({
7
- Plugin: jest.fn(function MockPlugin(spec) {
8
- this.spec = spec;
9
- return { spec };
10
- }),
11
- }));
12
-
13
- jest.mock('@tiptap/react', () => ({
14
- ReactNodeViewRenderer: jest.fn((component) => component),
15
- }));
16
-
17
- jest.mock('../image-component', () => ({
18
- __esModule: true,
19
- default: jest.fn(() => <div data-testid="image-component" />),
20
- }));
21
-
22
- import { Plugin } from '@tiptap/pm/state';
23
- import { ImageUploadNode } from '../image';
24
-
25
- function setupPastePlugin() {
26
- const insertContent = jest.fn();
27
- const editor = { commands: { insertContent } };
28
- Plugin.mockClear();
29
- ImageUploadNode.addProseMirrorPlugins.call({ editor });
30
- expect(Plugin).toHaveBeenCalledTimes(1);
31
- const handlePaste = Plugin.mock.calls[0][0].props.handlePaste;
32
- return { handlePaste, insertContent, editor };
33
- }
34
-
35
- describe('ImageUploadNode', () => {
36
- describe('configuration', () => {
37
- it('has correct name', () => {
38
- expect(ImageUploadNode.name).toBe('imageUploadNode');
39
- });
40
-
41
- it('is in block group', () => {
42
- expect(ImageUploadNode.group).toBe('block');
43
- });
44
-
45
- it('is atomic', () => {
46
- expect(ImageUploadNode.atom).toBe(true);
47
- });
48
-
49
- it('is selectable', () => {
50
- expect(ImageUploadNode.selectable).toBe(true);
51
- });
52
-
53
- it('is draggable', () => {
54
- expect(ImageUploadNode.draggable).toBe(true);
55
- });
56
- });
57
-
58
- describe('addAttributes', () => {
59
- it('returns all required attributes with defaults', () => {
60
- const attributes = ImageUploadNode.addAttributes();
61
-
62
- expect(attributes).toHaveProperty('loaded');
63
- expect(attributes).toHaveProperty('deleteStatus');
64
- expect(attributes).toHaveProperty('alignment');
65
- expect(attributes).toHaveProperty('percent');
66
- expect(attributes).toHaveProperty('width');
67
- expect(attributes).toHaveProperty('height');
68
- expect(attributes).toHaveProperty('src');
69
- expect(attributes).toHaveProperty('alt');
70
-
71
- expect(attributes.loaded).toEqual({ default: false });
72
- expect(attributes.deleteStatus).toEqual({ default: null });
73
- expect(attributes.alignment).toEqual({ default: null });
74
- expect(attributes.percent).toEqual({ default: null });
75
- expect(attributes.width).toEqual({ default: null });
76
- expect(attributes.height).toEqual({ default: null });
77
- expect(attributes.src).toEqual({ default: null });
78
- expect(attributes.alt).toEqual({ default: null });
79
- });
80
- });
81
-
82
- describe('parseHTML', () => {
83
- it('returns array with div selector', () => {
84
- const rules = ImageUploadNode.parseHTML();
85
-
86
- expect(Array.isArray(rules)).toBe(true);
87
- expect(rules).toHaveLength(1);
88
- expect(rules[0]).toHaveProperty('tag', 'img[data-type="image-upload-node"]');
89
- });
90
- });
91
-
92
- describe('renderHTML', () => {
93
- it('renders img tag with data-type attribute', () => {
94
- const HTMLAttributes = {
95
- src: 'test.jpg',
96
- width: 100,
97
- height: 100,
98
- };
99
-
100
- const result = ImageUploadNode.renderHTML({ HTMLAttributes });
101
-
102
- expect(result[0]).toBe('img');
103
- expect(result[1]).toEqual({
104
- ...HTMLAttributes,
105
- 'data-type': 'image-upload-node',
106
- });
107
- });
108
-
109
- it('merges attributes correctly', () => {
110
- const HTMLAttributes = {
111
- src: 'test.jpg',
112
- alt: 'Test image',
113
- };
114
-
115
- const result = ImageUploadNode.renderHTML({ HTMLAttributes });
116
-
117
- expect(result[1].src).toBe('test.jpg');
118
- expect(result[1].alt).toBe('Test image');
119
- expect(result[1]['data-type']).toBe('image-upload-node');
120
- });
121
- });
122
-
123
- describe('addNodeView', () => {
124
- it('returns ReactNodeViewRenderer result', () => {
125
- const result = ImageUploadNode.addNodeView();
126
-
127
- expect(result).toBeDefined();
128
- });
129
- });
130
-
131
- describe('addCommands', () => {
132
- it('returns setImageUploadNode command', () => {
133
- const context = { name: 'imageUploadNode' };
134
- const commands = ImageUploadNode.addCommands.call(context);
135
-
136
- expect(commands).toHaveProperty('setImageUploadNode');
137
- expect(typeof commands.setImageUploadNode).toBe('function');
138
- });
139
-
140
- it('setImageUploadNode inserts content', () => {
141
- const context = { name: 'imageUploadNode' };
142
- const commands = ImageUploadNode.addCommands.call(context);
143
- const mockCommands = {
144
- insertContent: jest.fn(() => true),
145
- };
146
- const result = commands.setImageUploadNode()({ commands: mockCommands });
147
- expect(mockCommands.insertContent).toHaveBeenCalledWith(
148
- expect.objectContaining({
149
- type: 'imageUploadNode',
150
- attrs: expect.objectContaining({ nodeKey: expect.any(String) }),
151
- }),
152
- );
153
- expect(result).toBe(true);
154
- });
155
- });
156
-
157
- describe('addProseMirrorPlugins', () => {
158
- const mockView = {};
159
-
160
- beforeEach(() => {
161
- jest.spyOn(global, 'FileReader').mockImplementation(function MockFileReader() {
162
- this.readAsDataURL = function readAsDataURL() {
163
- this.result = 'data:image/png;base64,Zm9v';
164
- queueMicrotask(() => {
165
- if (this.onload) {
166
- this.onload();
167
- }
168
- });
169
- };
170
- });
171
- });
172
-
173
- afterEach(() => {
174
- global.FileReader.mockRestore();
175
- });
176
-
177
- it('registers one paste plugin', () => {
178
- const insertContent = jest.fn();
179
- const editor = { commands: { insertContent } };
180
- Plugin.mockClear();
181
- const plugins = ImageUploadNode.addProseMirrorPlugins.call({ editor });
182
- expect(plugins).toHaveLength(1);
183
- expect(Plugin).toHaveBeenCalledTimes(1);
184
- });
185
-
186
- it('handlePaste returns false when clipboard has no image file', () => {
187
- const { handlePaste } = setupPastePlugin();
188
- const event = {
189
- clipboardData: {
190
- items: [{ kind: 'string', type: 'text/plain', getAsFile: () => null }],
191
- },
192
- };
193
- expect(handlePaste(mockView, event)).toBe(false);
194
- });
195
-
196
- it('handlePaste returns false when clipboardData is missing', () => {
197
- const { handlePaste } = setupPastePlugin();
198
- const event = {};
199
- expect(handlePaste(mockView, event)).toBe(false);
200
- });
201
-
202
- it('handlePaste returns false when the file item has no file', () => {
203
- const { handlePaste } = setupPastePlugin();
204
- const event = {
205
- clipboardData: {
206
- items: [{ kind: 'file', type: 'image/png', getAsFile: () => null }],
207
- },
208
- };
209
- expect(handlePaste(mockView, event)).toBe(false);
210
- });
211
-
212
- it('handlePaste returns true and inserts imageUploadNode with data URL after read', async () => {
213
- const { handlePaste, insertContent } = setupPastePlugin();
214
- const file = new File([new Uint8Array([1, 2, 3])], 'p.png', { type: 'image/png' });
215
- const event = {
216
- clipboardData: {
217
- items: [{ kind: 'file', type: 'image/png', getAsFile: () => file }],
218
- },
219
- };
220
-
221
- expect(handlePaste(mockView, event)).toBe(true);
222
- expect(insertContent).not.toHaveBeenCalled();
223
-
224
- await new Promise((resolve) => queueMicrotask(resolve));
225
-
226
- expect(insertContent).toHaveBeenCalledWith(
227
- expect.objectContaining({
228
- type: 'imageUploadNode',
229
- attrs: expect.objectContaining({
230
- src: 'data:image/png;base64,Zm9v',
231
- loaded: true,
232
- }),
233
- }),
234
- );
235
- });
236
- });
237
- });